Esempio n. 1
0
        public FileResult GetFile(int id)
        {
            ImageTankDTO imgTankDto = imageTankService.GetImg(id);

            Mapper.Initialize(cfg => cfg.CreateMap <ImageTankDTO, ImageTankViewModel>());
            var img = Mapper.Map <ImageTankDTO, ImageTankViewModel>(imgTankDto);

            return(File(img.Data, img.MimeType));
        }
Esempio n. 2
0
        public void Add(ImageTankDTO imageTankDto)
        {
            Tank tank = Database.Tanks.Get(imageTankDto.TankId);

            // валидация
            if (tank == null)
            {
                throw new ValidationException("Tank не найден", "");
            }
            ImageTank imageTank = new ImageTank
            {
                Data     = imageTankDto.Data,
                MimeType = imageTankDto.MimeType,
                TankID   = tank.Id,
            };

            Database.ImageTanks.Create(imageTank);
            Database.Save();
        }
Esempio n. 3
0
        public ActionResult Upload(HttpPostedFileBase uploadImage, int id)
        {
            TankDTO tankDto = imageTankService.GetTank(id);

            if (ModelState.IsValid && tankDto != null)
            {
                ImageTankDTO image = new ImageTankDTO
                {
                    TankId   = id,
                    MimeType = uploadImage.ContentType,
                };
                image.Data = new byte[uploadImage.ContentLength];
                uploadImage.InputStream.Read(image.Data, 0, uploadImage.ContentLength);
                imageTankService.Add(image);

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