public ActionResult Create([Bind(Include = "ID,IdCustomer,IdSLA")] CustomerSLA customerSLA) { try { if (ModelState.IsValid) { var SLAExists = db.CustomerSLAS.Where(x => x.IdCustomer.Equals(customerSLA.IdCustomer) && x.IdSLA.Equals(customerSLA.IdSLA)).Count(); if (SLAExists == 0) { db.CustomerSLAS.Add(customerSLA); db.SaveChanges(); this.AddToastMessage("Assign SLA", "SLA successfully assigned to company.", ToastType.Success); return(RedirectToAction("Create", "CustomerSLAs", new { IdCustomer = customerSLA.IdCustomer })); } else { this.AddToastMessage("Assign SLA", "This SLA already exists for this company, please verify", ToastType.Error); return(RedirectToAction("Create", "CustomerSLAs", new { IdCustomer = customerSLA.IdCustomer })); } } } catch (Exception ex) { logger.Error(ex.ToString()); } ViewBag.IdCustomer = new SelectList(db.Customers, "Id", "CompanyName", customerSLA.IdCustomer); ViewBag.IdSLA = new SelectList(db.SLAS, "ID", "Name", customerSLA.IdSLA); return(View(customerSLA)); }
public ActionResult Delete(int id) { CustomerSLA sla = db.CustomerSLAS.Find(id); db.CustomerSLAS.Remove(sla); db.SaveChanges(); return(RedirectToAction("Create", "CustomerSLAs", new { IdCustomer = sla.IdCustomer })); }