This commit is contained in:
2021-09-14 19:21:25 +00:00
parent 08138894c9
commit 8a1c01b2e1
2 changed files with 127 additions and 50 deletions

View 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