public void Save(Contact model)
        {
            if (!User.Identity.IsAuthenticated)
               {
               Response.End();
               }

               var id = model.ContactId;
               bool isUpdate = false;

               Contact contact = new Contact();

               if(id > 0){
               isUpdate = true;
               contact = contactrepo.GetContactById(id);
               }

               try
            {
                contact.FirstName = model.FirstName;
                contact.LastName = model.LastName;
                contact.Phone = model.Phone;
                contact.Country = model.Country;
                contact.Address = model.Address;
                contact.RelationshipId = model.RelationshipId;

                if (!isUpdate)
                {
                    contactrepo.Add(contact);
                }

                contactrepo.Save();

                //make sure that client side knows we don't have errors
                var newmodel = helper.ToDictModel(model);
                newmodel.Add("isError", false);
                Response.Write(serializer.Serialize(newmodel));
                Response.End();

            }
            catch(Exception ex)
            {

                IEnumerable<Error> errors = contact.GetErrors();
                var errormodel = helper.ToDictModel(model);

                string errorstring = "";
                foreach (Error error in errors)
                {
                    errorstring += "<p>" + error.ErrorMessage + "</p>";
                }

                if (string.IsNullOrEmpty(errorstring)) {
                    errorstring = ex.Message;
                }

                errormodel.Add("isError", errorstring);
                Response.Write(serializer.Serialize(errormodel));
                Response.End();
            }
        }