public ActionResult DeleteConfirmed(int id) { CustEntity custEntity = db.CustEntities.Find(id); db.CustEntities.Remove(custEntity); db.SaveChanges(); return(RedirectToAction("Index")); }
// POST: CustEntities/Remove/companyid,custid // [HttpPost] // [ValidateAntiForgeryToken] public ActionResult Remove(int comid, int custid) { CustEntity custEntity = db.CustEntities.Where(c => c.CustEntMainId == comid && c.CustomerId == custid).FirstOrDefault(); CustEntity custEntityDeleted = db.CustEntities.Find(custEntity.Id); db.CustEntities.Remove(custEntityDeleted); db.SaveChanges(); return(RedirectToAction("Details", "Customers", new { id = custid })); }
public ActionResult Edit([Bind(Include = "Id,CustEntMainId,CustomerId")] CustEntity custEntity) { if (ModelState.IsValid) { db.Entry(custEntity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustEntMainId = new SelectList(db.CustEntMains, "Id", "Name", custEntity.CustEntMainId); ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", custEntity.CustomerId); return(View(custEntity)); }
public ActionResult Create([Bind(Include = "Id,CustEntMainId,CustomerId")] CustEntity custEntity) { if (ModelState.IsValid) { db.CustEntities.Add(custEntity); db.SaveChanges(); return(RedirectToAction("Details", "Customers", new { id = custEntity.CustomerId })); } ViewBag.CustEntMainId = new SelectList(db.CustEntMains, "Id", "Name", custEntity.CustEntMainId); ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", custEntity.CustomerId); return(View(custEntity)); }
// GET: CustEntities/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CustEntity custEntity = db.CustEntities.Find(id); if (custEntity == null) { return(HttpNotFound()); } return(View(custEntity)); }
// GET: CustEntities/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CustEntity custEntity = db.CustEntities.Find(id); if (custEntity == null) { return(HttpNotFound()); } ViewBag.CustEntMainId = new SelectList(db.CustEntMains, "Id", "Name", custEntity.CustEntMainId); ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", custEntity.CustomerId); return(View(custEntity)); }
public ActionResult CompanyCreate([Bind(Include = "Id,Name,Address,Contact1,Contact2,iconPath")] CustEntMain custEntMain, int?id) { if (ModelState.IsValid) { db.CustEntMains.Add(custEntMain); db.SaveChanges(); //save new company to customer CustEntity company = new CustEntity(); company.CustEntMainId = custEntMain.Id; company.CustomerId = (int)id; db.CustEntities.Add(company); db.SaveChanges(); return(RedirectToAction("Details", "Customers", new { id = id })); } return(View(custEntMain)); }
// GET: CustEntities/Create public ActionResult Create(int?id, int?companyId) { if (id != null) { ViewBag.Id = id; } else { ViewBag.Id = 0; } Customer selectedCustomer = db.Customers.Find(id); CustEntity custEntity = db.CustEntities.Find(id); ViewBag.CustEntMainId = new SelectList(db.CustEntMains, "Id", "Name", companyId); ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", id); return(View()); }
// GET: Customers public ActionResult Index() { var customerList = db.Customers.ToList(); string category; string companyName; List <CustomerDetails> customerDetailList = new List <CustomerDetails>(); foreach (var customer in customerList) { CustCategory custcategory = new CustCategory(); CustCat custcat = new CustCat(); CustEntity companyEntity = new CustEntity(); CustEntMain company = new CustEntMain(); try { custcat = db.CustCats.Where(c => c.CustomerId == customer.Id).FirstOrDefault(); custcategory = db.CustCategories.Where(cat => cat.Id == custcat.CustCategoryId).FirstOrDefault(); } catch (Exception ex) { custcategory = new CustCategory { Id = 0, Name = "Not Assigned", iconPath = "Images/Customers/Category/unavailable-40.png" }; } try { companyEntity = db.CustEntities.Where(ce => ce.CustomerId == customer.Id).FirstOrDefault(); company = db.CustEntMains.Where(co => co.Id == companyEntity.CustEntMainId).FirstOrDefault(); } catch (Exception ex) { company = new CustEntMain { Id = 0, Name = "Not Assigned", Address = "none", Contact1 = "0", Contact2 = "0", iconPath = "Images/Customers/Category/unavailable-40.png" }; } customerDetailList.Add(new CustomerDetails { Id = customer.Id, Name = customer.Name, Email = customer.Email, Contact1 = customer.Contact1, Contact2 = customer.Contact2, Remarks = customer.Remarks, Status = customer.Status, JobID = customer.JobMains.Count(), CustCategoryID = custcategory.Id, CustCategoryIcon = custcategory.iconPath, CustEntID = company.Id, CustEntName = company.Name, CustEntIconPath = "~/Images/Customers/Company/organization-40.png", categories = getCategoriesList(customer.Id), companies = getCompanyList(customer.Id) // JobID = db.JobMains.Where(jm => jm.CustomerId.Equals(customer.Id)).FirstOrDefault() == null ? 0 : db.JobMains.Where(jm => jm.CustomerId.Equals(customer.Id)).FirstOrDefault().Id, //end }); } //return View(db.Customers.ToList()); return(View(customerDetailList)); }