public ActionResult Create([Bind(Include = "ID,idConsultant,idKPI")] ConsultantKPI consultantKPI) { try { if (ModelState.IsValid) { var KPIExists = db.ConsultantsKPIs.Where(x => x.idConsultant.Equals(consultantKPI.idConsultant) && x.idKPI.Equals(consultantKPI.idKPI)).Count(); if (KPIExists == 0) { db.ConsultantsKPIs.Add(consultantKPI); db.SaveChanges(); this.AddToastMessage("Assign KPI", "KPI successfully assigned to consultant.", ToastType.Success); return(RedirectToAction("Create", "ConsultantKPIs", new { idConsultant = consultantKPI.idConsultant })); } else { this.AddToastMessage("Assign KPI", "This KPI already exists for this consultant, please verify", ToastType.Error); return(RedirectToAction("Create", "ConsultantKPIs", new { idConsultant = consultantKPI.idConsultant })); } } } catch (Exception ex) { logger.Error(ex.ToString()); } ViewBag.idConsultant = new SelectList(db.Consultants, "Id", "FullName", consultantKPI.idConsultant); ViewBag.idKPI = new SelectList(db.SLAS, "ID", "Name", consultantKPI.idKPI); return(View(consultantKPI)); }
public ActionResult Delete(int id) { ConsultantKPI kPI = db.ConsultantsKPIs.Find(id); db.ConsultantsKPIs.Remove(kPI); db.SaveChanges(); return(RedirectToAction("Create", "ConsultantKPIs", new { idConsultant = kPI.idConsultant })); }