This commit is contained in:
2021-06-30 20:27:35 +00:00
parent 41da081ce5
commit 779a695ff7
4 changed files with 133 additions and 133 deletions

View File

@@ -60,29 +60,29 @@ namespace AyaNova.Api.Controllers
return CreatedAtAction(nameof(PurchaseOrderController.GetPurchaseOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o)); return CreatedAtAction(nameof(PurchaseOrderController.GetPurchaseOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
} }
/// <summary> // /// <summary>
/// Duplicate PurchaseOrder // /// Duplicate PurchaseOrder
/// (Wiki and Attachments are not duplicated) // /// (Wiki and Attachments are not duplicated)
/// </summary> // /// </summary>
/// <param name="id">Source object id</param> // /// <param name="id">Source object id</param>
/// <param name="apiVersion">From route path</param> // /// <param name="apiVersion">From route path</param>
/// <returns>PurchaseOrder</returns> // /// <returns>PurchaseOrder</returns>
[HttpPost("duplicate/{id}")] // [HttpPost("duplicate/{id}")]
public async Task<IActionResult> DuplicatePurchaseOrder([FromRoute] long id, ApiVersion apiVersion) // public async Task<IActionResult> DuplicatePurchaseOrder([FromRoute] long id, 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));
PurchaseOrderBiz biz = PurchaseOrderBiz.GetBiz(ct, HttpContext); // PurchaseOrderBiz biz = PurchaseOrderBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType)) // if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse()); // return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid) // if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); // return BadRequest(new ApiErrorResponse(ModelState));
PurchaseOrder o = await biz.DuplicateAsync(id); // PurchaseOrder o = await biz.DuplicateAsync(id);
if (o == null) // if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors)); // return BadRequest(new ApiErrorResponse(biz.Errors));
else // else
return CreatedAtAction(nameof(PurchaseOrderController.GetPurchaseOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o)); // return CreatedAtAction(nameof(PurchaseOrderController.GetPurchaseOrder), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
} // }
/// <summary> /// <summary>
/// Get PurchaseOrder /// Get PurchaseOrder

View File

@@ -159,35 +159,35 @@ namespace AyaNova.Api.Controllers
} }
} }
/// <summary> // /// <summary>
/// Duplicate User // /// Duplicate User
/// (Wiki and Attachments are not duplicated) // /// (Wiki and Attachments are not duplicated)
/// </summary> // /// </summary>
/// <param name="id">Source object id</param> // /// <param name="id">Source object id</param>
/// <param name="apiVersion">From route path</param> // /// <param name="apiVersion">From route path</param>
/// <returns>User</returns> // /// <returns>User</returns>
[HttpPost("duplicate/{id}")] // [HttpPost("duplicate/{id}")]
public async Task<IActionResult> DuplicateUser([FromRoute] long id, ApiVersion apiVersion) // public async Task<IActionResult> DuplicateUser([FromRoute] long id, 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));
UserBiz biz = UserBiz.GetBiz(ct, HttpContext); // UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
//Also used for Contacts (customer type user or ho type user) // //Also used for Contacts (customer type user or ho type user)
//by users with no User right so further biz rule required depending on usertype // //by users with no User right so further biz rule required depending on usertype
//this is just phase 1 // //this is just phase 1
if (!Authorized.HasCreateRole(HttpContext.Items, AyaType.User) && !Authorized.HasCreateRole(HttpContext.Items, AyaType.Customer)) // if (!Authorized.HasCreateRole(HttpContext.Items, AyaType.User) && !Authorized.HasCreateRole(HttpContext.Items, AyaType.Customer))
return StatusCode(403, new ApiNotAuthorizedResponse()); // return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid) // if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); // return BadRequest(new ApiErrorResponse(ModelState));
User o = await biz.DuplicateAsync(id); // User o = await biz.DuplicateAsync(id);
if (o == null) // if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors)); // return BadRequest(new ApiErrorResponse(biz.Errors));
else // else
return CreatedAtAction(nameof(UserController.GetUser), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o)); // return CreatedAtAction(nameof(UserController.GetUser), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
} // }
/// <summary> /// <summary>

View File

@@ -74,45 +74,45 @@ namespace AyaNova.Biz
} }
} }
//////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////
//DUPLICATE // //DUPLICATE
// // //
internal async Task<PurchaseOrder> DuplicateAsync(long id) // internal async Task<PurchaseOrder> DuplicateAsync(long id)
{ // {
//TODO: allow this but only with ZEROS set for the actual received amount and ignore woitempart requested during dupe? // //TODO: allow this but only with ZEROS set for the actual received amount and ignore woitempart requested during dupe?
var dbObject = await GetAsync(id, false, false); // var dbObject = await GetAsync(id, false, false);
if (dbObject == null) // if (dbObject == null)
{ // {
AddError(ApiErrorCode.NOT_FOUND, "id"); // AddError(ApiErrorCode.NOT_FOUND, "id");
return null; // return null;
} // }
PurchaseOrder newObject = new PurchaseOrder(); // PurchaseOrder newObject = new PurchaseOrder();
CopyObject.Copy(dbObject, newObject, "Wiki,Serial"); // CopyObject.Copy(dbObject, newObject, "Wiki,Serial");
newObject.Id = 0; // newObject.Id = 0;
newObject.Concurrency = 0; // newObject.Concurrency = 0;
newObject.Status = PurchaseOrderStatus.OpenNotYetOrdered; // newObject.Status = PurchaseOrderStatus.OpenNotYetOrdered;
foreach (var item in newObject.Items) // foreach (var item in newObject.Items)
{ // {
item.Id = 0; // item.Id = 0;
item.Concurrency = 0; // item.Concurrency = 0;
item.QuantityReceived = 0; // item.QuantityReceived = 0;
item.ReceivedCost = 0; // item.ReceivedCost = 0;
item.ReceivedDate = null; // item.ReceivedDate = null;
item.PurchaseOrderId = 0; // item.PurchaseOrderId = 0;
item.WorkorderItemPartRequestId = null; // item.WorkorderItemPartRequestId = null;
item.PartRequestedById = null; // item.PartRequestedById = null;
} // }
await ct.PurchaseOrder.AddAsync(newObject); // await ct.PurchaseOrder.AddAsync(newObject);
await ct.SaveChangesAsync(); // await ct.SaveChangesAsync();
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct); // await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await SearchIndexAsync(newObject, true); // await SearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null); // await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject); // await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
await SetDisplayFields(newObject); // await SetDisplayFields(newObject);
return newObject; // return newObject;
} // }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//GET //GET

View File

@@ -286,56 +286,56 @@ namespace AyaNova.Biz
} }
} }
//////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////
//DUPLICATE // //DUPLICATE
// // //
internal async Task<User> DuplicateAsync(long id) // internal async Task<User> DuplicateAsync(long id)
{ // {
User dbObject = await GetAsync(id, false); // User dbObject = await GetAsync(id, false);
if (dbObject == null) // if (dbObject == null)
{ // {
AddError(ApiErrorCode.NOT_FOUND, "id"); // AddError(ApiErrorCode.NOT_FOUND, "id");
return null; // return null;
} // }
//Also used for Contacts (customer type user or ho type user) // //Also used for Contacts (customer type user or ho type user)
//by users with no User right but with Customer rights so need to double check here // //by users with no User right but with Customer rights so need to double check here
if ( // if (
(dbObject.IsOutsideUser && !Authorized.HasCreateRole(CurrentUserRoles, AyaType.Customer)) || // (dbObject.IsOutsideUser && !Authorized.HasCreateRole(CurrentUserRoles, AyaType.Customer)) ||
(!dbObject.IsOutsideUser && !Authorized.HasCreateRole(CurrentUserRoles, AyaType.User)) // (!dbObject.IsOutsideUser && !Authorized.HasCreateRole(CurrentUserRoles, AyaType.User))
) // )
{ // {
AddError(ApiErrorCode.NOT_AUTHORIZED); // AddError(ApiErrorCode.NOT_AUTHORIZED);
return null; // return null;
} // }
User newObject = new User(); // User newObject = new User();
CopyObject.Copy(dbObject, newObject, "Id, Salt, Login, Password, CurrentAuthToken, DlKey, DlKeyExpire, Wiki, Serial"); // CopyObject.Copy(dbObject, newObject, "Id, Salt, Login, Password, CurrentAuthToken, DlKey, DlKeyExpire, Wiki, Serial");
string newUniqueName = string.Empty; // string newUniqueName = string.Empty;
bool NotUnique = true; // bool NotUnique = true;
long l = 1; // long l = 1;
do // do
{ // {
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255); // newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255);
NotUnique = await ct.User.AnyAsync(z => z.Name == newUniqueName); // NotUnique = await ct.User.AnyAsync(z => z.Name == newUniqueName);
} while (NotUnique); // } while (NotUnique);
newObject.Name = newUniqueName; // newObject.Name = newUniqueName;
newObject.Id = 0; // newObject.Id = 0;
newObject.Concurrency = 0; // newObject.Concurrency = 0;
newObject.Salt = Hasher.GenerateSalt(); // newObject.Salt = Hasher.GenerateSalt();
newObject.Password = Hasher.GenerateSalt(); // newObject.Password = Hasher.GenerateSalt();
newObject.Login = Hasher.GenerateSalt(); // newObject.Login = Hasher.GenerateSalt();
newObject.UserOptions = new UserOptions(); // newObject.UserOptions = new UserOptions();
newObject.UserOptions.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID; // newObject.UserOptions.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
await ct.User.AddAsync(newObject); // await ct.User.AddAsync(newObject);
await ct.SaveChangesAsync(); // await ct.SaveChangesAsync();
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct); // await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
await SearchIndexAsync(newObject, true); // await SearchIndexAsync(newObject, true);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null); // await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject); // await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
return newObject; // return newObject;
} // }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
/// GET /// GET