/// <summary> /// Adds the contact information in the database. /// </summary> public void ContactListView_InsertItem(Contact contact) { if (ModelState.IsValid) { try { Service.SaveContact(contact); Message = "Kontaktuppgiften har lagts till."; Response.Redirect(String.Format("?page={0}", LastPage.TotalRowCount / LastPage.MaximumRows + 1)); } catch (Exception) { ModelState.AddModelError(String.Empty, "Ett oväntat fel inträffade då kontaktuppgiften skulle läggas till."); } } }
/// <summary> /// Save the contact information to the database. /// </summary> /// <param name="contact">Contact information that will be saved.</param> public void SaveContact(Contact contact) { ICollection<ValidationResult> validationResults; if (!contact.Validate(out validationResults)) { var ex = new ValidationException("Objektet klarade inte valderingen."); ex.Data.Add("ValidationResult", validationResults); throw ex; } // Create a new entry if ContactID is equal to zero. if (contact.ContactID == 0) { ContactDAL.InsertContact(contact); } else { ContactDAL.UpdateContact(contact); } }