예제 #1
0
        // cập nhat phan quyen xem tài liệu khi các moduel khác chỉnh sửa phân quyền
        #region UpdateStaff
        public static void UpdateStaff(string Staff, int?CategoryId, string Category)
        {
            DocumentFieldRepository DocumentFieldRepository = new DocumentFieldRepository(new Domain.Staff.ErpStaffDbContext());
            var document = DocumentFieldRepository.GetDocumentFieldByCategory(Category, CategoryId);

            if (document != null)
            {
                document.IsSearch = Staff;
                DocumentFieldRepository.UpdateDocumentField(document);
            }
        }
예제 #2
0
        public static void SaveUpload(string NameField, string IsSearch, int CategoryId, string Category, string FailedMessageKey = null, string fileName = null)
        {
            //insert và upload documentField, documentAttribute.
            List <HttpPostedFileBase> listFile = new List <HttpPostedFileBase>();

            if (System.Web.HttpContext.Current.Session["file"] != null)
            {
                listFile = (List <HttpPostedFileBase>)System.Web.HttpContext.Current.Session["file"];
            }

            DocumentFieldRepository DocumentFieldRepository = new DocumentFieldRepository(new Domain.Staff.ErpStaffDbContext());

            DocumentAttributeRepository DocumentAttributeRepository = new DocumentAttributeRepository(new Domain.Staff.ErpStaffDbContext());

            if (listFile.Count > 0)
            {
                var DocumentField = new DocumentField();

                DocumentField.IsDeleted      = false;
                DocumentField.CreatedUserId  = WebSecurity.CurrentUserId;
                DocumentField.ModifiedUserId = WebSecurity.CurrentUserId;
                DocumentField.AssignedUserId = WebSecurity.CurrentUserId;
                DocumentField.CreatedDate    = DateTime.Now;
                DocumentField.ModifiedDate   = DateTime.Now;
                DocumentField.Name           = NameField;
                //  DocumentField.DocumentTypeId = DocumentTypeId;
                DocumentField.IsSearch   = IsSearch;
                DocumentField.Category   = Category;
                DocumentField.CategoryId = CategoryId;
                DocumentFieldRepository.InsertDocumentField(DocumentField);
                var prefix = Erp.BackOffice.Helpers.Common.GetSetting("prefixOrderNo_DocumentField");
                DocumentField.Code = Erp.BackOffice.Helpers.Common.GetCode(prefix, DocumentField.Id);
                DocumentFieldRepository.UpdateDocumentField(DocumentField);
                int dem = 0;
                foreach (var item in listFile)
                {
                    dem = dem + 1;
                    var type              = item.FileName.Split('.').Last();
                    var FileName          = DocumentField.Name.Replace(" ", "_");
                    var name              = Erp.BackOffice.Helpers.Common.ChuyenThanhKhongDau(FileName).ToLower();
                    var DocumentAttribute = new DocumentAttribute();
                    DocumentAttribute.IsDeleted      = false;
                    DocumentAttribute.CreatedUserId  = WebSecurity.CurrentUserId;
                    DocumentAttribute.ModifiedUserId = WebSecurity.CurrentUserId;
                    DocumentAttribute.AssignedUserId = WebSecurity.CurrentUserId;
                    DocumentAttribute.CreatedDate    = DateTime.Now;
                    DocumentAttribute.ModifiedDate   = DateTime.Now;
                    DocumentAttribute.OrderNo        = dem;
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        DocumentAttribute.File = fileName + "(" + DocumentField.Id + "_" + DocumentAttribute.OrderNo + ")" + "." + type;
                    }
                    else
                    {
                        DocumentAttribute.File = name + "(" + DocumentField.Id + "_" + DocumentAttribute.OrderNo + ")" + "." + type;
                    }
                    DocumentAttribute.Size            = item.ContentLength.ToString();
                    DocumentAttribute.TypeFile        = type;
                    DocumentAttribute.DocumentFieldId = DocumentField.Id;
                    DocumentAttributeRepository.InsertDocumentAttribute(DocumentAttribute);
                    var  path     = System.Web.HttpContext.Current.Server.MapPath("~" + Helpers.Common.GetSetting(Category));
                    bool isExists = System.IO.Directory.Exists(path);
                    if (!isExists)
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }
                    item.SaveAs(path + DocumentAttribute.File);
                }
            }
            else
            {
                FailedMessageKey = "Vui lòng chụp ảnh!";
            }
        }