예제 #1
0
        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);
        }
예제 #2
0
 public static DTO_CAT_LinhVuc toDTO(tbl_CAT_LinhVuc dbResult)
 {
     if (dbResult != null)
     {
         return(new DTO_CAT_LinhVuc()
         {
             ID = dbResult.ID,
             ParentID = dbResult.ParentID,
             Name = dbResult.Name,
             Note = dbResult.Note,
             Sort = dbResult.Sort,
             IsDisabled = dbResult.IsDisabled,
             IsDeleted = dbResult.IsDeleted,
             CreatedDate = dbResult.CreatedDate,
             CreatedBy = dbResult.CreatedBy,
             ModifiedDate = dbResult.ModifiedDate,
             ModifiedBy = dbResult.ModifiedBy,
         });
     }
     else
     {
         return(null);
     }
 }
예제 #3
0
        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);
        }