public ActionResult Create([Bind(Include = "ID, Title, Photo, Contents, DateOfPublication")] ReviewModels review, int BoardGame_Id) { System.Diagnostics.Debug.WriteLine("CREATE REVIEW"); var query = db.User.Where(i => i.Email == User.Identity.Name); UserModels user = query.Single(); review.Author = user; review.DateOfPublication = DateTime.Now; var query2 = db.BoardGame.Where(i => i.ID == BoardGame_Id); BoardGameModels game = query2.Single(); review.BoardGame = game; System.Diagnostics.Debug.WriteLine(BoardGame_Id); if (ModelState.IsValid) { db.Review.Add(review); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BoardGame_Id = new SelectList(db.BoardGame, "Id", "Title", review.BoardGame.ID); ViewBag.Author_Id = new SelectList(db.User, "Id", "FullName", review.Author.ID); return(View(review)); }
public ActionResult Delete(int?id) { if (id == null) { return(RedirectToAction("Index")); } BoardGameModels game = db.BoardGame.Find(id); if (game == null) { return(HttpNotFound()); } return(View(game)); }
public ActionResult Edit(BoardGameModels game) { try { if (ModelState.IsValid) { db.Entry(game).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(game)); } catch { return(View()); } }
public ActionResult Create(BoardGameModels game) { try { if (ModelState.IsValid) { db.BoardGame.Add(game); db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id) { BoardGameModels game = db.BoardGame.Find(id); try { db.BoardGame.Remove(game); db.SaveChanges(); return(RedirectToAction("Index")); } catch { ViewBag.Message = String.Format("This element is coneted with other DB you cant remove it!"); return(View(game)); // return RedirectToAction("Index"); } }
public ActionResult Create(AdvertisementModels advertisement, int BoardGame_Id) { try { var query2 = db.BoardGame.Where(i => i.ID == BoardGame_Id); BoardGameModels game = query2.Single(); var query = db.User.Where(i => i.Email == User.Identity.Name); UserModels user = query.Single(); advertisement.Author = user; advertisement.BoardGame = game; advertisement.IsActive = true; if (ModelState.IsValid) { db.Advertisement.Add(advertisement); db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); } catch { return(View()); } }