This commit is contained in:
2020-05-04 21:16:18 +00:00
parent 4cf69b0bc3
commit a36d8bb118
4 changed files with 202 additions and 298 deletions

View File

@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
@@ -115,59 +114,19 @@ namespace AyaNova.Api.Controllers
/// <summary>
/// Patch (update) Quote
/// </summary>
/// <param name="id"></param>
/// <param name="concurrencyToken"></param>
/// <param name="objectPatch"></param>
/// <returns></returns>
[HttpPatch("{id}/{concurrencyToken}")]
public async Task<IActionResult> PatchQuote([FromRoute] long id, [FromRoute] uint concurrencyToken, [FromBody]JsonPatchDocument<Quote> objectPatch)
{
//https://dotnetcoretutorials.com/2017/11/29/json-patch-asp-net-core/
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
//Instantiate the business object handler
QuoteBiz biz = QuoteBiz.GetBiz(ct, HttpContext);
var o = await biz.GetAsync(id, false);
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
try
{
//patch and validate
if (!await biz.PatchAsync(o, objectPatch, concurrencyToken))
return BadRequest(new ApiErrorResponse(biz.Errors));
}
catch (DbUpdateConcurrencyException)
{
if (!await biz.ExistsAsync(id))
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
else
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
}
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
}
/// <summary>
/// Post Quote
/// </summary>
/// <param name="inObj"></param>
/// <param name="quoteTemplateId"></param>
/// <param name="customerId"></param>
/// <param name="serial">force a workorder number, leave null to autogenerate the next one in sequence (mostly used for import)</param>
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
/// <returns></returns>
[HttpPost]
public async Task<IActionResult> PostQuote([FromBody] Quote inObj, ApiVersion apiVersion)
/// <returns>A created workorder ready to fill out</returns>
[HttpPost("Create")]
public async Task<IActionResult> PostQuote([FromQuery] long? quoteTemplateId, long? customerId, uint? serial, ApiVersion apiVersion)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
@@ -183,7 +142,7 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState));
//Create and validate
Quote o = await biz.CreateAsync(inObj);
Quote o = await biz.CreateAsync(quoteTemplateId,customerId, serial);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
else