public Person EditPerson(Person person) { // Get original person object from database, no need to assig it to a variable GetPerson(person.PersonID); _entities.Persons.ApplyCurrentValues(person); _entities.SaveChanges(); return person; }
public bool DeletePerson(Person person) { try { _personRepository.DeletePerson(person); } catch { return false; } return true; }
public bool EditPerson(Person person) { // Validation logic if (!ValidatePerson(person)) return false; // Database logic try { _personRepository.EditPerson(person); } catch { return false; } return true; }
public ActionResult Edit(Person person) { // Validation logic _personService.ValidatePerson(person); if (!ModelState.IsValid) return View(); try { _personService.EditPerson(person); return RedirectToAction("Index", "Person"); } catch { return View(); } }
/// <summary> /// Deprecated Method for adding a new object to the Persons EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPersons(Person person) { base.AddObject("Persons", person); }
/// <summary> /// Create a new Person object. /// </summary> /// <param name="personID">Initial value of the PersonID property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="addressId">Initial value of the AddressId property.</param> public static Person CreatePerson(global::System.Int32 personID, global::System.String firstName, global::System.String lastName, global::System.Int32 addressId) { Person person = new Person(); person.PersonID = personID; person.FirstName = firstName; person.LastName = lastName; person.AddressId = addressId; return person; }
public void DeletePerson(Person person) { var originalPerson = GetPerson(person.PersonID); _entities.Persons.DeleteObject(person); _entities.SaveChanges(); }
public Person CreatePerson(Person person) { _entities.AddToPersons(person); _entities.SaveChanges(); return person; }
public bool ValidatePerson(Person person) { if (person.FirstName.Trim().Length == 0) _validationDictionary.AddError("FirstName", "First name is required."); if (person.LastName.Trim().Length == 0) _validationDictionary.AddError("LastName", "Last name is required."); if (!string.IsNullOrEmpty(person.HomePhone) && !Regex.IsMatch(person.HomePhone, @"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}")) _validationDictionary.AddError("HomePhone", "Invalid phone number."); return _validationDictionary.IsValid; }