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)); }
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(); }
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")); } }