//update gym entry public void Update(SingleGym gym) { var entry = db.Entry(gym); entry.State = EntityState.Modified; db.SaveChanges(); }
// update public void Update(SingleGym gym) { var existing = Get(gym.GymId); if (existing != null) { existing.Name = gym.Name; existing.Type = gym.Type; } }
// GET: Gym/Edit/5 public ActionResult Edit(int id) { SingleGym gym = dataContext.Gyms.Where(x => x.GymID == id).Select(x => new SingleGym() { GymId = x.GymID, Name = x.Name, Type = (GymType)x.Type }).SingleOrDefault(); return(View(gym)); }
public ActionResult Delete(SingleGym model) { try { Gym selectGym = dataContext.Gyms.Where(x => x.GymID == model.GymId).Single <Gym>(); dataContext.Gyms.DeleteOnSubmit(selectGym); dataContext.SubmitChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(View(model)); } }
public ActionResult Create(SingleGym model) { try { Gym newGym = new Gym() { Name = model.Name, Type = (int)model.Type }; dataContext.Gyms.InsertOnSubmit(newGym); dataContext.SubmitChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(View(model)); } }
public ActionResult Edit(SingleGym model) { try { string tempString = model.Name.Replace(" ", String.Empty); if (tempString == String.Empty) { throw new System.ArgumentException("Name cannot be blank", "NameField"); } Gym selectGym = dataContext.Gyms.Where(x => x.GymID == model.GymId).Single <Gym>(); selectGym.Name = model.Name; selectGym.Type = (int)model.Type; dataContext.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View(model)); } }
// add public void Add(SingleGym gym) { gyms.Add(gym); gym.GymId = gyms.Max(g => g.GymId) + 1; }
// add to database public void Add(SingleGym gym) { db.Gyms.Add(gym); db.SaveChanges(); }
// GET: Gym/Create public ActionResult Create() { SingleGym newGym = new SingleGym(); return(View(newGym)); }