コード例 #1
0
        public IHttpActionResult Create(SendDocumentCreateModel createModel)
        {
            string UserId = Request.Headers.GetValues("UserId").FirstOrDefault();

            createModel.CreatedByUserId = Convert.ToInt32(UserId);
            var result = handler.Create(createModel);

            return(Ok(result));
        }
コード例 #2
0
 public Response <SendDocumentModel> Create(SendDocumentCreateModel createModel)
 {
     try
     {
         using (var unitOfwork = new UnitOfWork())
         {
             var user = unitOfwork.GetRepository <User>().GetById(createModel.CreatedByUserId);
             if (user == null)
             {
                 return(new Response <SendDocumentModel>(0, "", null));
             }
             SendDocument entity = new SendDocument
             {
                 SecretLevel             = createModel.SecretLevel,
                 ResponsibleUserId       = createModel.ResponsibleUserId,
                 ResponseForRDocId       = createModel.ResponseForRDocId,
                 SenderId                = createModel.SenderId,
                 SignedByUserId          = createModel.SignedByUserId,
                 Summary                 = createModel.Summary,
                 WrittenByUserId         = createModel.WrittenByUserId,
                 ResponseDeadline        = createModel.ResponseDeadline,
                 ReceiverContactPersonId = createModel.ReceiverContactPersonId,
                 ReceiverId              = createModel.ReceiverId,
                 Name                 = createModel.Name,
                 DocumentStatusId     = createModel.DocumentStatusId,
                 CategoryId           = createModel.CategoryId,
                 CreatedByUserId      = createModel.CreatedByUserId,
                 CreatedOnDate        = DateTime.Now,
                 DeliveryMethodId     = createModel.DeliveryMethodId,
                 LastModifiedOnDate   = DateTime.Now,
                 DepartmentId         = user.DepartmentId,
                 IsDelete             = false,
                 LastModifiedByUserId = createModel.CreatedByUserId,
                 SendDocumentId       = 1,
                 ResignedNumber       = createModel.ResignedNumber,
                 ResignedOnDate       = createModel.ResignedOnDate,
                 AttachedFileUrl      = createModel.AttachedFileUrl
             };
             var last = unitOfwork.GetRepository <SendDocument>().GetAll().OrderByDescending(d => d.SendDocumentId).FirstOrDefault();
             if (last != null)
             {
                 entity.SendDocumentId = last.SendDocumentId + 1;
             }
             unitOfwork.GetRepository <SendDocument>().Add(entity);
             if (unitOfwork.Save() >= 1)
             {
                 return(GetById(entity.SendDocumentId));
             }
             return(new Response <SendDocumentModel>(0, "Lưu thông tin không thành công", null));
         }
     }
     catch (Exception ex)
     {
         return(new Response <SendDocumentModel>(-1, ex.ToString(), null));
     }
 }