public ActionResult CreateSup(SupplierModel sup) { if (ModelState.IsValid) { foreach (SUPPLIER_PHONE phone in sup.Phones.ToList()) { if (phone.DeletePhone == true) { // Delete Phone Numbers which is marked to remove sup.Phones.Remove(phone); } if (phone.Phone == null) { // Delete Phone Numbers When Phone = null sup.Phones.Remove(phone); } } //เช็ค เบอร์ซ้ำ List <SUPPLIER_PHONE> pList = new List <SUPPLIER_PHONE>(sup.Phones); for (int i = 0; i < pList.Count; i++) { for (int j = 0; j < pList.Count; j++) { if (pList[i].Phone.Equals(pList[j].Phone) && i != j) { ModelState.AddModelError("", "Please complete the following information,Phone Number Fail."); return(View(sup)); } } } if (_supRepository.InsertSupAndPhone(Mapper.ToDto(sup), sup.Phones.ToList()) == false) { ModelState.AddModelError("", "Please complete the following information,Phone Number Fail."); return(View(sup)); } return(RedirectToAction("ListSup")); } ModelState.AddModelError("", "Please complete the following information."); //return Redirect("CreateSup"); return(View(sup)); }