コード例 #1
0
 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;
 }
コード例 #2
0
 public bool DeletePerson(Person person)
 {
     try
     {
         _personRepository.DeletePerson(person);
     }
     catch
     {
         return false;
     }
     return true;
 }
コード例 #3
0
        public bool EditPerson(Person person)
        {
            // Validation logic
            if (!ValidatePerson(person))
                return false;

            // Database logic
            try
            {
                _personRepository.EditPerson(person);
            }
            catch
            {
                return false;
            }
            return true;
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Persons EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPersons(Person person)
 {
     base.AddObject("Persons", person);
 }
コード例 #6
0
 /// <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;
 }
コード例 #7
0
 public void DeletePerson(Person person)
 {
     var originalPerson = GetPerson(person.PersonID);
     _entities.Persons.DeleteObject(person);
     _entities.SaveChanges();
 }
コード例 #8
0
 public Person CreatePerson(Person person)
 {
     _entities.AddToPersons(person);
     _entities.SaveChanges();
     return person;
 }
コード例 #9
0
 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;
 }