コード例 #1
0
 public Response <DirectoryModel> Update(int Id, DirectoryUpdateModel updateModel)
 {
     try
     {
         using (var unitOfWork = new UnitOfWork())
         {
             var dir = unitOfWork.GetRepository <Directory>().GetById(Id);
             if (dir != null)
             {
                 Ultis.TransferValues(dir, updateModel);
                 dir.Name                 = updateModel.Name;
                 dir.ParentId             = updateModel.ParentId;
                 dir.LastModifiedByUserId = updateModel.LastModifiedByUserId;
                 dir.LastModifiedOnDate   = DateTime.Now;
                 unitOfWork.GetRepository <Directory>().Update(dir);
                 if (unitOfWork.Save() >= 1)
                 {
                     return(GetById(dir.DirectoryId));
                 }
                 return(new Response <DirectoryModel>(0, "Lưu thông tin không thành công!", null));
             }
             else
             {
                 return(new Response <DirectoryModel>(0, "Không tìm thấy thư mục", null));
             }
         }
     }
     catch (Exception ex)
     {
         return(new Response <DirectoryModel>(-1, ex.ToString(), null));
     }
 }
コード例 #2
0
        public IHttpActionResult Update(int Id, DirectoryUpdateModel updateModel)
        {
            string UserId = Request.Headers.GetValues("UserId").FirstOrDefault();

            updateModel.LastModifiedByUserId = Convert.ToInt32(UserId);
            var result = handler.Update(Id, updateModel);

            return(Ok(result));
        }