示例#1
0
        public FileResult GetFile(int id)
        {
            ImageBoxModDTO imgBoxModDto = imageBoxModService.GetImg(id);

            Mapper.Initialize(cfg => cfg.CreateMap <ImageBoxModDTO, ImageBoxModViewModel>());
            var img = Mapper.Map <ImageBoxModDTO, ImageBoxModViewModel>(imgBoxModDto);

            return(File(img.Data, img.MimeType));
        }
示例#2
0
        public void Add(ImageBoxModDTO imageBoxModDto)
        {
            BoxMod boxMod = Database.BoxMods.Get(imageBoxModDto.BoxModId);

            // валидация
            if (boxMod == null)
            {
                throw new ValidationException("FullVape не найден", "");
            }
            ImageBoxMod imageBoxMod = new ImageBoxMod
            {
                Data     = imageBoxModDto.Data,
                MimeType = imageBoxModDto.MimeType,
                BoxModId = boxMod.Id,
            };

            Database.ImageBoxMods.Create(imageBoxMod);
            Database.Save();
        }
示例#3
0
        public ActionResult Upload(HttpPostedFileBase uploadImage, int id)
        {
            BoxModDTO boxModDto = imageBoxModService.GetBoxMod(id);

            if (ModelState.IsValid && boxModDto != null)
            {
                ImageBoxModDTO image = new ImageBoxModDTO
                {
                    BoxModId = id,
                    MimeType = uploadImage.ContentType,
                };
                image.Data = new byte[uploadImage.ContentLength];
                uploadImage.InputStream.Read(image.Data, 0, uploadImage.ContentLength);
                imageBoxModService.Add(image);

                return(View("View"));
            }
            else
            {
                return(View("View1"));
            }
        }