public ExhibitViewModel(DataContext db, Exhibit item, Article article) : this(db, item) { Article = article; }
public ActionResult EditArticlePost(int exhibitId, int? id, HttpPostedFileBase Photo) { Article item = null; Exhibit exhibit = null; try { exhibit = db.Exhibits.Find(exhibitId); if (exhibit == null) throw new ArgumentException("Экспонат не найден."); if (id.HasValue) { item = db.Articles.SingleOrDefault(i => i.Id == id); if (item == null) throw new ArgumentException("Материал не найден."); } else { item = new Article() { Exhibit = exhibit }; } TryUpdateModel(item, "Article", new[] { "Title", "Text" }); 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.Articles.Add(item); else db.Entry<Article>(item).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Articles", new { id = exhibit.Id }); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return View(new ExhibitViewModel(db, exhibit, item)); }
public ExhibitViewModel(Exhibit item, Article article) : this(item) { Item = item; Article = article; }
// // GET: /Admin/Exhibit/EditArticle public ActionResult EditArticle(int exhibitId, int? id) { Article item = null; Exhibit exhibit = null; try { exhibit = db.Exhibits.Find(exhibitId); if (exhibit == null) throw new ArgumentException("Экспонат не найден."); if (id.HasValue) { item = db.Articles.SingleOrDefault(i => i.Id == id); if (item == null) throw new ArgumentException("Материал не найден."); } else { item = new Article() { Exhibit = exhibit }; } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return View(new ExhibitViewModel(db, exhibit, item)); }