public ActionResult Edit(WorkNC_WorkZone workZone, HttpPostedFileBase upload) { List <WorkNC_Factory> listFactory = new List <WorkNC_Factory>(); List <WorkNC_Machine> listMachine = new List <WorkNC_Machine>(); using (WorkNCDbContext context = new WorkNCDbContext()) { listFactory = db.WorkNC_Factory.ToList(); listMachine = db.WorkNC_Machine.ToList(); } ViewBag.Factory = new SelectList(listFactory.OrderBy(n => n.Name), "FactoryId", "Name"); ViewBag.Machine = new SelectList(listMachine.OrderBy(n => n.Name), "MachineId", "Name"); try { if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { } //workZone.FactoryId = ViewBag.Factory("Name"); workZone.ModifiedDate = DateTime.Now; workZone.ModifiedAccount = User.Identity.Name; db.Entry(workZone).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(workZone)); } catch (Exception e) { ModelState.AddModelError("error", e); return(View()); } }
// GET: Factory/Create public ActionResult Create() { List <WorkNC_Company> listCompany = new List <WorkNC_Company>(); using (WorkNCDbContext db = new WorkNCDbContext()) { listCompany = db.WorkNC_Company.ToList(); } ViewBag.Company = new SelectList(listCompany, "CompanyId", "CompanyName"); return(View()); }
// GET: WorkZone/Edit/5 public ActionResult Edit(int?id) { List <WorkNC_Factory> listFactory = new List <WorkNC_Factory>(); List <WorkNC_Machine> listMachine = new List <WorkNC_Machine>(); using (WorkNCDbContext context = new WorkNCDbContext()) { listFactory = db.WorkNC_Factory.ToList(); listMachine = db.WorkNC_Machine.ToList(); } WorkNC_WorkZone workZone = db.WorkNC_WorkZone.Find(id); //fill to DropdownList ViewBag.Factory = new SelectList(listFactory.OrderBy(n => n.Name), "FactoryId", "Name"); ViewBag.Machine = new SelectList(listMachine.OrderBy(n => n.Name), "MachineId", "Name"); return(View(workZone)); }
public ActionResult FillDropDownCompany() { if (!string.IsNullOrEmpty(User.Identity.Name)) { List <WorkNC_Company> listCompany = new List <WorkNC_Company>(); using (WorkNCDbContext db = new WorkNCDbContext()) { listCompany = db.WorkNC_Company.ToList(); } var user = (from f in db.WorkNC_UserPermission where f.Username == User.Identity.Name select f).FirstOrDefault(); //check role if (user != null) { if (User.IsInRole("Admin")) { int companyId; HttpCookie cookie = Request.Cookies["cookieCompany"]; if (cookie != null) { companyId = Convert.ToInt32(cookie.Value); } else { companyId = user.CompanyId; } ViewBag.Company = new SelectList(listCompany, "CompanyId", "CompanyName", companyId); } else { listCompany = db.WorkNC_Company.Where(n => n.CompanyId == user.CompanyId && n.isDeleted == false).ToList(); ViewBag.Company = new SelectList(listCompany, "CompanyId", "CompanyName"); } } } return(PartialView("_CompanyPartial")); }
public PartialViewResult SearchMachine() { var user = (from f in db.WorkNC_UserPermission where f.Username == User.Identity.Name select f).FirstOrDefault(); List <WorkNC_Factory> listFactory = new List <WorkNC_Factory>(); using (WorkNCDbContext context = new WorkNCDbContext()) { int companyId; HttpCookie cookie = Request.Cookies["cookieCompany"]; if (cookie != null) { companyId = Convert.ToInt32(cookie.Value); } else { companyId = user.CompanyId; } listFactory = context.WorkNC_Factory.Where(n => n.CompanyId == companyId).ToList(); } ViewBag.FacrotyId = new SelectList(listFactory, "FactoryId", "Name"); return(PartialView("_SearchMachine")); }