コード例 #1
0
 public void ListView_InsertItem(Contact contact)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Service.SaveContact(contact);
             Session["success"] = true;
             MessageStatus = "The contact was added successfully.";
             Response.Redirect("/Default.aspx");
         }
         catch (Exception)
         {
             ModelState.AddModelError(String.Empty, "An error occured when trying to create a new contact.");
         }
     }
 }
コード例 #2
0
        public void SaveContact(Contact contact)
        {
            ICollection<ValidationResult> validationResults;
            if (!contact.Validate(out validationResults))
            {
                var ex = new ValidationException("The object did not pass the validation.");
                ex.Data.Add("ValidationResult", validationResults);
                throw ex;
            }

            if (contact.ContactId == 0)
            {
                ContactDAL.InsertContact(contact);
            }
            else
            {
                ContactDAL.UpdateContact(contact);
            }
        }
コード例 #3
0
 /// <summary>
 /// Lägg till kontakt
 /// </summary>
 /// <param name="contact">Kontakt</param>
 public void ContactListView_InsertItem(Contact contact)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (TryUpdateModel(contact))
             {
                 Service.SaveContact(contact);
                 Response.Redirect(string.Concat(Request.RawUrl, "?attempt=success&message=Kontakten%20lades%20till."));
             }
         }
         catch (Exception)
         {
             ModelState.AddModelError(string.Empty, "Ett oväntat fel inträffade då kontakten skulle läggas till.");
         }
     }
 }
コード例 #4
0
 /// <summary>
 /// Ta bort kontakt (objekt)
 /// </summary>
 /// <param name="contact">Kontakt (objekt)</param>
 public void DeleteContact(Contact contact)
 {
     ContactDAL.DeleteContact(contact.ContactId);
 }