Exemplo n.º 1
0
        public ActionResult New()
        {
            var ewcCode   = _context.EwcCodes.ToList();
            var viewModel = new WasteTypeFormViewModel
            {
                WasteType = new WasteType(),
                EwcCode   = ewcCode
            };

            return(View("WasteTypeForm", viewModel));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            var wastetype = _context.WasteTypes.SingleOrDefault(w => w.Id == id); //if the customer exists in the DB it will be returned, otherwise null

            if (wastetype == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new WasteTypeFormViewModel
            {
                WasteType = wastetype,
                EwcCode   = _context.EwcCodes.ToList()
            };


            return(View("WasteTypeForm", viewModel)); //need to specify new otherwise MVC will look for 'edit'
        }
Exemplo n.º 3
0
        public ActionResult Save(WasteType wasteType)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new WasteTypeFormViewModel
                {
                    WasteType = wasteType,
                    EwcCode   = _context.EwcCodes.ToList()
                };

                return(View("WasteTypeForm", viewModel));
            }

            if (wasteType.Id == 0)
            {
                _context.WasteTypes.Add(wasteType);
            }
            else
            {
                var wastetypeInDb = _context.WasteTypes.Single(w => w.Id == wasteType.Id);
                wastetypeInDb.Name      = wasteType.Name;
                wastetypeInDb.EwcCodeId = wasteType.EwcCodeId;
            }


            try
            {
                _context.SaveChanges();
            }


            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e);
            }

            return(RedirectToAction("Index", "WasteTypes"));
        }