예제 #1
0
        public ActionResult Create([Bind(Include = "Id,客戶Id,職稱,姓名,Email,手機,電話")] 客戶聯絡人 客戶聯絡人)
        {
            if (ModelState.IsValid)
            {
                // 驗證客戶聯繫資料是否有重複
                if (客戶聯絡人.CheckEmailIsUnique(客戶聯絡人.客戶Id, 客戶聯絡人.Email))
                {
                    ViewBag.客戶Id = new SelectList(db.客戶資料, "Id", "客戶名稱");

                    ModelState.AddModelError("Email", "客戶Email資料重複,無法新增,請您確認一下客戶聯繫Email資料");
                    return(View(客戶聯絡人));
                }
                else
                {
                    db.客戶聯絡人.Add(客戶聯絡人);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Edit([Bind(Include = "Id,客戶Id,職稱,姓名,Email,手機,電話")] 客戶聯絡人 客戶聯絡人)
        {
            if (ModelState.IsValid)
            {
                客戶聯絡人.Email = 客戶聯絡人.Email.Trim();

                if (客戶聯絡人.CheckMailChanged(客戶聯絡人.Id, 客戶聯絡人.Email) && 客戶聯絡人.CheckEmailIsUnique(客戶聯絡人.客戶Id, 客戶聯絡人.Email))
                {
                    ModelState.AddModelError("Email", "客戶Email資料重複,無法新增,請您確認一下客戶聯繫Email資料");

                    ViewBag.客戶Id = new SelectList(db.客戶資料, "Id", "客戶名稱", 客戶聯絡人.客戶Id);
                    return(View(客戶聯絡人));
                }
                else
                {
                    db.Entry(客戶聯絡人).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.客戶Id = new SelectList(db.客戶資料, "Id", "客戶名稱", 客戶聯絡人.客戶Id);
            return(View(客戶聯絡人));
        }