Esempio n. 1
0
        public void CanInvalidateFileSize()
        {
            HttpPostedFileBase file = new TestPostedFileBase(7168001);

            bool actual = FileUploadUtility.InvalidFileSize(file);

            Assert.IsTrue(actual);
        }
Esempio n. 2
0
        public void CanInvalidateDocFile()
        {
            HttpPostedFileBase file = new TestPostedFileBase("test.doc");

            bool actual = FileUploadUtility.InvalidFileExtension(file);

            Assert.IsTrue(actual);
        }
Esempio n. 3
0
        public void CanValidateJPGFile()
        {
            HttpPostedFileBase file = new TestPostedFileBase("test.jpg");

            bool actual = FileUploadUtility.InvalidFileExtension(file);

            Assert.IsFalse(actual);
        }
Esempio n. 4
0
        public void CanGetFilenameWithTimestamp()
        {
            HttpPostedFileBase file   = new TestPostedFileBase("test.jpg");
            string             actual = FileUploadUtility.GetFilenameWithTimestamp(file.FileName);
            DateTime           now    = DateTime.Now;

            string expected = "test_" + FileUploadUtility.GetTimestamp(now) + ".jpg";

            Assert.AreEqual(expected, actual);
        }
Esempio n. 5
0
        public JsonResult UploadHandle(string saveDirectory)
        {
            var fileBase     = System.Web.HttpContext.Current.Request.Files[0];
            var SavePath     = saveDirectory;// "/UserFiles/Test/";
            var TargetPath   = System.Web.HttpContext.Current.Server.MapPath(SavePath) + fileBase.FileName;
            var ContentRange = Request.Headers["Content-Range"];

            TempPath = TargetPath;
            FileUploadUtility.UploadBigFile(fileBase, TargetPath, ContentRange);
            var result = new { name = "提示:上传成功!", filePath = saveDirectory + fileBase.FileName };

            return(Json(result));
        }
Esempio n. 6
0
        /// <summary>
        /// Add/Update User
        /// </summary>
        /// <returns></returns>
        public static bool AddUpdateUser(User entity)
        {
            var sqlUser = new SqlUser();
            var action = Enums.LoyaltyGatorAction.AddUser;
            if (entity.Id > 0)
            {
                action = Enums.LoyaltyGatorAction.UpdateUser;
            }
            if (entity.SchoolName == null)
            {
                entity.SchoolName = string.Empty;
            }
            if (!string.IsNullOrWhiteSpace(entity.ProfileImage))
            {
                var profileData = entity.ProfileImage.Split(',');
                switch (profileData.Length)
                {
                    case 3:
                        entity.ProfileImageByte = Convert.FromBase64String(profileData[2]);
                        entity.ProfileImage = profileData[0];
                        break;
                }
                if (entity.ProfileImageByte != null && entity.ProfileImageByte.Length > 0)
                {
                    entity.ProfileImage = FileUploadUtility.GetFileName(Path.GetFileNameWithoutExtension(entity.ProfileImage)) + Path.GetExtension(entity.ProfileImage);
                    entity.ProfileImage = FileUploadUtility.ConvertByteToImage(entity.ProfileImageByte, entity.ProfileImage, WebConstant.ConfigKey.UserProfilePhysicalFilePath) ? entity.ProfileImage : "";
                    if (!string.IsNullOrWhiteSpace(entity.ProfileImage))
                    {
                        string profileImageIcon = Utilities.ResizeImage(entity.ProfileImage, 100, 100, WebConstant.ConfigKey.UserProfilePhysicalFilePath);
                        entity.ProfileImage = !string.IsNullOrWhiteSpace(profileImageIcon) ? profileImageIcon : entity.ProfileImage;
                    }
                }
            }
            if (!string.IsNullOrWhiteSpace(entity.TaxExemptFile))
            {
                var taxExemptData = entity.TaxExemptFile.Split(',');
                byte[] taxExemptDataByte = { };
                switch (taxExemptData.Length)
                {
                    case 3:
                        taxExemptDataByte = Convert.FromBase64String(taxExemptData[2]);
                        entity.ProfileImage = taxExemptData[0];
                        break;
                }
                if (taxExemptDataByte.Length > 0)
                {
                    var fileExtension = Path.GetExtension(entity.TaxExemptFile);
                    var fileType = fileExtension.FileType();
                    entity.TaxExemptFile = FileUploadUtility.GetFileName(Path.GetFileNameWithoutExtension(entity.TaxExemptFile)) + fileExtension;
                    switch (fileType)
                    {
                        case "IMAGE":
                            entity.TaxExemptFile = FileUploadUtility.ConvertByteToImage(taxExemptDataByte, entity.TaxExemptFile, WebConstant.ConfigKey.OrdersFilePath) ? entity.TaxExemptFile : "";
                            break;
                        case "PDF":
                        case "DOC":
                            entity.TaxExemptFile = FileUploadUtility.ConvertByteToDoc(taxExemptDataByte, entity.TaxExemptFile, WebConstant.ConfigKey.OrdersFilePath) ? entity.TaxExemptFile : "";
                            break;
                    }
                }
            }

            bool isAddUpdated = sqlUser.AddUpdateUser(entity);
            if (isAddUpdated)
            {
                if (Utilities.EnableLoyaltyGator)
                {
                    LoyaltyGatorRepository.AddUpdateLoyaltyGatorUser(entity, action);
                }
            }
            return isAddUpdated;
        }