public ActionResult AddEventImageLocal(int?id, EventImageBindingModel bind) { if (this.ModelState.IsValid) { var @event = this.db.Events.Find(id); if (@event == null) { return(this.HttpNotFound()); } var photo = Request.Files["Url"]; if (photo == null) { return(this.View()); } var directory = $"{Server.MapPath("~")}{Constants.EventImagesMapPath}"; photo.SaveAs(Path.Combine(directory, photo.FileName)); bind.Url = Constants.EventImagesFolderPath + photo.FileName; if (@event.EventImages.All(ei => ei.Url != bind.Url)) { var image = Mapper.Map <EventImageBindingModel, EventImage>(bind); @event.EventImages.Add(image); this.db.SaveChanges(); } ViewBag.EventName = @event.Name; return(this.RedirectToAction("AddEventImageLocal")); } return(this.View()); }
public ActionResult AddEventImage(int?id, EventImageBindingModel bind) { if (this.ModelState.IsValid) { var @event = this.db.Events.Find(id); bind.Url = Constants.EventImagesFolderPath + bind.Url; if ([email protected](ei => ei.Url == bind.Url)) { var image = Mapper.Map <EventImageBindingModel, EventImage>(bind); @event.EventImages.Add(image); this.db.SaveChanges(); } return(this.RedirectToAction("AddEventImage")); } return(this.View(bind)); }