public void AddAircraftImage(AircraftImage image) { _repository.Add<AircraftImage>(image); _repository.UnitOfWork.SaveChanges(); }
public ActionResult AddImage(HttpPostedFileBase file, AircraftImageViewModel viewModel) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["AircraftImages"]), fileName);//Path.Combine(Server.MapPath("~/Content/AircraftImages"), fileName); file.SaveAs(path); // create small, medium and large versions List<string> validationErrors = ImageHelper.CreateImageSet(path); if (validationErrors.Count > 0) { foreach (var error in validationErrors) { ModelState.AddModelError("", error); } return View(ViewNames.AddAircraftImage, viewModel); } AircraftImage image = new AircraftImage() { AircraftId = viewModel.AircraftId, Descritpion = viewModel.Description, Title = viewModel.Title, Type = viewModel.Type, FileName = fileName, FileName_Large = Path.GetFileNameWithoutExtension(fileName) + ".lrg" + Path.GetExtension(fileName), FileName_Medium = Path.GetFileNameWithoutExtension(fileName) + ".med" + Path.GetExtension(fileName), FileName_Small = Path.GetFileNameWithoutExtension(fileName) + ".small" + Path.GetExtension(fileName), }; _dataService.AddAircraftImage(image); } return RedirectToAction("Edit", new { id = viewModel.AircraftId }); }