public ActionResult Create([Bind(Include = "Id,客戶Id,職稱,姓名,Email,手機,電話,刪除")] 客戶聯絡人 客戶聯絡人) { var s = db聯絡人.EmailFind(客戶聯絡人.Email); if (ModelState.IsValid && (s == null)) { 客戶聯絡人.刪除 = false; db聯絡人.Add(客戶聯絡人); db聯絡人.UnitOfWork.Commit(); return(RedirectToAction("Index")); } if (s != null) { ViewBag.ErrorMessage = "你輸入的Email已經使用過"; } ViewBag.客戶Id = new SelectList(re客.All(), "Id", "客戶名稱", 客戶聯絡人.客戶Id); return(View(客戶聯絡人)); }
public ActionResult Create([Bind(Include = "Id,客戶Id,職稱,姓名,Email,手機,電話")] 客戶聯絡人 客戶聯絡人) { var s = repo.EmailFind(客戶聯絡人.Email); if (ModelState.IsValid && (s == null)) //if (ModelState.IsValid) { //db.客戶聯絡人.Add(客戶聯絡人); //db.SaveChanges(); repo.Add(客戶聯絡人); repo.UnitOfWork.Commit(); return(RedirectToAction("Index")); } else if (s != null) { ViewBag.ErrorMessage = "此 Email 已存在!"; } //ViewBag.客戶Id = new SelectList(db.客戶資料, "Id", "客戶名稱", 客戶聯絡人.客戶Id); ViewBag.客戶Id = new SelectList(repoCust.All(), "Id", "客戶名稱", 客戶聯絡人.客戶Id); return(View(客戶聯絡人)); }