public ActionResult Approve(ReturnModel model) { var returnEntity = _returnRepository.GetById(model.Id); Validate(model, returnEntity, WorkflowActionName.Approve); if (ModelState.IsValid) { returnEntity = model.ToEntity(returnEntity); if (returnEntity.IsNew == true) { string number = _autoNumberService.GenerateNextAutoNumber(_dateTimeHelper.ConvertToUserTime(DateTime.UtcNow, DateTimeKind.Utc), returnEntity); returnEntity.Number = number; } //always set IsNew to false when saving returnEntity.IsNew = false; //update attributes _returnRepository.Update(returnEntity); //commit all changes in UI this._dbContext.SaveChanges(); //approve _returnService.Approve(returnEntity); //notification SuccessNotification(_localizationService.GetResource("Record.Saved")); return(Json(new { number = returnEntity.Number, isApproved = returnEntity.IsApproved })); } else { return(Json(new { Errors = ModelState.SerializeErrors() })); } }