public static bool put_CAT_LinhVuc(AppEntities db, int ID, DTO_CAT_LinhVuc item, string Username) { bool result = false; var dbitem = db.tbl_CAT_LinhVuc.Find(ID); if (dbitem != null) { dbitem.ParentID = item.ParentID; dbitem.Name = item.Name; dbitem.Note = item.Note; dbitem.Sort = item.Sort; dbitem.IsDisabled = item.IsDisabled; dbitem.IsDeleted = item.IsDeleted; dbitem.ModifiedBy = Username; dbitem.ModifiedDate = DateTime.Now; try { db.SaveChanges(); BS_CUS_Version.update_CUS_Version(db, null, "DTO_CAT_LinhVuc", DateTime.Now, Username); result = true; } catch (DbEntityValidationException e) { errorLog.logMessage("put_CAT_LinhVuc", e); result = false; } } return(result); }
public IHttpActionResult Get(int id) { DTO_CAT_LinhVuc tbl_CAT_LinhVuc = BS_CAT_LinhVuc.get_CAT_LinhVuc(db, id); if (tbl_CAT_LinhVuc == null) { return(NotFound()); } return(Ok(tbl_CAT_LinhVuc)); }
public IHttpActionResult Post(DTO_CAT_LinhVuc tbl_CAT_LinhVuc) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DTO_CAT_LinhVuc result = BS_CAT_LinhVuc.post_CAT_LinhVucCustom(db, tbl_CAT_LinhVuc, Username); if (result != null) { return(CreatedAtRoute("get_CAT_LinhVuc", new { id = result.ID }, result)); } return(Conflict()); }
public static DTO_CAT_LinhVuc post_CAT_LinhVuc(AppEntities db, DTO_CAT_LinhVuc item, string Username) { tbl_CAT_LinhVuc dbitem = new tbl_CAT_LinhVuc(); if (item != null) { dbitem.ParentID = item.ParentID; dbitem.Name = item.Name; dbitem.Note = item.Note; dbitem.Sort = item.Sort; dbitem.IsDisabled = item.IsDisabled; dbitem.IsDeleted = item.IsDeleted; dbitem.CreatedBy = Username; dbitem.CreatedDate = DateTime.Now; dbitem.ModifiedBy = Username; dbitem.ModifiedDate = DateTime.Now; try { db.tbl_CAT_LinhVuc.Add(dbitem); db.SaveChanges(); BS_CUS_Version.update_CUS_Version(db, null, "DTO_CAT_LinhVuc", DateTime.Now, Username); item.ID = dbitem.ID; item.CreatedBy = dbitem.CreatedBy; item.CreatedDate = dbitem.CreatedDate; item.ModifiedBy = dbitem.ModifiedBy; item.ModifiedDate = dbitem.ModifiedDate; } catch (DbEntityValidationException e) { errorLog.logMessage("post_CAT_LinhVuc", e); item = null; } } return(item); }
public IHttpActionResult Put(int id, DTO_CAT_LinhVuc tbl_CAT_LinhVuc) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tbl_CAT_LinhVuc.ID) { return(BadRequest()); } bool result = BS_CAT_LinhVuc.put_CAT_LinhVucCustom(db, id, tbl_CAT_LinhVuc, Username); if (result) { return(StatusCode(HttpStatusCode.NoContent)); } else { return(NotFound()); } }
public static DTO_CAT_LinhVuc post_CAT_LinhVucCustom(AppEntities db, DTO_CAT_LinhVuc item, string Username) { tbl_CAT_LinhVuc dbitem = new tbl_CAT_LinhVuc(); if (item != null) { dbitem.ParentID = item.ParentID; dbitem.Name = item.Name; dbitem.Note = item.Note; dbitem.Sort = item.Sort; dbitem.IsDisabled = item.IsDisabled; dbitem.IsDeleted = item.IsDeleted; dbitem.CreatedBy = Username; dbitem.CreatedDate = DateTime.Now; dbitem.ModifiedBy = Username; dbitem.ModifiedDate = DateTime.Now; try { db.tbl_CAT_LinhVuc.Add(dbitem); db.SaveChanges(); // Tạo thư mục var folder = db.tbl_CUS_DOC_Folder.FirstOrDefault(c => c.IDLinhVuc == dbitem.ID); if (folder == null) { folder = new tbl_CUS_DOC_Folder { CreatedBy = Username, CreatedDate = DateTime.Now, IDLinhVuc = dbitem.ID, }; db.tbl_CUS_DOC_Folder.Add(folder); } folder.IDPartner = 1; folder.Name = item.Name; folder.Sort = item.Sort; folder.ModifiedBy = Username; folder.ModifiedDate = DateTime.Now; if (item.ParentID > 0) { var folderParent = db.tbl_CUS_DOC_Folder.FirstOrDefault(c => c.IDLinhVuc == item.ParentID); if (folderParent != null) { folder.IDParent = folderParent.ID; } } BS_CUS_Version.update_CUS_Version(db, null, "DTO_CAT_LinhVuc", DateTime.Now, Username); db.SaveChanges(); item.ID = dbitem.ID; item.CreatedBy = dbitem.CreatedBy; item.CreatedDate = dbitem.CreatedDate; item.ModifiedBy = dbitem.ModifiedBy; item.ModifiedDate = dbitem.ModifiedDate; } catch (DbEntityValidationException e) { errorLog.logMessage("post_CAT_LinhVuc", e); item = null; } } return(item); }
public static bool put_CAT_LinhVucCustom(AppEntities db, int ID, DTO_CAT_LinhVuc item, string Username) { bool result = false; var dbitem = db.tbl_CAT_LinhVuc.Find(ID); if (dbitem != null) { bool isChangeParent = dbitem.ParentID != item.ParentID; dbitem.ParentID = item.ParentID; dbitem.Name = item.Name; dbitem.Note = item.Note; dbitem.Sort = item.Sort; dbitem.IsDisabled = item.IsDisabled; dbitem.IsDeleted = item.IsDeleted; dbitem.ModifiedBy = Username; dbitem.ModifiedDate = DateTime.Now; try { db.SaveChanges(); var folder = db.tbl_CUS_DOC_Folder.FirstOrDefault(c => c.IDLinhVuc == ID); if (folder == null) { folder = new tbl_CUS_DOC_Folder { CreatedBy = Username, CreatedDate = DateTime.Now, IDLinhVuc = ID, }; db.tbl_CUS_DOC_Folder.Add(folder); } folder.IDPartner = 1; folder.Name = item.Name; folder.Sort = item.Sort; folder.ModifiedBy = Username; folder.ModifiedDate = DateTime.Now; if (item.ParentID == null) { folder.IDParent = null; } if (isChangeParent && item.ParentID > 0) { var folderParent = db.tbl_CUS_DOC_Folder.FirstOrDefault(c => c.IDLinhVuc == item.ParentID); if (folderParent != null) { folder.IDParent = folderParent.ID; } } db.SaveChanges(); BS_CUS_Version.update_CUS_Version(db, null, "DTO_CAT_LinhVuc", DateTime.Now, Username); result = true; } catch (DbEntityValidationException e) { errorLog.logMessage("put_CAT_LinhVuc", e); result = false; } } return(result); }