public Response <DirectoryModel> Create(DirectoryCreateModel createModel) { try { using (var unitOfWork = new UnitOfWork()) { var last = unitOfWork.GetRepository <Directory>().GetAll().OrderByDescending(c => c.DirectoryId).FirstOrDefault(); Directory dir = new Directory { CreatedByUserId = createModel.CreatedByUserId, CreatedOnDate = DateTime.Now, DirectoryId = 1, ParentId = createModel.ParentId, LastModifiedByUserId = createModel.CreatedByUserId, LastModifiedOnDate = DateTime.Now, Name = createModel.Name, IsDelete = false, ModuleId = createModel.ModuleId, DepartmentId = createModel.DepartmentId }; if (last != null) { dir.DirectoryId = last.DirectoryId + 1; } unitOfWork.GetRepository <Directory>().Add(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)); } } catch (Exception ex) { return(new Response <DirectoryModel>(-1, ex.ToString(), null)); } }
public IHttpActionResult Create(DirectoryCreateModel createModel) { var result = handler.Create(createModel); return(Ok(result)); }