This commit is contained in:
2020-12-29 23:20:39 +00:00
parent 68b55860f2
commit c5daf3340b
6 changed files with 77 additions and 6 deletions

View File

@@ -56,11 +56,9 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
if (id == 0)
return Ok(ApiOkResponse.Response(ayType.ToString()));
using (var command = ct.Database.GetDbConnection().CreateCommand())
{
ct.Database.OpenConnection();
return Ok(ApiOkResponse.Response(BizObjectNameFetcherDirect.Name(ayType, id, command)));
}
return Ok(ApiOkResponse.Response(BizObjectNameFetcherDirect.Name(ayType, id, ct)));
}

View File

@@ -108,6 +108,14 @@ namespace AyaNova.Biz
return await ct.Reminder.AnyAsync(z => z.Id == id);
case AyaType.Review:
return await ct.Review.AnyAsync(z => z.Id == id);
case AyaType.ServiceRate:
return await ct.ServiceRate.AnyAsync(z => z.Id == id);
case AyaType.TravelRate:
return await ct.TravelRate.AnyAsync(z => z.Id == id);
case AyaType.TaxCode:
return await ct.TaxCode.AnyAsync(z => z.Id == id);
case AyaType.ServiceBank:
return await ct.ServiceBank.AnyAsync(z => z.Id == id);
default:
throw new System.NotSupportedException($"AyaNova.Biz.BizObjectExistsInDatabase::ExistsAsync type {objectType.ToString()} is not supported");
}

View File

@@ -98,6 +98,8 @@ namespace AyaNova.Biz
return new TravelRateBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
case AyaType.TaxCode:
return new TaxCodeBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
case AyaType.ServiceBank:
return new ServiceBankBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
namespace AyaNova.Biz
{
@@ -10,6 +11,7 @@ namespace AyaNova.Biz
{
try
{
cmd.CommandText = $"select PUBLIC.AYGETNAME({id}, {(int)ayaType}) as m";
// cmd.CommandText = $"SELECT m.{COLUMN} FROM {TABLE} AS m WHERE m.id = {id} LIMIT 1";
using (var dr = cmd.ExecuteReader())
@@ -21,6 +23,18 @@ namespace AyaNova.Biz
throw;
}
}
//warning: use the above in a loop, not this one
internal static string Name(AyaType ayaType, long id, AyaNova.Models.AyContext ct)
{
using (var command = ct.Database.GetDbConnection().CreateCommand())
{
ct.Database.OpenConnection();
return Name(ayaType, id, command);
}
}
}//eoc
}//eons

View File

@@ -132,7 +132,7 @@ namespace AyaNova.Biz
/////////////////////////////////////////
// PROCESS STANDARD CREATE NOTIFICATION
// PROCESS STANDARD MODIFIED NOTIFICATION
//
//
public static async Task ProcessStandardObjectModifiedEvents(ICoreBizObjectModel newObject, AyContext ct)

View File

@@ -110,8 +110,18 @@ namespace AyaNova.Biz
//Name required
if (string.IsNullOrWhiteSpace(proposedObj.Name))
{
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
return;
}
//Object exists?
if (!await BizObjectExistsInDatabase.ExistsAsync(proposedObj.ObjectType, proposedObj.ObjectId, ct))
{
AddError(ApiErrorCode.NOT_FOUND, "generalerror", $"Bankable source object specified doesn't exist [type:{proposedObj.ObjectType}, id:{proposedObj.ObjectId}]");
return;
}
/*
"CONSTRAINT UNQ_ServiceBank UNIQUE (entrydate, objectid, objecttype, incidentsbalance, hoursbalance, currencybalance), " +
"CONSTRAINT UNQ_ServiceBank_Previous_values UNIQUE (lastentrydate, objectid, objecttype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance), " +
@@ -241,6 +251,45 @@ namespace AyaNova.Biz
await NotifyEventHelper.ProcessStandardObjectEvents(ayaEvent, proposedObj, ct);
//SPECIFIC EVENTS FOR THIS OBJECT
var o = (ServiceBank)proposedObj;
//SERVICE BANK DEPLETED
{
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ServiceBankDepleted).ToListAsync();
string SourceName = string.Empty;
if (subs.Count > 0)
SourceName = BizObjectNameFetcherDirect.Name(o.ObjectType, o.ObjectId, ct);
foreach (var sub in subs)
{
//not for inactive users
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
//Has any of the balances changed and is that changed balance within this users selected threshold?
//decvalue here refers to the balance left
if (
(o.LastCurrencyBalance != null && o.CurrencyBalance != o.LastCurrencyBalance && o.CurrencyBalance <= sub.DecValue)
|| (o.LastHoursBalance != null && o.HoursBalance != o.LastHoursBalance && o.HoursBalance <= sub.DecValue)
|| (o.LastIncidentsBalance != null && o.IncidentsBalance != o.LastIncidentsBalance && o.IncidentsBalance <= sub.DecValue)
)
{
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.ServiceBankDepleted,
UserId = sub.UserId,
AyaType = o.ObjectType,
ObjectId = o.ObjectId,
NotifySubscriptionId = sub.Id,
Name = SourceName
};
await ct.NotifyEvent.AddAsync(n);
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
await ct.SaveChangesAsync();
}
}
}
}//end of process notifications