예제 #1
0
        // GET: Devices/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var device = _deviceService.GetById(id);

            var model = new DeviceListingModel
            {
                Id = device.Id,
                ManufacturerName = device.Product.Manufacturer.ManufacturerName, //need to create IEnumerable for HTML select
                ProductName      = device.Product.ProductName,
                MacAddress       = device.MacAddress,
                Firmware         = device.Firmware,
                Quantity         = device.Quantity
            };

            if (device == null)
            {
                return(NotFound());
            }
            return(View(model));
        }
예제 #2
0
        // GET: Devices/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var device = _deviceService.GetById(id);

            var mfgList = _context.Manufacturers
                          .Select(mfg => new SelectListItem()
            {
                Value = mfg.Id.ToString(),
                Text  = mfg.ManufacturerName,
                //Selected = device.Product.Manufacturer.Id == mfg.Id ? true : false
            }).ToList();

            var productList = _context.Products
                              .Select(p => new SelectListItem()
            {
                Value = p.Id.ToString(),
                Text  = p.ProductName,
                //Selected = device.Product.Id == p.Id ? true : false
            }).ToList();

            var model = new DeviceListingModel
            {
                Id = device.Id,
                ManufacturerName = device.Product.Manufacturer.ManufacturerName, //need to create IEnumerable for HTML select
                ManufacturerId   = device.Product.Manufacturer.Id,
                Product          = device.Product,
                Location         = device.Location,
                MacAddress       = device.MacAddress,
                Firmware         = device.Firmware,
                Quantity         = device.Quantity,
                ManufacturerList = mfgList,
                ProductList      = productList
            };



            if (device == null)
            {
                return(NotFound());
            }
            return(View(model));
        }