Example #1
0
 public ContactDetailPage()
 {
     InitializeComponent();
     NavigationPage.SetHasNavigationBar(this, false);
     viewModel      = new ContactDetailVM();
     BindingContext = viewModel;
 }
        public JsonResult Delete([Bind(Include = "Id")] ContactDetailVM toBeRemoved)
        {
            if (toBeRemoved.Id == 0)
            {
                return(Json(new { success = false, ErrorMessage = "Id cannot be zero." }));
            }

            try
            {
                _contactService.Remove(toBeRemoved);
                return(Json(new { success = true }));
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Contact not found."))
                {
                    ModelState.AddModelError(string.Empty, "The delete failed because the contact was not found.");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "The delete failed.");
                }

                return(JsonErrorResult());
            }
        }
 public ActionResult Add([Bind(Include = "Code,Description,UnitsOfMeasure,QtyOnHand")] ContactDetailVM contactVM)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _contactService.Add(contactVM);
             return(Json(new { success = true, model = contactVM }));
         }
         catch (Exception ex)
         {
             if (ex.Message.Contains("IX_Code"))
             {
                 ModelState.AddModelError("Code", "This Contact Number already exists. Duplicate Contact Numbers are not allowed.");
             }
             else
             {
                 ModelState.AddModelError(string.Empty, "The save failed.");
             }
         }
     }
     return(JsonErrorResult());
 }
        //public JsonResult Update([Bind(Include = "Id,Code,Description,UnitsOfMeasure,QtyOnHand")]ContactVM revised)
        public JsonResult Update(ContactDetailVM revised)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var updated = _contactService.Update(revised);
                    return(Json(new { success = true, model = updated }));
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("IX_Code"))
                    {
                        ModelState.AddModelError("Code", "This Contact Number already exists. Duplicate Contact Numbers are not allowed.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "The save failed.");
                    }
                }
            }

            return(JsonErrorResult());
        }
Example #5
0
 public void LoadContacts()
 {
     ContactDetailVM.LoadContacts(_service.GetContactModels());
 }