public IHttpActionResult Create(ReceivedDocumentCreateModel createModel) { string UserId = Request.Headers.GetValues("UserId").FirstOrDefault(); createModel.CreatedByUserId = Convert.ToInt32(UserId); var result = handler.Create(createModel); return(Ok(result)); }
public Response <ReceivedDocumentModel> Create(ReceivedDocumentCreateModel createModel) { try { using (var unitOfwork = new UnitOfWork()) { var user = unitOfwork.GetRepository <User>().GetById(createModel.CreatedByUserId); if (user == null) { return(new Response <ReceivedDocumentModel>(0, "", null)); } ReceivedDocument entity = new ReceivedDocument { SecretLevel = createModel.SecretLevel, ResponsibleUserId = createModel.ResponsibleUserId, ReceivedDocumentId = 1, SenderId = createModel.SenderId, SignedByUserId = createModel.SignedByUserId, Summary = createModel.Summary, DocumentDate = createModel.DocumentDate, DocumentIndex = createModel.DocumentIndex, ReceiverUserId = createModel.ReceiverUserId, DocumentStatusId = createModel.DocumentStatusId, ReceiverId = createModel.ReceiverId, Name = createModel.Name, CategoryId = createModel.CategoryId, CreatedByUserId = createModel.CreatedByUserId, CreatedOnDate = DateTime.Now, DeliveryMethodId = createModel.DeliveryMethodId, LastModifiedOnDate = DateTime.Now, DepartmentId = user.DepartmentId, IsDelete = false, LastModifiedByUserId = createModel.CreatedByUserId, ResignedNumber = createModel.ResignedNumber, ResignedOnDate = createModel.ResignedOnDate, AttachedFileUrl = createModel.AttachedFileUrl }; var last = unitOfwork.GetRepository <ReceivedDocument>().GetAll().OrderByDescending(d => d.ReceivedDocumentId).FirstOrDefault(); if (last != null) { entity.ReceivedDocumentId = last.ReceivedDocumentId + 1; } unitOfwork.GetRepository <ReceivedDocument>().Add(entity); if (unitOfwork.Save() >= 1) { return(GetById(entity.ReceivedDocumentId)); } return(new Response <ReceivedDocumentModel>(0, "Lưu thông tin không thành công", null)); } } catch (Exception ex) { return(new Response <ReceivedDocumentModel>(-1, ex.ToString(), null)); } }