public ActionResult CreateBreeder(Person person) { if (person.Name == null) { ModelState.AddModelError("Name", "Name is required."); } if (person.CountryId == null) { ModelState.AddModelError("CountryId", "Country is required."); } if (ModelState.IsValid) { try { person.Breeder = true; db.Person.Add(person); db.SaveChanges(); //return Json(new { Message = "success" }); return Json(new { success = true }); } catch (Exception e) { ModelState.AddModelError("", e.Message); } } ViewBag.CountryId = new SelectList(db.Country, "Id", "Name", person.CountryId); return PartialView("CreateBreeder", person); }
public ActionResult Create(Person person) { if (ModelState.IsValid) { db.Person.Add(person); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CountryId = new SelectList(db.Country, "Id", "Name", person.CountryId); return View(person); }
public static List<Dog> CreateTestDogs() { List<Dog> dogs = new List<Dog>(); Person person = new Person() { Id = 1, Name = "Jón Jónsson" }; Dog rakki = new Dog() { Id = 1, Name = "Rakki_Founder", Reg = "IS1", Sex = "M", LitterId = 1 }; Dog tik = new Dog() { Id = 2, Name = "Tík_Founder", Reg = "IS2", Sex = "M", LitterId = 1 }; dogs.Add(rakki); dogs.Add(tik); Litter litter1 = new Litter() { Id = 1, FatherId = 1, MotherId = 2, PersonId = 1 }; Litter litter2 = new Litter() { Id = 2, FatherId = 1, MotherId = 2, PersonId = 1 }; Dog hvolpur1 = new Dog() { Id = 3, Name = "Hvolpur1", Reg = "IS3", Sex = "M", LitterId = 2 }; Dog hvolpur2 = new Dog() { Id = 4, Name = "Hvolpur2", Reg = "IS4", Sex = "F", LitterId = 2 }; dogs.Add(hvolpur1); dogs.Add(hvolpur2); return dogs; }
public ActionResult Edit(Person person) { if (ModelState.IsValid) { db.Entry(person).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CountryId = new SelectList(db.Country, "Id", "Name", person.CountryId); return View(person); }