public ActionResult Approve(PhysicalCountModel model) { var physicalCount = _physicalCountRepository.GetById(model.Id); Validate(model, physicalCount, WorkflowActionName.Approve); if (ModelState.IsValid) { physicalCount = model.ToEntity(physicalCount); if (physicalCount.IsNew == true) { string number = _autoNumberService.GenerateNextAutoNumber(_dateTimeHelper.ConvertToUserTime(DateTime.UtcNow, DateTimeKind.Utc), physicalCount); physicalCount.Number = number; } //always set IsNew to false when saving physicalCount.IsNew = false; //update attributes _physicalCountRepository.Update(physicalCount); //commit all changes in UI this._dbContext.SaveChanges(); //approve _physicalCountService.Approve(physicalCount); //notification SuccessNotification(_localizationService.GetResource("Record.Saved")); return(Json(new { number = physicalCount.Number, isApproved = physicalCount.IsApproved })); } else { return(Json(new { Errors = ModelState.SerializeErrors() })); } }
private void Validate(PhysicalCountModel model, PhysicalCount physicalCount, string actionName) { if (!string.IsNullOrEmpty(actionName)) { if (actionName == WorkflowActionName.Approve) { if (model.PhysicalCountDate != null && model.PhysicalCountDate < DateTime.UtcNow.Date) { ModelState.AddModelError("", _localizationService.GetResource("PhysicalCount.PhysicalCountDateCannotEarlierThanToday")); } if (physicalCount.IsApproved == true) { ModelState.AddModelError("", _localizationService.GetResource("Record.AlreadyApproved")); } } } }