Ejemplo n.º 1
0
        public ActionResult Save(客戶聯絡人 model)
        {
            var msg = "客戶聯絡人" + (model.Id == 0 ? "新增" : "更新") + "成功";

            if (ModelState.IsValid)
            {
                try
                {
                    ContactRepo.Save(model);
                    ContactRepo.UnitOfWork.Commit();
                    return(Json(new { id = model.Id, isValid = true, message = HttpUtility.HtmlEncode(msg) }));
                }
                catch (Exception ex)
                {
                    return(Json(new { isValid = false, message = HttpUtility.HtmlEncode("客戶聯絡人儲存失敗。錯誤訊息: " + ex.Message) }));
                }
            }
            msg = string.Join(" ", ModelState.Values.SelectMany(p => p.Errors).Select(p => p.ErrorMessage));
            return(Json(new { isValid = false, message = HttpUtility.HtmlEncode("客戶聯絡人儲存時,驗證欄位失敗。" + msg) }));
        }