public ActionResult Create(AdvertisementModels model) { var userId = User.Identity.GetUserId(); using (var context = ApplicationDbContext.Create()) { var ad = new Advertisement { Adress = model.Adress, Header = model.Header, Content = model.Content, Price = Convert.ToInt32(model.Price), Size = Convert.ToInt32(model.Size), OwnerId = userId, RenterId = null, Date = DateTime.Now }; context.Advertisements.Add(ad); context.SaveChanges(); return(View("SuccessfulCreated")); } return(View()); }
public ActionResult DeleteConfirmed(int id) { AdvertisementModels advertisementModels = db.Advertisements.Find(id); db.Advertisements.Remove(advertisementModels); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "ID,CarID,Active,OfferAmount")] AdvertisementModels advertisementModels) { //if (ModelState.IsValid) //{ db.Advertisements.Add(advertisementModels); db.SaveChanges(); return(RedirectToAction("Index")); //} //return View(advertisementModels); }
public ActionResult CreateUser([Bind(Include = "ID,CarID,Active,OfferAmount")] AdvertisementModels advertisementModels) { advertisementModels.Active = false; if (ModelState.IsValid) { db.Advertisements.Add(advertisementModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(advertisementModels)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AdvertisementModels advertisementModels = db.Advertisements.Find(id); if (advertisementModels == null) { return(HttpNotFound()); } return(View(advertisementModels)); }
public ActionResult Delete(int?id) { if (id == null) { return(RedirectToAction("Index")); } AdvertisementModels advertisement = db.Advertisement.Find(id); if (advertisement == null) { return(HttpNotFound()); } return(View(advertisement)); }
public ActionResult Edit([Bind(Include = "ID,CarID,Active,OfferAmount")] AdvertisementModels advertisementModels) { if (User.IsInRole("user")) { advertisementModels.Active = false; } if (ModelState.IsValid) { db.Entry(advertisementModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(advertisementModels)); }
public ActionResult Edit(AdvertisementModels advertisement) { try { if (ModelState.IsValid) { db.Entry(advertisement).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(advertisement)); } catch { return(View()); } }
public ActionResult Create(PlayerModels player, int id /*int id, string content*/) { try { PlayerModels player1 = new PlayerModels(); var query = db.User.Where(i => i.Email == User.Identity.Name); UserModels user = query.Single(); var query2 = db.Advertisement.Where(i => i.ID == id); AdvertisementModels adv = query2.Single(); player1.Player = user; player1.Advertisement = adv; PlayerModels testPlayer = new PlayerModels(); testPlayer.Advertisement = adv; testPlayer.Player = user; var test = db.Player .Where(b => b.Player.ID == user.ID) .Where(c => c.Advertisement.ID == adv.ID) .FirstOrDefault(); if (test != null) { System.Diagnostics.Debug.WriteLine("You are already added to the game!"); return(RedirectToAction("Details", "AdvertisementModel", new { id })); } if (ModelState.IsValid) { System.Diagnostics.Debug.WriteLine("IS WALID"); db.Player.Add(player1); db.SaveChanges(); return(RedirectToAction("Details", "AdvertisementModel", new { id })); } return(RedirectToAction("Details", "AdvertisementModel", new { id })); } catch { return(View()); } }
public ActionResult Delete(int id) { System.Diagnostics.Debug.WriteLine("Delete advmodel"); AdvertisementModels advertisement = db.Advertisement.Find(id); try { advertisement.Players.Clear(); db.Advertisement.Remove(advertisement); db.SaveChanges(); return(RedirectToAction("Index")); } catch { ViewBag.Message = String.Format("This element is coneted with other DB you cant remove it!"); return(View(advertisement)); // 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()); } }