This commit is contained in:
119
server/AyaNova/Controllers/ScheduleController.cs
Normal file
119
server/AyaNova/Controllers/ScheduleController.cs
Normal file
@@ -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<ScheduleController> log;
|
||||||
|
private readonly ApiServerState serverState;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dbcontext"></param>
|
||||||
|
/// <param name="logger"></param>
|
||||||
|
/// <param name="apiServerState"></param>
|
||||||
|
public ScheduleController(AyContext dbcontext, ILogger<ScheduleController> logger, ApiServerState apiServerState)
|
||||||
|
{
|
||||||
|
ct = dbcontext;
|
||||||
|
log = logger;
|
||||||
|
serverState = apiServerState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get personal schedule for parameters specified
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p">Personal schedule parameters</param>
|
||||||
|
/// <param name="apiVersion">From route path</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("personal")]
|
||||||
|
public async Task<IActionResult> 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
|
||||||
@@ -5,6 +5,13 @@ using AyaNova.Models;
|
|||||||
|
|
||||||
namespace AyaNova.DataList
|
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
|
internal class SchedulePersonalWorkOrderDataList : DataListProcessingBase, IDataListInternalCriteria
|
||||||
{
|
{
|
||||||
public SchedulePersonalWorkOrderDataList()
|
public SchedulePersonalWorkOrderDataList()
|
||||||
@@ -456,56 +463,7 @@ namespace AyaNova.DataList
|
|||||||
SqlValueColumnName = "viewworkorder.latitude"
|
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
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user