Ejemplo n.º 1
0
        public FileResult GetFile(int id)
        {
            ImageDripDTO imgDripDto = imageDripService.GetImg(id);

            Mapper.Initialize(cfg => cfg.CreateMap <ImageDripDTO, ImageDripViewModel>());
            var img = Mapper.Map <ImageDripDTO, ImageDripViewModel>(imgDripDto);

            return(File(img.Data, img.MimeType));
        }
Ejemplo n.º 2
0
        public void Add(ImageDripDTO imageDripDto)
        {
            Drip drip = Database.Drips.Get(imageDripDto.DripId);

            // валидация
            if (drip == null)
            {
                throw new ValidationException("Drip не найден", "");
            }
            ImageDrip imageDrip = new ImageDrip
            {
                Data     = imageDripDto.Data,
                MimeType = imageDripDto.MimeType,
                DripID   = drip.Id,
            };

            Database.ImageDrips.Create(imageDrip);
            Database.Save();
        }
Ejemplo n.º 3
0
        public ActionResult Upload(HttpPostedFileBase uploadImage, int id)
        {
            DripDTO dripDto = imageDripService.GetDrip(id);

            if (ModelState.IsValid && dripDto != null)
            {
                ImageDripDTO image = new ImageDripDTO
                {
                    DripId   = id,
                    MimeType = uploadImage.ContentType,
                };
                image.Data = new byte[uploadImage.ContentLength];
                uploadImage.InputStream.Read(image.Data, 0, uploadImage.ContentLength);
                imageDripService.Add(image);

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