public IActionResult CreateConvenient(Convenients model) { if (HttpContext.Session.GetString("ID") == null) { return(RedirectToAction("Login", "Admin")); } else { //check validation if (ModelState.IsValid) { //check duplicate bool check = hotelRepository.checkConvenientID(model.ID); if (check) { hotelRepository.AddConvenient(model); return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "This ID already exists."); return(View()); } } return(View(model)); } }
public void AddConvenient(Convenients _Convenients) { db.tbl_Convenient.Add(_Convenients); db.SaveChanges(); }