public void ChangeProductionBatchStatus(ProductionBatch entity, ChangeProductionBatchStatusModel model) { if (model.Status == Data.Constants.BatchStatus.New) { throw new Exception("Invalid status change"); } switch (model.Status) { case Data.Constants.BatchStatus.Started: entity.StartedTime = DateTime.UtcNow; break; case Data.Constants.BatchStatus.Finished: entity.FinishedTime = DateTime.UtcNow; break; } entity.Status = model.Status; PrepareUpdate(entity); }
public IActionResult ChangeStatus(int id, ChangeProductionBatchStatusModel model) { var entity = _service.ProductionBatchs.Id(id).FirstOrDefault(); if (entity == null) { return(NotFound(AppResult.NotFound())); } var validationData = _service.ValidateChangeProductionBatchStatus(User, entity, model); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } _service.ChangeProductionBatchStatus(entity, model); context.SaveChanges(); // must be in transaction var ev = _ev_service.ChangeProductionBatchStatus(entity, User); context.SaveChanges(); return(NoContent()); }
public ValidationData ValidateChangeProductionBatchStatus(ClaimsPrincipal principal, ProductionBatch entity, ChangeProductionBatchStatusModel model) { return(new ValidationData()); }