This commit is contained in:
@@ -191,6 +191,8 @@ namespace AyaNova.Biz
|
||||
|
||||
//and need TRANSLATION KEYS because any type could show in the event log at the client end
|
||||
|
||||
//AND QBI mirrors this too
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
using System.Linq;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
@@ -39,6 +40,20 @@ namespace AyaNova.Biz
|
||||
return await ct.Integration.AnyAsync(z => z.Id == id);
|
||||
}
|
||||
|
||||
internal async Task<bool> ExistsByIntegrationAppIdAsync(Guid IntegrationAppId)
|
||||
{
|
||||
return await ct.Integration.AnyAsync(z => z.IntegrationAppId == IntegrationAppId);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
//APPID FROM dbID
|
||||
internal async Task<Guid> AppIdFromDbIdAsync(long id)
|
||||
{
|
||||
return await ct.Integration.AsNoTracking().Where(z => z.Id == id).Select(z => z.IntegrationAppId).SingleOrDefaultAsync();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE
|
||||
//
|
||||
@@ -49,10 +64,10 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
await ct.Integration.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
@@ -60,12 +75,19 @@ namespace AyaNova.Biz
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//GET
|
||||
//
|
||||
internal async Task<Integration> GetAsync(Guid IntegrationAppId, bool logTheGetEvent = true, bool populatePartNames = false)
|
||||
//
|
||||
|
||||
internal async Task<Integration> GetAsync(long id, bool logTheGetEvent = true)
|
||||
{
|
||||
return await GetAsync(await AppIdFromDbIdAsync(id), logTheGetEvent);
|
||||
}
|
||||
|
||||
|
||||
internal async Task<Integration> GetAsync(Guid IntegrationAppId, bool logTheGetEvent = true)
|
||||
{
|
||||
var ret = await ct.Integration.AsNoTracking().Include(z => z.Items).SingleOrDefaultAsync(m => m.IntegrationAppId == IntegrationAppId);
|
||||
if (logTheGetEvent && ret != null)
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, ret.Id, BizType, AyaEvent.Retrieved), ct);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, ret.Id, BizType, AyaEvent.Retrieved), ct);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -89,7 +111,7 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
await ValidateAsync(putObject, dbObject);
|
||||
if (HasErrors) return null;
|
||||
ct.Replace(dbObject, putObject);
|
||||
@@ -106,14 +128,20 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
}
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct);
|
||||
|
||||
|
||||
|
||||
|
||||
return putObject;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
|
||||
internal async Task<bool> DeleteAsync(long id)
|
||||
{
|
||||
return await DeleteAsync(await AppIdFromDbIdAsync(id));
|
||||
}
|
||||
|
||||
internal async Task<bool> DeleteAsync(Guid IntegrationAppId)
|
||||
{
|
||||
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||
@@ -127,7 +155,7 @@ namespace AyaNova.Biz
|
||||
ValidateCanDelete(dbObject);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
|
||||
|
||||
ct.Integration.Remove(dbObject);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
@@ -141,7 +169,7 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
@@ -166,11 +194,11 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
//Name required
|
||||
//Name required
|
||||
if (proposedObj.IntegrationAppId == Guid.Empty)
|
||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "IntegrationAppId");
|
||||
|
||||
//If name is otherwise OK, check that name is unique
|
||||
//If name is otherwise OK, check that name is unique
|
||||
if (!PropertyHasErrors("IntegrationAppId"))
|
||||
{
|
||||
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
||||
@@ -178,7 +206,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "IntegrationAppId");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -188,7 +216,7 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user