This commit is contained in:
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.JsonPatch;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
@@ -115,59 +114,19 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Patch (update) PM
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id"></param>
|
|
||||||
/// <param name="concurrencyToken"></param>
|
|
||||||
/// <param name="objectPatch"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPatch("{id}/{concurrencyToken}")]
|
|
||||||
public async Task<IActionResult> PatchPM([FromRoute] long id, [FromRoute] uint concurrencyToken, [FromBody]JsonPatchDocument<PM> 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
|
|
||||||
PMBiz biz = PMBiz.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>
|
/// <summary>
|
||||||
/// Post PM
|
/// Post PM
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inObj"></param>
|
/// <param name="pmTemplateId"></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>
|
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||||
/// <returns></returns>
|
/// <returns>A created workorder ready to fill out</returns>
|
||||||
[HttpPost]
|
[HttpPost("Create")]
|
||||||
public async Task<IActionResult> PostPM([FromBody] PM inObj, ApiVersion apiVersion)
|
public async Task<IActionResult> PostPM([FromQuery] long? pmTemplateId, long? customerId, uint? serial, ApiVersion apiVersion)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
@@ -183,7 +142,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
//Create and validate
|
//Create and validate
|
||||||
PM o = await biz.CreateAsync(inObj);
|
PM o = await biz.CreateAsync(pmTemplateId,customerId, serial);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.JsonPatch;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using AyaNova.Models;
|
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>
|
/// <summary>
|
||||||
/// Post Quote
|
/// Post Quote
|
||||||
/// </summary>
|
/// </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>
|
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||||
/// <returns></returns>
|
/// <returns>A created workorder ready to fill out</returns>
|
||||||
[HttpPost]
|
[HttpPost("Create")]
|
||||||
public async Task<IActionResult> PostQuote([FromBody] Quote inObj, ApiVersion apiVersion)
|
public async Task<IActionResult> PostQuote([FromQuery] long? quoteTemplateId, long? customerId, uint? serial, ApiVersion apiVersion)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
@@ -183,7 +142,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
//Create and validate
|
//Create and validate
|
||||||
Quote o = await biz.CreateAsync(inObj);
|
Quote o = await biz.CreateAsync(quoteTemplateId,customerId, serial);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
internal class PMBiz : BizObject, ISearchAbleObject
|
internal class PMBiz : BizObject, ISearchAbleObject
|
||||||
{
|
{
|
||||||
|
//Feature specific roles
|
||||||
|
internal static AuthorizationRoles RolesAllowedToChangeSerial = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.AccountingFull;
|
||||||
|
|
||||||
internal PMBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
internal PMBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||||
{
|
{
|
||||||
@@ -60,28 +62,41 @@ namespace AyaNova.Biz
|
|||||||
//CREATE
|
//CREATE
|
||||||
|
|
||||||
//Called from route and also seeder
|
//Called from route and also seeder
|
||||||
internal async Task<PM> CreateAsync(PM inObj)
|
internal async Task<PM> CreateAsync(long? workorderTemplateId, long? customerId, uint? serial)
|
||||||
{
|
{
|
||||||
await ValidateAsync(inObj, null);
|
//Create and save to db a new workorder and return it
|
||||||
if (HasErrors)
|
//NOTE: Serial can be specified or edited after the fact in a limited way by full role specfic only!! (service manager, bizadminfull, accounting maybe)
|
||||||
return null;
|
|
||||||
else
|
if (serial != null && !Authorized.HasAnyRole(CurrentUserRoles, RolesAllowedToChangeSerial))
|
||||||
{
|
{
|
||||||
//do stuff with PM
|
AddError(ApiErrorCode.NOT_AUTHORIZED, "Serial");
|
||||||
PM outObj = inObj;
|
return null;
|
||||||
|
|
||||||
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
|
|
||||||
outObj.CustomFields = JsonUtil.CompactJson(outObj.CustomFields);
|
|
||||||
//Save to db
|
|
||||||
await ct.PM.AddAsync(outObj);
|
|
||||||
await ct.SaveChangesAsync();
|
|
||||||
//Handle child and associated items:
|
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
|
||||||
await SearchIndexAsync(outObj, true);
|
|
||||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
|
||||||
|
|
||||||
return outObj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// await ValidateAsync(inObj, null);
|
||||||
|
// if (HasErrors)
|
||||||
|
// return null;
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
//do stuff with PM
|
||||||
|
PM o = new PM();
|
||||||
|
o.Serial = serial ?? ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
||||||
|
|
||||||
|
//TODO: template
|
||||||
|
//TODO: CUSTOMER ID
|
||||||
|
|
||||||
|
|
||||||
|
//Save to db
|
||||||
|
await ct.PM.AddAsync(o);
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
//Handle child and associated items:
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, o.Id, BizType, AyaEvent.Created), ct);
|
||||||
|
await SearchIndexAsync(o, true);
|
||||||
|
// await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, o.Tags, null);
|
||||||
|
|
||||||
|
return o;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,34 +108,34 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
internal async Task<PM> DuplicateAsync(PM dbObj)
|
internal async Task<PM> DuplicateAsync(PM dbObj)
|
||||||
{
|
{
|
||||||
|
throw new System.NotImplementedException("STUB: WORKORDER DUPLICATE");
|
||||||
|
// PM outObj = new PM();
|
||||||
|
// CopyObject.Copy(dbObj, outObj, "Wiki");
|
||||||
|
// // outObj.Name = Util.StringUtil.NameUniquify(outObj.Name, 255);
|
||||||
|
// //generate unique name
|
||||||
|
// string newUniqueName = string.Empty;
|
||||||
|
// bool NotUnique = true;
|
||||||
|
// long l = 1;
|
||||||
|
// do
|
||||||
|
// {
|
||||||
|
// newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255);
|
||||||
|
// NotUnique = await ct.PM.AnyAsync(m => m.Name == newUniqueName);
|
||||||
|
// } while (NotUnique);
|
||||||
|
|
||||||
PM outObj = new PM();
|
// outObj.Name = newUniqueName;
|
||||||
CopyObject.Copy(dbObj, outObj, "Wiki");
|
|
||||||
// outObj.Name = Util.StringUtil.NameUniquify(outObj.Name, 255);
|
|
||||||
//generate unique name
|
|
||||||
string newUniqueName = string.Empty;
|
|
||||||
bool NotUnique = true;
|
|
||||||
long l = 1;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255);
|
|
||||||
NotUnique = await ct.PM.AnyAsync(m => m.Name == newUniqueName);
|
|
||||||
} while (NotUnique);
|
|
||||||
|
|
||||||
outObj.Name = newUniqueName;
|
|
||||||
|
|
||||||
|
|
||||||
outObj.Id = 0;
|
// outObj.Id = 0;
|
||||||
outObj.ConcurrencyToken = 0;
|
// outObj.ConcurrencyToken = 0;
|
||||||
|
|
||||||
await ct.PM.AddAsync(outObj);
|
// await ct.PM.AddAsync(outObj);
|
||||||
await ct.SaveChangesAsync();
|
// await ct.SaveChangesAsync();
|
||||||
|
|
||||||
//Handle child and associated items:
|
// //Handle child and associated items:
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||||
await SearchIndexAsync(outObj, true);
|
// await SearchIndexAsync(outObj, true);
|
||||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
// await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
||||||
return outObj;
|
// return outObj;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,22 +144,28 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
|
|
||||||
//put
|
//put
|
||||||
internal async Task<bool> PutAsync(PM dbObj, PM inObj)
|
internal async Task<bool> PutAsync(PM dbObj, PM putObj)
|
||||||
{
|
{
|
||||||
|
|
||||||
//make a snapshot of the original for validation but update the original to preserve workflow
|
// make a snapshot of the original for validation but update the original to preserve workflow
|
||||||
PM SnapshotOfOriginalDBObj = new PM();
|
PM SnapshotOfOriginalDBObj = new PM();
|
||||||
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
|
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
|
||||||
|
|
||||||
//Replace the db object with the PUT object
|
//Replace the db object with the PUT object
|
||||||
CopyObject.Copy(inObj, dbObj, "Id");
|
CopyObject.Copy(putObj, dbObj, "Id,Serial");
|
||||||
|
|
||||||
|
//if user has rights then change it, otherwise just ignore it and do the rest
|
||||||
|
if (SnapshotOfOriginalDBObj.Serial != putObj.Serial && Authorized.HasAnyRole(CurrentUserRoles, RolesAllowedToChangeSerial))
|
||||||
|
{
|
||||||
|
dbObj.Serial = putObj.Serial;
|
||||||
|
}
|
||||||
|
|
||||||
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
||||||
dbObj.CustomFields = JsonUtil.CompactJson(dbObj.CustomFields);
|
dbObj.CustomFields = JsonUtil.CompactJson(dbObj.CustomFields);
|
||||||
|
|
||||||
//Set "original" value of concurrency token to input token
|
//Set "original" value of concurrency token to input token
|
||||||
//this will allow EF to check it out
|
//this will allow EF to check it out
|
||||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
|
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = putObj.ConcurrencyToken;
|
||||||
|
|
||||||
|
|
||||||
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
||||||
@@ -159,42 +180,13 @@ namespace AyaNova.Biz
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//patch
|
|
||||||
internal async Task<bool> PatchAsync(PM dbObj, JsonPatchDocument<PM> objectPatch, uint concurrencyToken)
|
|
||||||
{
|
|
||||||
//Validate Patch is allowed
|
|
||||||
if (!ValidateJsonPatch<PM>.Validate(this, objectPatch)) return false;
|
|
||||||
|
|
||||||
//make a snapshot of the original for validation but update the original to preserve workflow
|
|
||||||
PM SnapshotOfOriginalDBObj = new PM();
|
|
||||||
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
|
|
||||||
|
|
||||||
//Do the patching
|
|
||||||
objectPatch.ApplyTo(dbObj);
|
|
||||||
|
|
||||||
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
|
||||||
dbObj.CustomFields = JsonUtil.CompactJson(dbObj.CustomFields);
|
|
||||||
|
|
||||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken;
|
|
||||||
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
|
||||||
if (HasErrors)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//Log event and save context
|
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
|
||||||
await SearchIndexAsync(dbObj, false);
|
|
||||||
|
|
||||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private async Task SearchIndexAsync(PM obj, bool isNew)
|
private async Task SearchIndexAsync(PM obj, bool isNew)
|
||||||
{
|
{
|
||||||
//SEARCH INDEXING
|
//SEARCH INDEXING
|
||||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationId, obj.Id, BizType);
|
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationId, obj.Id, BizType);
|
||||||
SearchParams.AddText(obj.Notes).AddText(obj.Name).AddText(obj.Wiki).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
SearchParams.AddText(obj.Notes).AddText(obj.Serial).AddText(obj.Wiki).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
||||||
|
|
||||||
if (isNew)
|
if (isNew)
|
||||||
await Search.ProcessNewObjectKeywordsAsync(SearchParams);
|
await Search.ProcessNewObjectKeywordsAsync(SearchParams);
|
||||||
@@ -207,7 +199,7 @@ namespace AyaNova.Biz
|
|||||||
var obj = await ct.PM.SingleOrDefaultAsync(m => m.Id == id);
|
var obj = await ct.PM.SingleOrDefaultAsync(m => m.Id == id);
|
||||||
var SearchParams = new Search.SearchIndexProcessObjectParameters();
|
var SearchParams = new Search.SearchIndexProcessObjectParameters();
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
SearchParams.AddText(obj.Notes).AddText(obj.Name).AddText(obj.Wiki).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
SearchParams.AddText(obj.Notes).AddText(obj.Serial).AddText(obj.Wiki).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
||||||
return SearchParams;
|
return SearchParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,20 +208,21 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
internal async Task<bool> DeleteAsync(PM dbObj)
|
internal async Task<bool> DeleteAsync(PM dbObj)
|
||||||
{
|
{
|
||||||
|
throw new System.NotImplementedException("STUB: WORKORDER DELETE");
|
||||||
//Determine if the object can be deleted, do the deletion tentatively
|
//Determine if the object can be deleted, do the deletion tentatively
|
||||||
//Probably also in here deal with tags and associated search text etc
|
//Probably also in here deal with tags and associated search text etc
|
||||||
|
|
||||||
//NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
|
//NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
|
||||||
if (HasErrors)
|
// if (HasErrors)
|
||||||
return false;
|
// return false;
|
||||||
ct.PM.Remove(dbObj);
|
// ct.PM.Remove(dbObj);
|
||||||
await ct.SaveChangesAsync();
|
// await ct.SaveChangesAsync();
|
||||||
|
|
||||||
//Log event
|
// //Log event
|
||||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
|
// await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Serial.ToString(), ct);
|
||||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, BizType);
|
// await Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, BizType);
|
||||||
await TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
|
// await TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
|
||||||
return true;
|
// return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -245,23 +238,23 @@ namespace AyaNova.Biz
|
|||||||
//run validation and biz rules
|
//run validation and biz rules
|
||||||
bool isNew = currentObj == null;
|
bool isNew = currentObj == null;
|
||||||
|
|
||||||
//Name required
|
// //Name required
|
||||||
if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
// if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
||||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
|
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
|
||||||
|
|
||||||
//Name must be less than 255 characters
|
// //Name must be less than 255 characters
|
||||||
if (proposedObj.Name.Length > 255)
|
// if (proposedObj.Name.Length > 255)
|
||||||
AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
|
// AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
|
||||||
|
|
||||||
//If name is otherwise OK, check that name is unique
|
// //If name is otherwise OK, check that name is unique
|
||||||
if (!PropertyHasErrors("Name"))
|
// if (!PropertyHasErrors("Name"))
|
||||||
{
|
// {
|
||||||
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
// //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
||||||
if (await ct.PM.AnyAsync(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
|
// if (await ct.PM.AnyAsync(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
|
||||||
{
|
// {
|
||||||
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
// AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
//Any form customizations to validate?
|
//Any form customizations to validate?
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
internal class QuoteBiz : BizObject, ISearchAbleObject
|
internal class QuoteBiz : BizObject, ISearchAbleObject
|
||||||
{
|
{
|
||||||
|
//Feature specific roles
|
||||||
|
internal static AuthorizationRoles RolesAllowedToChangeSerial = AuthorizationRoles.BizAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.AccountingFull;
|
||||||
|
|
||||||
internal QuoteBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
internal QuoteBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||||
{
|
{
|
||||||
@@ -60,28 +62,41 @@ namespace AyaNova.Biz
|
|||||||
//CREATE
|
//CREATE
|
||||||
|
|
||||||
//Called from route and also seeder
|
//Called from route and also seeder
|
||||||
internal async Task<Quote> CreateAsync(Quote inObj)
|
internal async Task<Quote> CreateAsync(long? workorderTemplateId, long? customerId, uint? serial)
|
||||||
{
|
{
|
||||||
await ValidateAsync(inObj, null);
|
//Create and save to db a new workorder and return it
|
||||||
if (HasErrors)
|
//NOTE: Serial can be specified or edited after the fact in a limited way by full role specfic only!! (service manager, bizadminfull, accounting maybe)
|
||||||
return null;
|
|
||||||
else
|
if (serial != null && !Authorized.HasAnyRole(CurrentUserRoles, RolesAllowedToChangeSerial))
|
||||||
{
|
{
|
||||||
//do stuff with Quote
|
AddError(ApiErrorCode.NOT_AUTHORIZED, "Serial");
|
||||||
Quote outObj = inObj;
|
return null;
|
||||||
|
|
||||||
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
|
|
||||||
outObj.CustomFields = JsonUtil.CompactJson(outObj.CustomFields);
|
|
||||||
//Save to db
|
|
||||||
await ct.Quote.AddAsync(outObj);
|
|
||||||
await ct.SaveChangesAsync();
|
|
||||||
//Handle child and associated items:
|
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
|
||||||
await SearchIndexAsync(outObj, true);
|
|
||||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
|
||||||
|
|
||||||
return outObj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// await ValidateAsync(inObj, null);
|
||||||
|
// if (HasErrors)
|
||||||
|
// return null;
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
//do stuff with Quote
|
||||||
|
Quote o = new Quote();
|
||||||
|
o.Serial = serial ?? ServerBootConfig.WORKORDER_SERIAL.GetNext();
|
||||||
|
|
||||||
|
//TODO: template
|
||||||
|
//TODO: CUSTOMER ID
|
||||||
|
|
||||||
|
|
||||||
|
//Save to db
|
||||||
|
await ct.Quote.AddAsync(o);
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
//Handle child and associated items:
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, o.Id, BizType, AyaEvent.Created), ct);
|
||||||
|
await SearchIndexAsync(o, true);
|
||||||
|
// await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, o.Tags, null);
|
||||||
|
|
||||||
|
return o;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -93,34 +108,34 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
internal async Task<Quote> DuplicateAsync(Quote dbObj)
|
internal async Task<Quote> DuplicateAsync(Quote dbObj)
|
||||||
{
|
{
|
||||||
|
throw new System.NotImplementedException("STUB: WORKORDER DUPLICATE");
|
||||||
|
// Quote outObj = new Quote();
|
||||||
|
// CopyObject.Copy(dbObj, outObj, "Wiki");
|
||||||
|
// // outObj.Name = Util.StringUtil.NameUniquify(outObj.Name, 255);
|
||||||
|
// //generate unique name
|
||||||
|
// string newUniqueName = string.Empty;
|
||||||
|
// bool NotUnique = true;
|
||||||
|
// long l = 1;
|
||||||
|
// do
|
||||||
|
// {
|
||||||
|
// newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255);
|
||||||
|
// NotUnique = await ct.Quote.AnyAsync(m => m.Name == newUniqueName);
|
||||||
|
// } while (NotUnique);
|
||||||
|
|
||||||
Quote outObj = new Quote();
|
// outObj.Name = newUniqueName;
|
||||||
CopyObject.Copy(dbObj, outObj, "Wiki");
|
|
||||||
// outObj.Name = Util.StringUtil.NameUniquify(outObj.Name, 255);
|
|
||||||
//generate unique name
|
|
||||||
string newUniqueName = string.Empty;
|
|
||||||
bool NotUnique = true;
|
|
||||||
long l = 1;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255);
|
|
||||||
NotUnique = await ct.Quote.AnyAsync(m => m.Name == newUniqueName);
|
|
||||||
} while (NotUnique);
|
|
||||||
|
|
||||||
outObj.Name = newUniqueName;
|
|
||||||
|
|
||||||
|
|
||||||
outObj.Id = 0;
|
// outObj.Id = 0;
|
||||||
outObj.ConcurrencyToken = 0;
|
// outObj.ConcurrencyToken = 0;
|
||||||
|
|
||||||
await ct.Quote.AddAsync(outObj);
|
// await ct.Quote.AddAsync(outObj);
|
||||||
await ct.SaveChangesAsync();
|
// await ct.SaveChangesAsync();
|
||||||
|
|
||||||
//Handle child and associated items:
|
// //Handle child and associated items:
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||||
await SearchIndexAsync(outObj, true);
|
// await SearchIndexAsync(outObj, true);
|
||||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
// await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, outObj.Tags, null);
|
||||||
return outObj;
|
// return outObj;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,22 +144,28 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
|
|
||||||
//put
|
//put
|
||||||
internal async Task<bool> PutAsync(Quote dbObj, Quote inObj)
|
internal async Task<bool> PutAsync(Quote dbObj, Quote putObj)
|
||||||
{
|
{
|
||||||
|
|
||||||
//make a snapshot of the original for validation but update the original to preserve workflow
|
// make a snapshot of the original for validation but update the original to preserve workflow
|
||||||
Quote SnapshotOfOriginalDBObj = new Quote();
|
Quote SnapshotOfOriginalDBObj = new Quote();
|
||||||
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
|
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
|
||||||
|
|
||||||
//Replace the db object with the PUT object
|
//Replace the db object with the PUT object
|
||||||
CopyObject.Copy(inObj, dbObj, "Id");
|
CopyObject.Copy(putObj, dbObj, "Id,Serial");
|
||||||
|
|
||||||
|
//if user has rights then change it, otherwise just ignore it and do the rest
|
||||||
|
if (SnapshotOfOriginalDBObj.Serial != putObj.Serial && Authorized.HasAnyRole(CurrentUserRoles, RolesAllowedToChangeSerial))
|
||||||
|
{
|
||||||
|
dbObj.Serial = putObj.Serial;
|
||||||
|
}
|
||||||
|
|
||||||
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
||||||
dbObj.CustomFields = JsonUtil.CompactJson(dbObj.CustomFields);
|
dbObj.CustomFields = JsonUtil.CompactJson(dbObj.CustomFields);
|
||||||
|
|
||||||
//Set "original" value of concurrency token to input token
|
//Set "original" value of concurrency token to input token
|
||||||
//this will allow EF to check it out
|
//this will allow EF to check it out
|
||||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
|
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = putObj.ConcurrencyToken;
|
||||||
|
|
||||||
|
|
||||||
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
||||||
@@ -159,42 +180,13 @@ namespace AyaNova.Biz
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//patch
|
|
||||||
internal async Task<bool> PatchAsync(Quote dbObj, JsonPatchDocument<Quote> objectPatch, uint concurrencyToken)
|
|
||||||
{
|
|
||||||
//Validate Patch is allowed
|
|
||||||
if (!ValidateJsonPatch<Quote>.Validate(this, objectPatch)) return false;
|
|
||||||
|
|
||||||
//make a snapshot of the original for validation but update the original to preserve workflow
|
|
||||||
Quote SnapshotOfOriginalDBObj = new Quote();
|
|
||||||
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
|
|
||||||
|
|
||||||
//Do the patching
|
|
||||||
objectPatch.ApplyTo(dbObj);
|
|
||||||
|
|
||||||
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
|
|
||||||
dbObj.CustomFields = JsonUtil.CompactJson(dbObj.CustomFields);
|
|
||||||
|
|
||||||
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken;
|
|
||||||
await ValidateAsync(dbObj, SnapshotOfOriginalDBObj);
|
|
||||||
if (HasErrors)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//Log event and save context
|
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
|
||||||
await SearchIndexAsync(dbObj, false);
|
|
||||||
|
|
||||||
await TagUtil.ProcessUpdateTagsInRepositoryAsync(ct, dbObj.Tags, SnapshotOfOriginalDBObj.Tags);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private async Task SearchIndexAsync(Quote obj, bool isNew)
|
private async Task SearchIndexAsync(Quote obj, bool isNew)
|
||||||
{
|
{
|
||||||
//SEARCH INDEXING
|
//SEARCH INDEXING
|
||||||
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationId, obj.Id, BizType);
|
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationId, obj.Id, BizType);
|
||||||
SearchParams.AddText(obj.Notes).AddText(obj.Name).AddText(obj.Wiki).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
SearchParams.AddText(obj.Notes).AddText(obj.Serial).AddText(obj.Wiki).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
||||||
|
|
||||||
if (isNew)
|
if (isNew)
|
||||||
await Search.ProcessNewObjectKeywordsAsync(SearchParams);
|
await Search.ProcessNewObjectKeywordsAsync(SearchParams);
|
||||||
@@ -207,7 +199,7 @@ namespace AyaNova.Biz
|
|||||||
var obj = await ct.Quote.SingleOrDefaultAsync(m => m.Id == id);
|
var obj = await ct.Quote.SingleOrDefaultAsync(m => m.Id == id);
|
||||||
var SearchParams = new Search.SearchIndexProcessObjectParameters();
|
var SearchParams = new Search.SearchIndexProcessObjectParameters();
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
SearchParams.AddText(obj.Notes).AddText(obj.Name).AddText(obj.Wiki).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
SearchParams.AddText(obj.Notes).AddText(obj.Serial).AddText(obj.Wiki).AddText(obj.Tags).AddCustomFields(obj.CustomFields);
|
||||||
return SearchParams;
|
return SearchParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,20 +208,21 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
internal async Task<bool> DeleteAsync(Quote dbObj)
|
internal async Task<bool> DeleteAsync(Quote dbObj)
|
||||||
{
|
{
|
||||||
|
throw new System.NotImplementedException("STUB: WORKORDER DELETE");
|
||||||
//Determine if the object can be deleted, do the deletion tentatively
|
//Determine if the object can be deleted, do the deletion tentatively
|
||||||
//Probably also in here deal with tags and associated search text etc
|
//Probably also in here deal with tags and associated search text etc
|
||||||
|
|
||||||
//NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
|
//NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
|
||||||
if (HasErrors)
|
// if (HasErrors)
|
||||||
return false;
|
// return false;
|
||||||
ct.Quote.Remove(dbObj);
|
// ct.Quote.Remove(dbObj);
|
||||||
await ct.SaveChangesAsync();
|
// await ct.SaveChangesAsync();
|
||||||
|
|
||||||
//Log event
|
// //Log event
|
||||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
|
// await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Serial.ToString(), ct);
|
||||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, BizType);
|
// await Search.ProcessDeletedObjectKeywordsAsync(dbObj.Id, BizType);
|
||||||
await TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
|
// await TagUtil.ProcessDeleteTagsInRepositoryAsync(ct, dbObj.Tags);
|
||||||
return true;
|
// return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -245,23 +238,23 @@ namespace AyaNova.Biz
|
|||||||
//run validation and biz rules
|
//run validation and biz rules
|
||||||
bool isNew = currentObj == null;
|
bool isNew = currentObj == null;
|
||||||
|
|
||||||
//Name required
|
// //Name required
|
||||||
if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
// if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
||||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
|
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
|
||||||
|
|
||||||
//Name must be less than 255 characters
|
// //Name must be less than 255 characters
|
||||||
if (proposedObj.Name.Length > 255)
|
// if (proposedObj.Name.Length > 255)
|
||||||
AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
|
// AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
|
||||||
|
|
||||||
//If name is otherwise OK, check that name is unique
|
// //If name is otherwise OK, check that name is unique
|
||||||
if (!PropertyHasErrors("Name"))
|
// if (!PropertyHasErrors("Name"))
|
||||||
{
|
// {
|
||||||
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
// //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
||||||
if (await ct.Quote.AnyAsync(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
|
// if (await ct.Quote.AnyAsync(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
|
||||||
{
|
// {
|
||||||
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
// AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
//Any form customizations to validate?
|
//Any form customizations to validate?
|
||||||
|
|||||||
Reference in New Issue
Block a user