public IHttpActionResult Finish(int Id, FinishConfirmModel model) { string UserId = Request.Headers.GetValues("UserId").FirstOrDefault(); model.UserId = Convert.ToInt32(UserId); var result = handler.Finish(Id, model); return(Ok(result)); }
public Response <DocumentConfirmModel> Finish(int Id, FinishConfirmModel model) { try { using (var unitOfWork = new UnitOfWork()) { var entity = unitOfWork.GetRepository <DocumentConfirm>().GetById(Id); if (entity != null) { if (entity.CreatedByUserId != model.UserId) { return(new Response <DocumentConfirmModel>(0, "Bạn không phải là tác giả", null)); } entity.IsFinished = 1; entity.UpdatedOnDate = DateTime.Now; unitOfWork.GetRepository <DocumentConfirm>().Update(entity); // var tmp = unitOfWork.GetRepository <DocumentProcess>().Get(d => d.Id == model.ProcessId && d.TaskType == (int)TaskType.CONFIRM); if (tmp == null) { return(new Response <DocumentConfirmModel>(0, "Bạn chưa khởi tạo tiến trình xử lý cho tài liệu này", null)); } tmp.Status = (int)DocumentProcessStatus.FINISHED; unitOfWork.GetRepository <DocumentProcess>().Update(tmp); // //var next = unitOfWork.GetRepository<DocumentProcess>().GetMany(d => d.Id == model.ProcessId && d.Status < 1).OrderBy(d => d.OrderIndex).FirstOrDefault(); //if (next != null) //{ // next.Status = (int)DocumentProcessStatus.INPROCESS; // unitOfWork.GetRepository<DocumentProcess>().Update(next); //} if (unitOfWork.Save() >= 1) { return(GetById(entity.ConfirmId)); } return(new Response <DocumentConfirmModel>(0, "Saving data not successful!", null)); } return(new Response <DocumentConfirmModel>(0, "Id is not valid", null)); } } catch (Exception ex) { return(new Response <DocumentConfirmModel>(-1, ex.ToString(), null)); } }