Example #1
0
 public void FormView_InsertItem(Contact contact)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var service = new Service();
             service.Savecontact(contact);
             Session["Success"] = true;
             Response.Redirect("~/");
         }
         catch (Exception)
         {
             ModelState.AddModelError(String.Empty, "Ett fel inträffade när kontakten skulle sparas");
         }
     }
 }
Example #2
0
        //spara uppdatera kontakt
        public void Savecontact(Contact contact)
        {
            //validering -valdiationextension
            ICollection<ValidationResult> validationResult;
            if (!contact.Validate(out validationResult))
            {
                var ex = new ValidationException("Kontakten klarade inte valideringen");
                ex.Data.Add("ValidationREsult", validationResult);
                throw ex;
            }

            //spara
            if (contact.ContactID == 0)
            {
                ContactDAL.InsertContact(contact);
            }
            //uppdatera
            else
            {
                ContactDAL.UpdateContact(contact);
            }
        }