From 8a1c01b2e15468b9895c395c9a03b98d5692701e Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 14 Sep 2021 19:21:25 +0000 Subject: [PATCH] --- .../AyaNova/Controllers/ScheduleController.cs | 119 ++++++++++++++++++ .../SchedulePersonalWorkOrderDataList.cs | 58 ++------- 2 files changed, 127 insertions(+), 50 deletions(-) create mode 100644 server/AyaNova/Controllers/ScheduleController.cs diff --git a/server/AyaNova/Controllers/ScheduleController.cs b/server/AyaNova/Controllers/ScheduleController.cs new file mode 100644 index 00000000..42e35fce --- /dev/null +++ b/server/AyaNova/Controllers/ScheduleController.cs @@ -0,0 +1,119 @@ +using System.Threading.Tasks; +using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Routing; +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Logging; +using AyaNova.Models; +using AyaNova.Api.ControllerHelpers; +using AyaNova.Biz; +using Microsoft.EntityFrameworkCore; +using System.Linq; + +namespace AyaNova.Api.Controllers +{ + [ApiController] + [ApiVersion("8.0")] + [Route("api/v{version:apiVersion}/schedule")] + [Produces("application/json")] + [Authorize] + public class ScheduleController : ControllerBase + { + private readonly AyContext ct; + private readonly ILogger log; + private readonly ApiServerState serverState; + + /// + /// ctor + /// + /// + /// + /// + public ScheduleController(AyContext dbcontext, ILogger logger, ApiServerState apiServerState) + { + ct = dbcontext; + log = logger; + serverState = apiServerState; + } + + /// + /// Get personal schedule for parameters specified + /// + /// Personal schedule parameters + /// From route path + /// + [HttpPost("personal")] + public async Task PostPersonalSchedule([FromBody] PersonalScheduleParams p, ApiVersion apiVersion) + { + if (!serverState.IsOpen) + return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); + if (!ModelState.IsValid) + return BadRequest(new ApiErrorResponse(ModelState)); + + var UserId = UserIdFromContext.Id(HttpContext.Items); + var UType = UserTypeFromContext.Type(HttpContext.Items); + + if (UType == UserType.Service || UType == UserType.ServiceContractor) + { + + + var w = await ct.WorkOrder.AsSplitQuery().AsNoTracking() + .Include(s => s.States) + .Include(w => w.Items.OrderBy(item => item.Sequence)) + .ThenInclude(wi => wi.Expenses) + .Include(w => w.Items) + .ThenInclude(wi => wi.Labors) + .Include(w => w.Items) + .ThenInclude(wi => wi.Loans) + .Include(w => w.Items) + .ThenInclude(wi => wi.Parts) + .Include(w => w.Items) + .ThenInclude(wi => wi.PartRequests) + .Include(w => w.Items) + .ThenInclude(wi => wi.ScheduledUsers) + .Include(w => w.Items) + .ThenInclude(wi => wi.Tasks.OrderBy(t => t.Sequence)) + .Include(w => w.Items) + .ThenInclude(wi => wi.Travels) + .Include(w => w.Items) + .ThenInclude(wi => wi.Units) + .Include(w => w.Items) + .ThenInclude(wi => wi.OutsideServices) + .SingleOrDefaultAsync(z => z.Id == userId); + } + + + return Ok(r); + + } + + + public enum PersonalScheduleWorkOrderColorSource : int + { + None = 0, + WorkOrderStatus = 2, + WorkOrderItemStatus = 3, + WorkOrderItemPriority = 4 + + } + + public class PersonalScheduleParams + { + public DateTime Start { get; set; } + public DateTime End { get; set; } + public PersonalScheduleWorkOrderColorSource ColorSource {get;set;} + } + + public class PersonalScheduleListItem + { + public DateTime Start { get; set; } + public DateTime End { get; set; } + public string Name { get; set; } + public string Color { get; set; } + + } + //------------ + + + }//eoc +}//eons \ No newline at end of file diff --git a/server/AyaNova/DataList/SchedulePersonalWorkOrderDataList.cs b/server/AyaNova/DataList/SchedulePersonalWorkOrderDataList.cs index a4c4c9b4..1b0a751e 100644 --- a/server/AyaNova/DataList/SchedulePersonalWorkOrderDataList.cs +++ b/server/AyaNova/DataList/SchedulePersonalWorkOrderDataList.cs @@ -5,6 +5,13 @@ using AyaNova.Models; namespace AyaNova.DataList { + /* + Personal home-schedule user's schedule list + Note: based on workorderitemscheduleduserdatalist so can copy fields from there and adjust from there to save time if more required later + Criteria params: + userid (from here internally) + client provided params: {fetchstart [required], fetchend [required]} + */ internal class SchedulePersonalWorkOrderDataList : DataListProcessingBase, IDataListInternalCriteria { public SchedulePersonalWorkOrderDataList() @@ -456,56 +463,7 @@ namespace AyaNova.DataList SqlValueColumnName = "viewworkorder.latitude" }); - FieldDefinitions.Add(new DataListFieldDefinition - { - TKey = "AddressLongitude", - FieldKey = "workorderlongitude", - UiFieldDataType = (int)UiFieldDataType.Decimal, - SqlValueColumnName = "viewworkorder.longitude" - }); - - - FieldDefinitions.Add(new DataListFieldDefinition - { - TKey = "WorkOrderCloseByDate", - FieldKey = "WorkOrderCloseByDate", - UiFieldDataType = (int)UiFieldDataType.DateTime, - SqlValueColumnName = "viewworkorder.closebydate" - }); - - FieldDefinitions.Add(new DataListFieldDefinition - { - TKey = "WorkOrderAge", - FieldKey = "WorkOrderAge", - UiFieldDataType = (int)UiFieldDataType.TimeSpan, - SqlValueColumnName = "expwoage" - }); - - FieldDefinitions.Add(new DataListFieldDefinition - { - TKey = "TimeToCompletion", - FieldKey = "TimeToCompletion", - UiFieldDataType = (int)UiFieldDataType.TimeSpan, - SqlValueColumnName = "durationtocompleted" - }); - - - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom1", FieldKey = "workordercustom1", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom2", FieldKey = "workordercustom2", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom3", FieldKey = "workordercustom3", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom4", FieldKey = "workordercustom4", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom5", FieldKey = "workordercustom5", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom6", FieldKey = "workordercustom6", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom7", FieldKey = "workordercustom7", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom8", FieldKey = "workordercustom8", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom9", FieldKey = "workordercustom9", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom10", FieldKey = "workordercustom10", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom11", FieldKey = "workordercustom11", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom12", FieldKey = "workordercustom12", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom13", FieldKey = "workordercustom13", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom14", FieldKey = "workordercustom14", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom15", FieldKey = "workordercustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); - FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WorkOrderCustom16", FieldKey = "workordercustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "viewworkorder.customfields", TKeySection = "WorkOrder" }); + #endregion