Ejemplo n.º 1
0
        public PersonDto FillImagesInfo(HttpPostedFileBase image, PoliticianImageTypeEnum imageType, PersonDto personDto)
        {
            if (image != null)
            {
                var imagePath = ImagesHelper.SaveImageForPolitician(image, personDto, imageType);
            }

            return(personDto);
        }
Ejemplo n.º 2
0
        public static string SaveImageForPolitician(HttpPostedFileBase image, PersonDto personDto, PoliticianImageTypeEnum imageType)
        {
            var fileName = Path.Combine(ConfigHelper.ContentPath, ConfigHelper.POLITICIANS_FOLDER, personDto.GenericName,
                                        $"{personDto.GenericName}{imageType.ToString()}{Path.GetExtension(image.FileName)}");

            var rescueFileName = Path.Combine(ConfigHelper.ContentPath, ConfigHelper.POLITICIANS_FOLDER, personDto.GenericName,
                                              $"{personDto.GenericName}{imageType.ToString()}Rescue{Path.GetExtension(image.FileName)}");

            if (!Directory.Exists(Path.GetDirectoryName(fileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(fileName));
            }

            try
            {
                image.SaveAs(fileName);
            }
            catch
            {
                fileName = rescueFileName;
                image.SaveAs(fileName);
            }

            var relativeFilePath = fileName.Replace(ConfigHelper.ContentPath, "");
            var pathPlusContent  = "\\content" + relativeFilePath;

            var imageInfo = new ImageInfoDto
            {
                ImagePath = pathPlusContent,
                Md5Hash   = FileHelper.CalcMD5(fileName)
            };

            switch (imageType)
            {
            case PoliticianImageTypeEnum.MainPic:
                personDto.MainPicPath = imageInfo;
                break;

            case PoliticianImageTypeEnum.ListButtonPic:
                personDto.ListButtonPicPath = imageInfo;
                break;

            case PoliticianImageTypeEnum.SmallButtonPic:
                personDto.SmallButtonPicPath = imageInfo;
                break;
            }

            return(pathPlusContent);
        }