Skip to content

Commit

Permalink
Merge pull request #9 from Lantzify/main
Browse files Browse the repository at this point in the history
Database compatibility & minor bug fixes
  • Loading branch information
Lantzify authored Feb 25, 2023
2 parents 3f5043a + 9179f72 commit e1893c0
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
});
});
} else {
vm.ticketStatus = {};
vm.loading = false;
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
});
});
} else {
vm.ticketType = {};
vm.loading = false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/uSupport/App_Plugins/uSupport/css/uSupport.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
display: none;
}

.uSupport .umb-control-group .control-header .control-label {
white-space: initial;
}
/* COLS */
.uSupport .uSupport-row {
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ protected override ActionResult<TreeNodeCollection> 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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected override ActionResult<TreeNodeCollection> 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);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
28 changes: 7 additions & 21 deletions src/uSupport/Extensions/SqlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<uSupportTicketStatus> 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<Guid> guids)
{
List<string> sql = new List<string>();
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))); ;
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
4 changes: 3 additions & 1 deletion src/uSupport/Migrations/uSupportMigrationPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Umbraco.Core.Migrations;
#endif
using uSupport.Migrations.Create;
using uSupport.Migrations.Updates._1._2._0;

namespace uSupport.Migrations
{
Expand All @@ -20,7 +21,8 @@ protected void DefinePlan()
.To<uSupportTicketCommentTable>("uSupport-ticket-comment")
.To<uSupportTicketTypeTable>("uSupport-ticket-type")
.To<uSupportTicketStatusTable>("uSupport-ticket-status")
.To<uSupportTicketTable>("uSupport-ticket");
.To<uSupportTicketTable>("uSupport-ticket")
.To<MakeExistingGuidIdsUpperCase>("uSupport-ticket-status-type-guid-update");
}
}
}
15 changes: 8 additions & 7 deletions src/uSupport/Services/uSupportServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(sql).FirstOrDefault();
}
Expand All @@ -71,16 +71,17 @@ public virtual IEnumerable<T> GetByIds(List<Guid> 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;
}
Expand All @@ -89,7 +90,7 @@ public void Delete(Guid id)
{
using (var scope = _scopeProvider.CreateScope())
{
var result = scope.Database.Delete<T>("WHERE [Id] = @id", new { id });
var result = scope.Database.Delete<T>($"WHERE Id = UPPER('{id}')");
scope.Complete();
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/uSupport/Services/uSupportSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ 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> _globalSettings;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IOptions<uSupportSettings> _uSupportSettings;
private readonly ITempDataProvider _tempDataProvider;
private readonly ILogger<IuSupportTicketService> _logger;
#else
private readonly EmailSender _emailSender;
private readonly ILogger _logger;
#endif

Expand All @@ -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<IuSupportTicketService> logger,
#if NET6_0_OR_GREATER
Expand All @@ -71,20 +72,24 @@ public uSupportSettingsService(IEmailSender emailSender
IOptions<GlobalSettings> globalSettings,
IOptions<uSupportSettings> uSupportSettings
#else
, ILogger logger

ILogger logger
#endif
)
{
{
#if NETCOREAPP
_tempDataProvider = tempDataProvider;
_globalSettings = globalSettings;
_uSupportSettings = uSupportSettings;
_hostingEnvironment = hostingEnvironment;
_httpContextAccessor = httpContextAccessor;
_razorViewEngine = razorViewEngine;
_emailSender = emailSender;
#else
_emailSender = new EmailSender();
#endif
_logger = logger;
_emailSender = emailSender;

_defaultSettings = new uSupportSettingsTicket();
}

Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/uSupport/Services/uSupportTicketCommentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<uSupportTicketCommentSchema>(sql).FirstOrDefault()?.ConvertSchemaToDto();
}
Expand All @@ -76,7 +76,7 @@ public IEnumerable<uSupportTicketComment> 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<uSupportTicketCommentSchema>(sql);
Expand Down
17 changes: 14 additions & 3 deletions src/uSupport/Services/uSupportTicketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public uSupportPage<uSupportTicket> 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<uSupportTicket>(sqlCount).ToList().Count;
var ticketCount = scope.Database.Fetch<int>(sqlCount).FirstOrDefault();
var tickets = scope.Database.SkipTake<uSupportTicket>((page - 1) * PageSize, PageSize, sql);

return MapPageToUSupportPage(tickets, ticketCount, page, PageSize);
Expand Down Expand Up @@ -125,14 +125,25 @@ public override uSupportTicket Get(Guid id)
.Select("*")
.From(TicketTableAlias)
.GetFullTicket()
.Where($"[Id] = {id.ConvertGuidToSqlString()}");
.Where($"{TicketTableAlias}.Id = UPPER('{id}')");

var ticket = scope.Database.Fetch<uSupportTicket>(sql).FirstOrDefault();

return ticket;
}
}

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");
Expand Down
8 changes: 4 additions & 4 deletions src/uSupport/Services/uSupportTicketStatusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public uSupportTicketStatus GetDefaultStatus()
using (var scope = _scopeProvider.CreateScope())
{
var db = scope.Database;
var status = db.Query<uSupportTicketStatus>($"SELECT * FROM {TicketStatusTableAlias} WHERE [Default] = 'True'").FirstOrDefault();
var status = db.Query<uSupportTicketStatus>($"SELECT * FROM {TicketStatusTableAlias} WHERE [Default] = '1'").FirstOrDefault();

return status;
}
Expand All @@ -40,7 +40,7 @@ public IEnumerable<uSupportTicketStatus> GetActiveStatuses()
using (var scope = _scopeProvider.CreateScope())
{
var db = scope.Database;
var statuses = db.Query<uSupportTicketStatus>($"SELECT * FROM {TicketStatusTableAlias} WHERE [Active] = 'True'");
var statuses = db.Query<uSupportTicketStatus>($"SELECT * FROM {TicketStatusTableAlias} WHERE [Active] = '1'");

return statuses.ToList();
}
Expand All @@ -51,7 +51,7 @@ public IEnumerable<uSupportTicketStatus> GetResolvedStatuses()
using (var scope = _scopeProvider.CreateScope())
{
var db = scope.Database;
var statuses = db.Query<uSupportTicketStatus>($"SELECT * FROM {TicketStatusTableAlias} WHERE [Active] = 'False'");
var statuses = db.Query<uSupportTicketStatus>($"SELECT * FROM {TicketStatusTableAlias} WHERE [Active] = '0'");

return statuses.ToList();
}
Expand Down Expand Up @@ -84,7 +84,7 @@ public int GetStatusCount()
using (var scope = _scopeProvider.CreateScope())
{
var db = scope.Database;
return db.Query<uSupportTicketStatus>($"SELECT [Order] FROM {TicketStatusTableAlias}").ToList().Count;
return db.Query<int>($"SELECT COUNT([Order]) FROM {TicketStatusTableAlias}").FirstOrDefault();
}
}
}
Expand Down
Loading

0 comments on commit e1893c0

Please sign in to comment.