public ActionResult AddCustomer(CustomerViewModel customer) { try { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList(); return(Json(new JsonMessage { Status = JsonResultStatus.Unvalidated, Message = "UnValidate customer", Errors = errors }, JsonRequestBehavior.AllowGet)); } var result = contactService.AddCustomer(customer); if (!result) { return(Json(new JsonMessage { Status = JsonResultStatus.Unvalidated, Message = "Customer has existed before !!!" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new JsonMessage { Status = JsonResultStatus.Fail, Message = "Error during create customer" }, JsonRequestBehavior.AllowGet)); } return(Json(new JsonMessage { Status = JsonResultStatus.Success, Message = "Adding customer successfully" }, JsonRequestBehavior.AllowGet)); }