public ActionResult EditPost(int? id, HttpPostedFileBase Photo) { Exhibit item = null; try { if (id.HasValue) { item = db.Exhibits.SingleOrDefault(i => i.Id == id); if (item == null) throw new ArgumentException("Экспонат не найден."); } else { item = new Exhibit(); } TryUpdateModel(item, "Item", new[] { "Name", "Description", "Location", "Code" }); if (ModelState.IsValid) { if (Photo != null && Photo.IsImage()) { item.ApplicationType = Photo.ContentType; item.ApplicationData = new WebImage(Photo.InputStream).Resize(300, 300).GetBytes(item.ApplicationType); Photo.InputStream.Read(item.ApplicationData, 0, Photo.ContentLength); } if (id == null) db.Exhibits.Add(item); else db.Entry<Exhibit>(item).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return View(new ExhibitViewModel(db, item)); }
// // GET: /Admin/Exhibit/Edit public ActionResult Edit(int? id) { Exhibit item = null; try { if (id.HasValue) { item = db.Exhibits.SingleOrDefault(i => i.Id == id); if (item == null) throw new ArgumentException("Экспонат не найден."); } else { item = new Exhibit(); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return View(new ExhibitViewModel(db, item)); }
public ExhibitViewModel(DataContext db, Exhibit item, Article article) : this(db, item) { Article = article; }
public ExhibitViewModel(DataContext db, Exhibit item) : this(db) { Item = item; }
public ExhibitViewModel(Exhibit item, Article article) : this(item) { Item = item; Article = article; }
public ExhibitViewModel(Exhibit item) { Item = item; }