This commit is contained in:
@@ -133,15 +133,15 @@ namespace AyaNova.Biz
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
//DELETE DIRECT CHILD OBJECTS
|
//DELETE DIRECT CHILD / RELATED OBJECTS
|
||||||
//(note: the convention is to allow deletion of children created *in* the same UI area so this will delete contacts, customer notes, but not workorders of this customer for example)
|
//(note: the convention is to allow deletion of children created *in* the same UI area so this will delete contacts, customer notes, but not workorders of this customer for example)
|
||||||
|
//Also these are done through their biz objects as there are notification, search and other concerns to be handled
|
||||||
{
|
{
|
||||||
var ContactIds = await ct.User.AsNoTracking().Where(z => z.CustomerId == id).Select(z => z.Id).ToListAsync();
|
var IDList = await ct.User.AsNoTracking().Where(z => z.CustomerId == id).Select(z => z.Id).ToListAsync();
|
||||||
if (ContactIds.Count() > 0)
|
if (IDList.Count() > 0)
|
||||||
{
|
{
|
||||||
UserBiz b = new UserBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
UserBiz b = new UserBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
||||||
foreach (long ItemId in ContactIds)
|
foreach (long ItemId in IDList)
|
||||||
if (!await b.DeleteAsync(ItemId, transaction))
|
if (!await b.DeleteAsync(ItemId, transaction))
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.CHILD_OBJECT_ERROR, null, $"CustomerContact [{ItemId}]: {b.GetErrorsAsString()}");
|
AddError(ApiErrorCode.CHILD_OBJECT_ERROR, null, $"CustomerContact [{ItemId}]: {b.GetErrorsAsString()}");
|
||||||
@@ -149,12 +149,13 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
var CustomerNoteIds = await ct.CustomerNote.AsNoTracking().Where(z => z.CustomerId == id).Select(z => z.Id).ToListAsync();
|
var IDList = await ct.CustomerNote.AsNoTracking().Where(z => z.CustomerId == id).Select(z => z.Id).ToListAsync();
|
||||||
if (CustomerNoteIds.Count() > 0)
|
if (IDList.Count() > 0)
|
||||||
{
|
{
|
||||||
CustomerNoteBiz b = new CustomerNoteBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
CustomerNoteBiz b = new CustomerNoteBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
||||||
foreach (long ItemId in CustomerNoteIds)
|
foreach (long ItemId in IDList)
|
||||||
if (!await b.DeleteAsync(ItemId, transaction))
|
if (!await b.DeleteAsync(ItemId, transaction))
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.CHILD_OBJECT_ERROR, null, $"CustomerNote [{ItemId}]: {b.GetErrorsAsString()}");
|
AddError(ApiErrorCode.CHILD_OBJECT_ERROR, null, $"CustomerNote [{ItemId}]: {b.GetErrorsAsString()}");
|
||||||
@@ -163,6 +164,20 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
var IDList = await ct.Review.AsNoTracking().Where(x => x.AType == AyaType.Customer && x.ObjectId == id).Select(x => x.Id).ToListAsync();
|
||||||
|
if (IDList.Count() > 0)
|
||||||
|
{
|
||||||
|
ReviewBiz b = new ReviewBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
||||||
|
foreach (long ItemId in IDList)
|
||||||
|
if (!await b.DeleteAsync(ItemId, transaction))
|
||||||
|
{
|
||||||
|
AddError(ApiErrorCode.CHILD_OBJECT_ERROR, null, $"Review [{ItemId}]: {b.GetErrorsAsString()}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ct.Customer.Remove(dbObject);
|
ct.Customer.Remove(dbObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -153,10 +153,11 @@ namespace AyaNova.Biz
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//DELETE
|
//DELETE
|
||||||
//
|
//
|
||||||
internal async Task<bool> DeleteAsync(long id)
|
internal async Task<bool> DeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||||
{
|
|
||||||
using (var transaction = await ct.Database.BeginTransactionAsync())
|
|
||||||
{
|
{
|
||||||
|
Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction transaction = null;
|
||||||
|
if (parentTransaction == null)
|
||||||
|
transaction = await ct.Database.BeginTransactionAsync();
|
||||||
var dbObject = await GetAsync(id, false);
|
var dbObject = await GetAsync(id, false);
|
||||||
if (dbObject == null)
|
if (dbObject == null)
|
||||||
{
|
{
|
||||||
@@ -176,10 +177,12 @@ namespace AyaNova.Biz
|
|||||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, BizType, ct);
|
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, BizType, ct);
|
||||||
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
|
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
|
||||||
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
|
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
|
||||||
|
//all good do the commit if it's ours
|
||||||
|
if (parentTransaction == null)
|
||||||
await transaction.CommitAsync();
|
await transaction.CommitAsync();
|
||||||
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
|
await HandlePotentialNotificationEvent(AyaEvent.Deleted, dbObject);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user