diff --git a/src/uSupport/App_Plugins/uSupport/backoffice/ticketStatuses/ticketStatuses.edit.controller.js b/src/uSupport/App_Plugins/uSupport/backoffice/ticketStatuses/ticketStatuses.edit.controller.js index bd935fa..44c10f8 100644 --- a/src/uSupport/App_Plugins/uSupport/backoffice/ticketStatuses/ticketStatuses.edit.controller.js +++ b/src/uSupport/App_Plugins/uSupport/backoffice/ticketStatuses/ticketStatuses.edit.controller.js @@ -53,6 +53,7 @@ }); }); } else { + vm.ticketStatus = {}; vm.loading = false; } @@ -61,20 +62,19 @@ if (formHelper.submitForm({ scope: $scope })) { - vm.ticketStatus = { - Name: vm.page.title, - Alias: vm.page.alias - }; + vm.ticketStatus.Name = vm.page.title; + vm.ticketStatus.Alias = vm.page.alias; vm.properties.forEach(function (property) { if (property.alias === "Color") { vm.ticketStatus[property.alias] = property.singleDropdownValue } else { - vm.ticketStatus[property.alias] = parseInt(property.value) + vm.ticketStatus[property.alias] = parseInt(+property.value) } }); if (!vm.create) { + uSupportTicketStatusResources.updateTicketStatus(vm.ticketStatus).then(function () { vm.buttonState = "success"; $scope.formName.$dirty = false; diff --git a/src/uSupport/App_Plugins/uSupport/backoffice/ticketTypes/ticketTypes.edit.controller.js b/src/uSupport/App_Plugins/uSupport/backoffice/ticketTypes/ticketTypes.edit.controller.js index 151ab67..d32c8cd 100644 --- a/src/uSupport/App_Plugins/uSupport/backoffice/ticketTypes/ticketTypes.edit.controller.js +++ b/src/uSupport/App_Plugins/uSupport/backoffice/ticketTypes/ticketTypes.edit.controller.js @@ -58,6 +58,7 @@ }); }); } else { + vm.ticketType = {}; vm.loading = false; } diff --git a/src/uSupport/App_Plugins/uSupport/css/uSupport.css b/src/uSupport/App_Plugins/uSupport/css/uSupport.css index 7d81ee0..12373f1 100644 --- a/src/uSupport/App_Plugins/uSupport/css/uSupport.css +++ b/src/uSupport/App_Plugins/uSupport/css/uSupport.css @@ -96,6 +96,9 @@ display: none; } +.uSupport .umb-control-group .control-header .control-label { + white-space: initial; +} /* COLS */ .uSupport .uSupport-row { display: flex; diff --git a/src/uSupport/Backoffice/Trees/uSupportTicketStatusesTreeController.cs b/src/uSupport/Backoffice/Trees/uSupportTicketStatusesTreeController.cs index 6a70a0f..1faf56d 100644 --- a/src/uSupport/Backoffice/Trees/uSupportTicketStatusesTreeController.cs +++ b/src/uSupport/Backoffice/Trees/uSupportTicketStatusesTreeController.cs @@ -86,7 +86,8 @@ protected override ActionResult GetTreeNodes(string id, Form foreach (uSupportTicketStatus ticketStatus in _uSupportTicketStatusService.GetAll()) { var node = CreateTreeNode($"{ticketStatus.Id}", TicketStatusesTreeAlias, queryStrings, ticketStatus.Name, $"icon-file-cabinet", false, $"uSupport/{TicketStatusesTreeAlias}/edit/{ticketStatus.Id}"); - node.AdditionalData.Add("overviewRoutePath", TicketStatusesTreeAlias); + node.AdditionalData.Add("overviewRoutePath", string.Format("/{0}/{1}/overview", uSupportConstants.SectionAlias, TicketStatusesTreeAlias)); + nodes.Add(node); } } @@ -153,7 +154,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, [ModelBinder(typeo foreach (uSupportTicketStatus ticketStatus in _uSupportTicketStatusService.GetAll()) { var node = CreateTreeNode($"{ticketStatus.Id}", TicketStatusesTreeAlias, queryStrings, ticketStatus.Name, $"icon-file-cabinet", false, $"uSupport/{TicketStatusesTreeAlias}/edit/{ticketStatus.Id}"); - node.AdditionalData.Add("overviewRoutePath", TicketStatusesTreeAlias); + node.AdditionalData.Add("overviewRoutePath", string.Format("/{0}/{1}/overview", uSupportConstants.SectionAlias, TicketStatusesTreeAlias)); nodes.Add(node); } } diff --git a/src/uSupport/Backoffice/Trees/uSupportTicketTypesTreeController.cs b/src/uSupport/Backoffice/Trees/uSupportTicketTypesTreeController.cs index e58f47d..e5b90e4 100644 --- a/src/uSupport/Backoffice/Trees/uSupportTicketTypesTreeController.cs +++ b/src/uSupport/Backoffice/Trees/uSupportTicketTypesTreeController.cs @@ -82,7 +82,7 @@ protected override ActionResult GetTreeNodes(string id, Form foreach (uSupportTicketType ticketType in _uSupportTicketTypeService.GetAll()) { var node = CreateTreeNode($"{ticketType.Id}", TicketTypesTreeAlias, queryStrings, ticketType.Name, "icon-ticket", false, "uSupport/ticketTypes/edit/" + ticketType.Id); - node.AdditionalData.Add("overviewRoutePath", "/uSupport/ticketTypes/overview"); + node.AdditionalData.Add("overviewRoutePath", string.Format("/{0}/{1}/overview", uSupportConstants.SectionAlias, TicketTypesTreeAlias)); nodes.Add(node); } } @@ -115,10 +115,10 @@ public uSupportTicketTypesTreeController(IuSupportTicketTypeService uSupportTick protected override TreeNode CreateRootNode(FormDataCollection queryStrings) { var root = base.CreateRootNode(queryStrings); - root.RoutePath = string.Format("/{0}/{1}/{2}", uSupportConstants.SectionAlias, TicketStatusesTreeAlias, "overview"); - root.Icon = "icon-file-cabinet"; + root.RoutePath = string.Format("/{0}/{1}/{2}", uSupportConstants.SectionAlias, TicketTypesTreeAlias, "overview"); + root.Icon = "icon-ticket"; root.HasChildren = false; - root.AdditionalData.Add("type", TicketStatusesTreeAlias); + root.AdditionalData.Add("type", TicketTypesTreeAlias); return root; } @@ -149,7 +149,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, [ModelBinder(typeo foreach (uSupportTicketType ticketType in _uSupportTicketTypeService.GetAll()) { var node = CreateTreeNode($"{ticketType.Id}", TicketTypesTreeAlias, queryStrings, ticketType.Name, "icon-ticket", false, "uSupport/ticketTypes/edit/" + ticketType.Id); - node.AdditionalData.Add("overviewRoutePath", "/uSupport/ticketTypes/overview"); + node.AdditionalData.Add("overviewRoutePath", string.Format("/{0}/{1}/overview", uSupportConstants.SectionAlias, TicketTypesTreeAlias)); nodes.Add(node); } } diff --git a/src/uSupport/Extensions/SqlExtensions.cs b/src/uSupport/Extensions/SqlExtensions.cs index 3ad6b5e..49b4bce 100644 --- a/src/uSupport/Extensions/SqlExtensions.cs +++ b/src/uSupport/Extensions/SqlExtensions.cs @@ -12,37 +12,23 @@ public static class SqlExtensions public static Sql GetFullTicket(this Sql sql) { return sql.InnerJoin(TicketTypeTableAlias) - .On($"[TypeId] = {TicketTypeTableAlias}.Id") + .On($"TypeId = UPPER({TicketTypeTableAlias}.Id)") .InnerJoin(TicketStatusTableAlias) - .On($"[StatusId] = {TicketStatusTableAlias}.Id"); + .On($"StatusId = UPPER({TicketStatusTableAlias}.Id)"); } public static string ConvertStatusesToSql(this IEnumerable statuses) { if (statuses == null) return string.Empty; - string sql = string.Empty; - - foreach (uSupportTicketStatus status in statuses) - { - sql += status.Id.ConvertGuidToSqlString(); - - if (status != statuses.LastOrDefault()) - sql += ", "; - } - - return sql; + return string.Join(", ", statuses.Select(x => string.Format("UPPER('{0}')", x.Id))); } public static string ConvertGuidToSqlString(this List guids) - { - List sql = new List(); - foreach (Guid guid in guids) - sql.Add(string.Format("CAST('{0}' as uniqueidentifier)", guid)); + { + if (guids == null) return string.Empty; - return string.Join(",", sql); - } - - public static string ConvertGuidToSqlString(this Guid guid) => $"CAST('{guid}' as uniqueidentifier)"; + return string.Join(", ", guids.Select(x => string.Format("UPPER('{0}')", x))); ; + } } } \ No newline at end of file diff --git a/src/uSupport/Migrations/Updates/1.2.0/MakeExistingGuidIdsUpperCase.cs b/src/uSupport/Migrations/Updates/1.2.0/MakeExistingGuidIdsUpperCase.cs new file mode 100644 index 0000000..59d1066 --- /dev/null +++ b/src/uSupport/Migrations/Updates/1.2.0/MakeExistingGuidIdsUpperCase.cs @@ -0,0 +1,22 @@ +#if NETCOREAPP +using Umbraco.Cms.Infrastructure.Migrations; +#else +using Umbraco.Core.Migrations; +#endif +using uSupport.Migrations.Schemas; +using static uSupport.Constants.uSupportConstants; + +namespace uSupport.Migrations.Updates._1._2._0 +{ + public class MakeExistingGuidIdsUpperCase : uSupportMigrationBase + { + public MakeExistingGuidIdsUpperCase(IMigrationContext context) : base(context) + { } + + protected override void DoMigrate() + { + Execute.Sql($"UPDATE {TicketTypeTableAlias} SET Id = UPPER(Id)").Do(); + Execute.Sql($"UPDATE {TicketStatusTableAlias} SET Id = UPPER(Id)").Do(); + } + } +} diff --git a/src/uSupport/Migrations/uSupportMigrationPlan.cs b/src/uSupport/Migrations/uSupportMigrationPlan.cs index cd6e6e6..c96cdcf 100644 --- a/src/uSupport/Migrations/uSupportMigrationPlan.cs +++ b/src/uSupport/Migrations/uSupportMigrationPlan.cs @@ -4,6 +4,7 @@ using Umbraco.Core.Migrations; #endif using uSupport.Migrations.Create; +using uSupport.Migrations.Updates._1._2._0; namespace uSupport.Migrations { @@ -20,7 +21,8 @@ protected void DefinePlan() .To("uSupport-ticket-comment") .To("uSupport-ticket-type") .To("uSupport-ticket-status") - .To("uSupport-ticket"); + .To("uSupport-ticket") + .To("uSupport-ticket-status-type-guid-update"); } } } \ No newline at end of file diff --git a/src/uSupport/Services/uSupportServiceBase.cs b/src/uSupport/Services/uSupportServiceBase.cs index d267da2..6c6fde2 100644 --- a/src/uSupport/Services/uSupportServiceBase.cs +++ b/src/uSupport/Services/uSupportServiceBase.cs @@ -49,7 +49,7 @@ public virtual T Get(Guid id) var sql = new Sql() .Select("*") .From(_tableAlias) - .Where($"Id = {id.ConvertGuidToSqlString()}"); + .Where($"Id = UPPER('{id}')"); return scope.Database.Fetch(sql).FirstOrDefault(); } @@ -71,16 +71,17 @@ public virtual IEnumerable GetByIds(List ids) public virtual T Update(Schema dto) { + var dtoType = dto.GetType(); + var dtoIdProperty = dtoType.GetProperty("Id"); + var id = dtoIdProperty.GetValue(dto).ToString(); + using (var scope = _scopeProvider.CreateScope()) { - scope.Database.Update(dto); + scope.Database.UpdateWhere(dto, $"Id = UPPER('{id}')"); scope.Complete(); } - var dtoType = dto.GetType(); - var dtoIdProperty = dtoType.GetProperty("Id"); - - var updatedNotification = Get(Guid.Parse(dtoIdProperty.GetValue(dto).ToString())); + var updatedNotification = Get(Guid.Parse(id)); return updatedNotification; } @@ -89,7 +90,7 @@ public void Delete(Guid id) { using (var scope = _scopeProvider.CreateScope()) { - var result = scope.Database.Delete("WHERE [Id] = @id", new { id }); + var result = scope.Database.Delete($"WHERE Id = UPPER('{id}')"); scope.Complete(); } } diff --git a/src/uSupport/Services/uSupportSettingsService.cs b/src/uSupport/Services/uSupportSettingsService.cs index f7603b9..5cd0dfd 100644 --- a/src/uSupport/Services/uSupportSettingsService.cs +++ b/src/uSupport/Services/uSupportSettingsService.cs @@ -37,10 +37,10 @@ namespace uSupport.Services { public class uSupportSettingsService : IuSupportSettingsService { - private readonly IEmailSender _emailSender; private readonly uSupportSettingsTicket _defaultSettings; #if NETCOREAPP + private readonly IEmailSender _emailSender; private readonly IRazorViewEngine _razorViewEngine; private readonly IOptions _globalSettings; private readonly IHttpContextAccessor _httpContextAccessor; @@ -48,6 +48,7 @@ public class uSupportSettingsService : IuSupportSettingsService private readonly ITempDataProvider _tempDataProvider; private readonly ILogger _logger; #else + private readonly EmailSender _emailSender; private readonly ILogger _logger; #endif @@ -56,10 +57,10 @@ public class uSupportSettingsService : IuSupportSettingsService #elif NET5_0 private readonly IHostingEnvironment _hostingEnvironment; #endif - public uSupportSettingsService(IEmailSender emailSender - + public uSupportSettingsService( #if NETCOREAPP - , ITempDataProvider tempDataProvider, + IEmailSender emailSender, + ITempDataProvider tempDataProvider, IRazorViewEngine razorViewEngine, ILogger logger, #if NET6_0_OR_GREATER @@ -71,10 +72,11 @@ public uSupportSettingsService(IEmailSender emailSender IOptions globalSettings, IOptions uSupportSettings #else - , ILogger logger + + ILogger logger #endif ) - { + { #if NETCOREAPP _tempDataProvider = tempDataProvider; _globalSettings = globalSettings; @@ -82,9 +84,12 @@ IOptions uSupportSettings _hostingEnvironment = hostingEnvironment; _httpContextAccessor = httpContextAccessor; _razorViewEngine = razorViewEngine; + _emailSender = emailSender; +#else + _emailSender = new EmailSender(); #endif _logger = logger; - _emailSender = emailSender; + _defaultSettings = new uSupportSettingsTicket(); } @@ -222,7 +227,7 @@ public void SendEmail(string toAddress, string subject, string templateViewPath, message.To.Add(toAddress); - _emailSender.SendAsync(message); + _emailSender.Send(message); } catch (Exception ex) { diff --git a/src/uSupport/Services/uSupportTicketCommentService.cs b/src/uSupport/Services/uSupportTicketCommentService.cs index 1f00c4a..7c2c7a0 100644 --- a/src/uSupport/Services/uSupportTicketCommentService.cs +++ b/src/uSupport/Services/uSupportTicketCommentService.cs @@ -62,7 +62,7 @@ public override uSupportTicketComment Get(Guid id) var sql = new Sql() .Select("*") .From(TicketCommentTableAlias) - .Where($"Id = {id.ConvertGuidToSqlString()}"); + .Where($"Id = UPPER('{id}')"); return scope.Database.Fetch(sql).FirstOrDefault()?.ConvertSchemaToDto(); } @@ -76,7 +76,7 @@ public IEnumerable GetCommentsFromTicketId(Guid ticketId) var sql = new Sql() .Select("*") .From(TicketCommentTableAlias) - .Where($"TicketId = {ticketId.ConvertGuidToSqlString()}") + .Where($"TicketId = UPPER('{ticketId}')") .OrderBy("Date"); var comments = scope.Database.Query(sql); diff --git a/src/uSupport/Services/uSupportTicketService.cs b/src/uSupport/Services/uSupportTicketService.cs index acbea68..f2c60d4 100644 --- a/src/uSupport/Services/uSupportTicketService.cs +++ b/src/uSupport/Services/uSupportTicketService.cs @@ -68,11 +68,11 @@ public uSupportPage GetPagedActiveTickets(long page) .OrderBy("Submitted"); var sqlCount = new Sql() - .Select("Id") + .Select("COUNT(Id)") .From(TicketTableAlias) .Where($"StatusId IN ({statuses})"); - var ticketCount = scope.Database.Fetch(sqlCount).ToList().Count; + var ticketCount = scope.Database.Fetch(sqlCount).FirstOrDefault(); var tickets = scope.Database.SkipTake((page - 1) * PageSize, PageSize, sql); return MapPageToUSupportPage(tickets, ticketCount, page, PageSize); @@ -125,7 +125,7 @@ public override uSupportTicket Get(Guid id) .Select("*") .From(TicketTableAlias) .GetFullTicket() - .Where($"[Id] = {id.ConvertGuidToSqlString()}"); + .Where($"{TicketTableAlias}.Id = UPPER('{id}')"); var ticket = scope.Database.Fetch(sql).FirstOrDefault(); @@ -133,6 +133,17 @@ public override uSupportTicket Get(Guid id) } } + public override uSupportTicket Update(uSupportTicketSchema dto) + { + using (var scope = _scopeProvider.CreateScope()) + { + scope.Database.Update(dto); + scope.Complete(); + } + + return base.Get(dto.Id); + } + public void ClearTicketCache() { _appCaches.RuntimeCache.ClearByRegex("uSupportPaged"); diff --git a/src/uSupport/Services/uSupportTicketStatusService.cs b/src/uSupport/Services/uSupportTicketStatusService.cs index 3db0756..0674750 100644 --- a/src/uSupport/Services/uSupportTicketStatusService.cs +++ b/src/uSupport/Services/uSupportTicketStatusService.cs @@ -29,7 +29,7 @@ public uSupportTicketStatus GetDefaultStatus() using (var scope = _scopeProvider.CreateScope()) { var db = scope.Database; - var status = db.Query($"SELECT * FROM {TicketStatusTableAlias} WHERE [Default] = 'True'").FirstOrDefault(); + var status = db.Query($"SELECT * FROM {TicketStatusTableAlias} WHERE [Default] = '1'").FirstOrDefault(); return status; } @@ -40,7 +40,7 @@ public IEnumerable GetActiveStatuses() using (var scope = _scopeProvider.CreateScope()) { var db = scope.Database; - var statuses = db.Query($"SELECT * FROM {TicketStatusTableAlias} WHERE [Active] = 'True'"); + var statuses = db.Query($"SELECT * FROM {TicketStatusTableAlias} WHERE [Active] = '1'"); return statuses.ToList(); } @@ -51,7 +51,7 @@ public IEnumerable GetResolvedStatuses() using (var scope = _scopeProvider.CreateScope()) { var db = scope.Database; - var statuses = db.Query($"SELECT * FROM {TicketStatusTableAlias} WHERE [Active] = 'False'"); + var statuses = db.Query($"SELECT * FROM {TicketStatusTableAlias} WHERE [Active] = '0'"); return statuses.ToList(); } @@ -84,7 +84,7 @@ public int GetStatusCount() using (var scope = _scopeProvider.CreateScope()) { var db = scope.Database; - return db.Query($"SELECT [Order] FROM {TicketStatusTableAlias}").ToList().Count; + return db.Query($"SELECT COUNT([Order]) FROM {TicketStatusTableAlias}").FirstOrDefault(); } } } diff --git a/src/uSupport/uSupport.csproj b/src/uSupport/uSupport.csproj index 20de3c8..b83c76d 100644 --- a/src/uSupport/uSupport.csproj +++ b/src/uSupport/uSupport.csproj @@ -26,7 +26,7 @@ uSupport - 1.1.0 + 1.2.0 uSupport Lantzify Lantzify