public ActionResult Create([Bind(Include = "PavilionId,Name")] AnimalGroups animalGroups) { ViewBag.Exception = null; string msg = null; if (ModelState.IsValid) { db.AnimalGroups.Add(animalGroups); try { db.SaveChanges(); } catch (Exception e) { if (e.InnerException == null) { msg = e.Message; } else { msg = e.InnerException.InnerException.Message; } ViewBag.Exception = msg; return(View(animalGroups)); } return(RedirectToAction("Index")); } ViewBag.PavilionId = new SelectList(db.Pavilions, "PavilionId", "Name", animalGroups.PavilionId); return(View(animalGroups)); }
public ActionResult DeleteConfirmed(int id) { AnimalGroups animalGroups = db.AnimalGroups.Find(id); db.AnimalGroups.Remove(animalGroups); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: AnimalGroups/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AnimalGroups animalGroups = db.AnimalGroups.Find(id); if (animalGroups == null) { return(HttpNotFound()); } AnimalsGroupModelView data = new AnimalsGroupModelView(); var animals = from a in db.Animals where a.AnimalGroupId == id select a; var feedings = from f in db.Feedings where f.AnimalGroupId == id select f; try { if (animals != null) { List <Animals> tanimals = new List <Animals>(); foreach (Animals animal in animals) { tanimals.Add(animal); } data.animals = tanimals; } } catch (Exception e) { } try { if (feedings != null) { List <Feedings> tfeedings = new List <Feedings>(); foreach (Feedings feeding in feedings) { tfeedings.Add(feeding); } data.feedings = tfeedings; } }catch (Exception e) { } data.animalGroup = animalGroups; return(View(data)); }
// GET: AnimalGroups/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AnimalGroups animalGroups = db.AnimalGroups.Find(id); if (animalGroups == null) { return(HttpNotFound()); } return(View(animalGroups)); }
// GET: AnimalGroups/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AnimalGroups animalGroups = db.AnimalGroups.Find(id); if (animalGroups == null) { return(HttpNotFound()); } ViewBag.PavilionId = new SelectList(db.Pavilions, "PavilionId", "Name", animalGroups.PavilionId); return(View(animalGroups)); }
public ActionResult Edit([Bind(Include = "AnimalGroupId,PavilionId,Name,RowVersion")] AnimalGroups animalGroups) { ViewBag.Exception = null; string msg = null; if (ModelState.IsValid) { var entity = db.AnimalGroups.Single(p => p.AnimalGroupId == animalGroups.AnimalGroupId); if (entity.RowVersion != animalGroups.RowVersion) { TempData["Exception"] = "Entity was modified by another user. Check values and perform edit action again"; return(RedirectToAction("Edit")); } entity.RowVersion++; entity.PavilionId = animalGroups.PavilionId; entity.Name = animalGroups.Name; db.Entry(entity).State = EntityState.Modified; try { db.SaveChanges(); } catch (Exception e) { if (e.InnerException == null) { msg = e.Message; } else { msg = e.InnerException.InnerException.Message; } ViewBag.Exception = msg; return(View(animalGroups)); } return(RedirectToAction("Index")); } ViewBag.PavilionId = new SelectList(db.Pavilions, "PavilionId", "Name", animalGroups.PavilionId); return(View(animalGroups)); }