Example #1
0
        public ActionResult Delete(int id, WorkNC_WorkZone workZone)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(workZone).State = EntityState.Deleted;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }

                return View(workZone);
            }
            catch
            {
                return View();
            }
        }
Example #2
0
        public ActionResult Edit(int? id, WorkNC_WorkZone workZone)
        {
            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, "FactoryId", "Name");
            ViewBag.Machine = new SelectList(listMachine, "MachineId", "Name");

            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(workZone).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                return View(workZone);

            }
            catch
            {
                return View();
            }
        }
Example #3
0
        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();
            }
        }