Exemple #1
0
 public string GetProfileBoxName(string profileType, string warehouseId, int boxCount, short year)
 {
     return(string.Format("{0}{1}{2}-{3:0000}",
                          year % 100,                                                           // year - e.g. 15
                          UnicodeCharacterReplacer.ReplaceString(profileType).Replace(" ", ""), // profile type - e.g. SA88
                          warehouseId,                                                          // warehouse - e.g. 01
                          boxCount));                                                           // box count - e.g. 0012
 }
Exemple #2
0
        public byte[] ExportProfilesForDistributor(Distributor dist, IList <Profile> profiles)
        {
            var exportData = new byte[] { };

            var tempProfileFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            Directory.CreateDirectory(tempProfileFolder);
            //var tempProfileFolder = Path.Combine(tempFolder, dist.DistNumber.ToString());
            //Directory.CreateDirectory(tempProfileFolder);

            // Copy files
            foreach (var profile in profiles)
            {
                var profileFilePath = Path.Combine(_appSettings.ProfileBoxFolder, profile.ProfileBox.Name + "\\" + profile.FileName);
                var newFilePath     = Path.Combine(tempProfileFolder,
                                                   string.Format("{0}_{1}{2}",
                                                                 profile.CreatedDate.ToString(_appSettings.ProfileExportDateFormat),
                                                                 profile.ProfileType.Name.Replace(' ', '_'),
                                                                 Path.GetExtension(profileFilePath)));

                File.Copy(profileFilePath, UnicodeCharacterReplacer.ReplaceString(newFilePath), true);
            }

            var zippedFiles = profiles.Select(x => Path.Combine(_appSettings.ProfileBoxFolder, x.ProfileBox.Name + "\\" + x.FileName));

            // Zip files
            using (var zipFile = new ZipFile(Encoding.UTF8))
            {
                using (var memoryStream = new MemoryStream())
                {
                    zipFile.AddDirectory(tempProfileFolder, string.Empty);
                    //zipFile.AddFiles(zippedFiles, string.Empty);
                    zipFile.Save(memoryStream);
                    exportData = memoryStream.ToArray();
                }
            }

            // Delete temp folder
            try
            {
                Directory.Delete(tempProfileFolder, true);
            }
            catch { }

            return(exportData);
        }
Exemple #3
0
        public ActionResult DownloadProfileFile(int downloadProfileId)
        {
            var profile = _profileService.GetProfileById(downloadProfileId, includeProfileBox: true, includeProfileType: true);

            if (profile == null)
            {
                return(PageNotFound());
            }

            var profileFilePath = Path.Combine(_appSettings.ProfileBoxFolder, profile.ProfileBox.Name + "\\" + profile.FileName);

            if (!System.IO.File.Exists(profileFilePath))
            {
                return(PageNotFound(_resourceManager.GetString("Profile.DownloadedFileNotFound")));
            }

            var fileName = string.Format("{0}_{1}{2}",
                                         Path.GetFileNameWithoutExtension(profile.FileName),
                                         UnicodeCharacterReplacer.ReplaceString(profile.ProfileType.Name),
                                         Path.GetExtension(profile.FileName));

            return(File(profileFilePath, FileContentType.PDF, fileName));
        }