This commit is contained in:
@@ -113,7 +113,8 @@ namespace AyaNova.Biz
|
||||
CustomerServiceRequest = 54,
|
||||
ServiceBank = 55,
|
||||
OpsNotificationSettings = 56,
|
||||
Report = 57
|
||||
Report = 57,
|
||||
DashboardView=58
|
||||
|
||||
|
||||
|
||||
|
||||
130
server/AyaNova/biz/DashboardViewBiz.cs
Normal file
130
server/AyaNova/biz/DashboardViewBiz.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using AyaNova.Util;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
|
||||
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
//Only one dashboard view per user and there is always one so no delete method, not create method
|
||||
internal class DashboardViewBiz : BizObject
|
||||
{
|
||||
|
||||
internal DashboardViewBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
UserId = currentUserId;
|
||||
UserTranslationId = userTranslationId;
|
||||
CurrentUserRoles = UserRoles;
|
||||
BizType = AyaType.DashboardView;
|
||||
}
|
||||
|
||||
internal static DashboardViewBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||
{
|
||||
if (httpContext != null)
|
||||
return new DashboardViewBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||
else
|
||||
return new DashboardViewBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//EXISTS
|
||||
internal async Task<bool> ExistsAsync(long id)
|
||||
{
|
||||
return await ct.DashboardView.AnyAsync(z => z.Id == id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// GET
|
||||
|
||||
//Get one - will create if there isn't one to get
|
||||
internal async Task<DashboardView> GetAsync()
|
||||
{
|
||||
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
||||
var ret = await ct.DashboardView.SingleOrDefaultAsync(z => z.UserId == UserId);
|
||||
if (ret == null)
|
||||
{
|
||||
ret = new DashboardView();
|
||||
ret.UserId = UserId;
|
||||
ct.DashboardView.Add(ret);
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//UPDATE
|
||||
//
|
||||
|
||||
//put
|
||||
internal async Task<bool> PutAsync(DashboardView dbObject, DashboardView inObj)
|
||||
{
|
||||
//always only current user id
|
||||
inObj.UserId = UserId;
|
||||
|
||||
//Replace the db object with the PUT object
|
||||
CopyObject.Copy(inObj, dbObject, "Id");
|
||||
//Set "original" value of concurrency token to input token
|
||||
//this will allow EF to check it out
|
||||
ct.Entry(dbObject).OriginalValues["Concurrency"] = inObj.Concurrency;
|
||||
|
||||
Validate(dbObject, false);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
//
|
||||
|
||||
//Can save or update?
|
||||
private void Validate(DashboardView inObj, bool isNew)
|
||||
{
|
||||
//Filter json must parse
|
||||
//this is all automated normally so not going to do too much parsing here
|
||||
//just ensure it's basically there
|
||||
if (!string.IsNullOrWhiteSpace(inObj.View))
|
||||
{
|
||||
try
|
||||
{
|
||||
var v = JArray.Parse(inObj.View);
|
||||
|
||||
}
|
||||
catch (Newtonsoft.Json.JsonReaderException ex)
|
||||
{
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", "ListView is not valid JSON string: " + ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
}//eons
|
||||
|
||||
Reference in New Issue
Block a user