public ActionResult Create() { HungryGroupViewModel hungrygroup = new HungryGroupViewModel(); hungrygroup.EatItemsDropdown = GetEatTypeItems(); hungrygroup.PlacesDropdown = GetPlaces(); return View(hungrygroup); }
public ActionResult Create(HungryGroupViewModel hungrygroup) { if (ModelState.IsValid) { hungrygroup.Creator = this.Db.UsersRepository.All().FirstOrDefault(x => x.UserName == User.Identity.Name); hungrygroup.Place = this.Db.PlaceRepository.All().FirstOrDefault(x => x.Id == hungrygroup.PlaceId); HungryGroup newGroup = new HungryGroup() { Creator = hungrygroup.Creator, EatTime = hungrygroup.EatTime, HungryUsers = hungrygroup.HungryUsers, Id = hungrygroup.Id, Place = hungrygroup.Place, StartingTime = hungrygroup.StartingTime }; this.Db.HungryGroupRepository.Add(newGroup); this.Db.SaveChanges(); return RedirectToAction("Index"); } return View(hungrygroup); }
// GET: /Administration/HungryGroups/Edit/5 public ActionResult Edit(int? id) { HungryGroupViewModel hungryGroupModel = new HungryGroupViewModel(); hungryGroupModel.EatItemsDropdown = GetEatTypeItems(); hungryGroupModel.PlacesDropdown = GetPlaces(); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } HungryGroup hungrygroup = this.Db.HungryGroupRepository.All().FirstOrDefault(x => x.Id == id); if (hungrygroup == null) { return HttpNotFound(); } else { hungryGroupModel.EatTime = hungrygroup.EatTime; hungryGroupModel.EatItemsDropdown.FirstOrDefault(x => x.Text == hungryGroupModel.EatTime.ToString()).Selected = true; hungryGroupModel.StartingTime = hungrygroup.StartingTime; } return View(hungryGroupModel); }
public ActionResult Edit(HungryGroupViewModel hungrygroup) { var place = db.Places.FirstOrDefault(x => x.Id == hungrygroup.Id); HungryGroup editedHungryGroup = new HungryGroup() { Creator = hungrygroup.Creator, EatTime = hungrygroup.EatTime, HungryUsers = hungrygroup.HungryUsers, Id = hungrygroup.Id, Place = place, StartingTime = hungrygroup.StartingTime }; if (ModelState.IsValid) { db.Entry(editedHungryGroup).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(hungrygroup); }