Files
raven/server/AyaNova/biz/PartInventoryRequestDataListBiz.cs
2021-12-23 17:49:06 +00:00

95 lines
3.8 KiB
C#

using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Models;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace AyaNova.Biz
{
internal class PartInventoryRequestDataListBiz : BizObject, IReportAbleObject, IExportAbleObject
{
internal PartInventoryRequestDataListBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
{
ct = dbcontext;
UserId = currentUserId;
UserTranslationId = userTranslationId;
CurrentUserRoles = UserRoles;
BizType = AyaType.PartInventoryRequestDataList;
}
internal static PartInventoryRequestDataListBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
{
if (httpContext != null)
return new PartInventoryRequestDataListBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
else
return new PartInventoryRequestDataListBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdmin);
}
////////////////////////////////////////////////////////////////////////////////////////////////
//REPORTING
//
public async Task<JArray> GetReportData(DataListSelectedRequest dataListSelectedRequest, DateTime renderTimeOutExpiry)
{
var idList = dataListSelectedRequest.SelectedRowIds;
JArray ReportData = new JArray();
while (idList.Any())
{
var batch = idList.Take(IReportAbleObject.REPORT_DATA_BATCH_SIZE);
idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray();
//query for this batch, comes back in db natural order unfortunately
var batchResults = await ct.ViewPartInventoryRequestList.AsNoTracking().Where(z => batch.Contains(z.RequestId)).ToArrayAsync();
//order the results back into original
var orderedList = from id in batch join z in batchResults on id equals z.RequestId select z;
//cache frequent viz data
var AyaTypesEnumList = await AyaNova.Api.Controllers.EnumListController.GetEnumList(
StringUtil.TrimTypeName(typeof(AyaType).ToString()),
UserTranslationId,
CurrentUserRoles);
// using (var command = ct.Database.GetDbConnection().CreateCommand())
// {
// ct.Database.OpenConnection();
foreach (ViewPartInventoryRequestList w in orderedList)
{
//await PopulateVizFields(w, AyaTypesEnumList, command);
var jo = JObject.FromObject(w);
ReportData.Add(jo);
}
//}
}
return ReportData;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// IMPORT EXPORT
//
public async Task<JArray> GetExportData(DataListSelectedRequest dataListSelectedRequest, DateTime renderTimeOutExpiry)
{
//for now just re-use the report data code
//this may turn out to be the pattern for most biz object types but keeping it seperate allows for custom usage from time to time
return await GetReportData(dataListSelectedRequest, renderTimeOutExpiry);
}
/////////////////////////////////////////////////////////////////////
}//eoc
}//eons