public ActionResult EditPerson(Person person) { if (ModelState.IsValid == false) { return Json(GridResponse.Create(ModelState), JsonRequestBehavior.AllowGet); } Person other = _persons.SingleOrDefault(oth => oth.PersonId == person.PersonId); if (other == null) { other = new Person(); other.PersonId = _persons.Max(per => per.PersonId) + 1; _persons.Add(other); } other.FirstName = person.FirstName; other.LastName = person.LastName; if (person.City.Id == Guid.Empty) { other.City = null; } else { other.City = _cities.Single(city => city.Id == person.City.Id); } return Json(GridResponse.Create(true), JsonRequestBehavior.AllowGet); }
public ActionResult DeletePerson(Person person) { if (person.PersonId == 20) { return Json(GridResponse.CreateFailure("This person can't be deleted, try another!"), JsonRequestBehavior.AllowGet); } if (_persons.RemoveAll(oth => oth.PersonId == person.PersonId) == 1) { return Json(GridResponse.CreateSuccess(), JsonRequestBehavior.AllowGet); } else { return Json(GridResponse.CreateFailure("Person not found!"), JsonRequestBehavior.AllowGet); } }