public static DTO_CUS_DOC_File_Actitity toDTO(tbl_CUS_DOC_File_Actitity dbResult)
 {
     if (dbResult != null)
     {
         return(new DTO_CUS_DOC_File_Actitity()
         {
             IDPartner = dbResult.IDPartner,
             IDFile = dbResult.IDFile,
             ID = dbResult.ID,
             Code = dbResult.Code,
             Name = dbResult.Name,
             Remark = dbResult.Remark,
             Sort = dbResult.Sort,
             IsDisabled = dbResult.IsDisabled,
             IsDeleted = dbResult.IsDeleted,
             CreatedBy = dbResult.CreatedBy,
             ModifiedBy = dbResult.ModifiedBy,
             CreatedDate = dbResult.CreatedDate,
             ModifiedDate = dbResult.ModifiedDate,
         });
     }
     else
     {
         return(null);
     }
 }
        public static DTO_CUS_DOC_File_Actitity post_CUS_DOC_File_Actitity(AppEntities db, int PartnerID, DTO_CUS_DOC_File_Actitity item, string Username)
        {
            tbl_CUS_DOC_File_Actitity dbitem = new tbl_CUS_DOC_File_Actitity();

            if (item != null)
            {
                dbitem.IDFile     = item.IDFile;
                dbitem.Code       = item.Code;
                dbitem.Name       = item.Name;
                dbitem.Remark     = item.Remark;
                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;

                dbitem.IDPartner = PartnerID;


                try
                {
                    db.tbl_CUS_DOC_File_Actitity.Add(dbitem);
                    db.SaveChanges();

                    BS_CUS_Version.update_CUS_Version(db, dbitem.IDPartner, "DTO_CUS_DOC_File_Actitity", dbitem.ModifiedDate, Username);



                    item.ID = dbitem.ID;

                    item.CreatedBy   = dbitem.CreatedBy;
                    item.CreatedDate = dbitem.CreatedDate;

                    item.ModifiedBy   = dbitem.ModifiedBy;
                    item.ModifiedDate = dbitem.ModifiedDate;

                    item.IDPartner = dbitem.IDPartner;
                }
                catch (DbEntityValidationException e)
                {
                    errorLog.logMessage("post_CUS_DOC_File_Actitity", e);
                    item = null;
                }
            }
            return(item);
        }
예제 #3
0
        public static bool put_CUS_DOC_File(AppEntities db, int PartnerID, int ID, DTO_CUS_DOC_File item, string Username, bool custom)
        {
            bool   result  = false;
            var    dbitem  = db.tbl_CUS_DOC_File.Find(ID);
            string changes = "";
            string oldName = "";

            if (dbitem != null)
            {
                string format = "\"{0}\": {{\"old\":\"{1}\", \"new\":\"{2}\"}},";
                if (dbitem.Code != item.Code)
                {
                    changes += string.Format(format, "Code", dbitem.Code, item.Code);
                }
                dbitem.Code = item.Code;

                if (dbitem.Name != item.Name)
                {
                    changes += string.Format(format, "Name", dbitem.Name, item.Name);
                }

                oldName     = dbitem.Name;
                dbitem.Name = item.Name;

                if (dbitem.Remark != item.Remark)
                {
                    changes += string.Format(format, "Remark", dbitem.Remark, item.Remark);
                }
                dbitem.Remark = item.Remark;

                if (dbitem.FileVersion != item.FileVersion)
                {
                    changes += string.Format(format, "FileVersion", dbitem.FileVersion, item.FileVersion);
                }
                dbitem.FileVersion = item.FileVersion;

                dbitem.Sort         = item.Sort;
                dbitem.IsDisabled   = item.IsDisabled;
                dbitem.IsDeleted    = item.IsDeleted;
                dbitem.ModifiedBy   = item.ModifiedBy;
                dbitem.ModifiedDate = item.ModifiedDate;

                if (dbitem.Path != item.Path)
                {
                    changes += string.Format(format, "Path", dbitem.Path, item.Path);
                }
                dbitem.Path = item.Path;

                if (dbitem.Extension != item.Extension)
                {
                    changes += string.Format(format, "Extension", dbitem.Extension, item.Extension);
                }
                dbitem.Extension = item.Extension;

                if (dbitem.FileSize != item.FileSize)
                {
                    changes += string.Format(format, "FileSize", dbitem.FileSize, item.FileSize);
                }
                dbitem.FileSize = item.FileSize;

                if (dbitem.IsApproved != item.IsApproved)
                {
                    changes += string.Format(format, "IsApproved", dbitem.IsApproved, item.IsApproved);
                }
                dbitem.IsApproved = item.IsApproved;

                if (dbitem.ApprovedBy != item.ApprovedBy)
                {
                    changes += string.Format(format, "ApprovedBy", dbitem.ApprovedBy, item.ApprovedBy);
                }
                dbitem.ApprovedBy = item.ApprovedBy;

                dbitem.ApprovedDate = item.ApprovedDate;



                try
                {
                    var folder = dbitem.tbl_CUS_DOC_FileInFolder.FirstOrDefault();

                    if (folder == null && item.IDFolder != null)
                    {
                        dbitem.tbl_CUS_DOC_FileInFolder.Add(new tbl_CUS_DOC_FileInFolder()
                        {
                            IDFolder = item.IDFolder, IDPartner = item.IDPartner, CreatedBy = dbitem.CreatedBy, CreatedDate = dbitem.CreatedDate, ModifiedBy = dbitem.ModifiedBy, ModifiedDate = dbitem.ModifiedDate
                        });
                    }
                    else if (folder != null && folder.IDFolder != item.IDFolder && item.IDFolder != null)
                    {
                        folder.IDFolder = item.IDFolder;
                    }
                    else if (folder != null && item.IDFolder == null)
                    {
                        db.tbl_CUS_DOC_FileInFolder.Remove(folder);
                    }

                    //check change to save activities

                    tbl_CUS_DOC_File_Actitity activity = new tbl_CUS_DOC_File_Actitity();
                    if (!db.tbl_CUS_DOC_File_Actitity.Any(d => d.IDPartner == PartnerID && d.IDFile == dbitem.ID))
                    {
                        activity.Code = "Add";
                        activity.Name = dbitem.Name;
                        changes       = string.Format(format, "Name", "", "Thêm tài liệu mới");
                    }
                    else if (changes != "")
                    {
                        activity.Code = "Update";
                        activity.Name = oldName;
                    }
                    if (!string.IsNullOrEmpty(changes))
                    {
                        activity.Remark = "{" + changes.Substring(0, changes.Length - 1) + "}";
                    }

                    activity.IDFile       = dbitem.ID;
                    activity.IDPartner    = dbitem.IDPartner;
                    activity.CreatedBy    = Username;
                    activity.CreatedDate  = DateTime.Now;
                    activity.ModifiedBy   = dbitem.ModifiedBy;
                    activity.ModifiedDate = dbitem.ModifiedDate;

                    if (!string.IsNullOrEmpty(activity.Code))
                    {
                        db.tbl_CUS_DOC_File_Actitity.Add(activity);
                    }


                    db.SaveChanges();

                    BS_CUS_Version.update_CUS_Version(db, dbitem.IDPartner, "DTO_CUS_DOC_File", dbitem.ModifiedDate, Username);



                    result = true;
                }
                catch (DbEntityValidationException e)
                {
                    errorLog.logMessage("put_CUS_DOC_File", e);
                    result = false;
                }
            }
            return(result);
        }