public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var order = await _context.Orders.FindAsync(id);

            if (order == null)
            {
                return(NotFound());
            }

            var vm = new BladeViewModel(order);
            // setup the items dictionary for the select lists
            // we use the dictionary now because we have two select lists - otherwiwe use SelectItems instead
            var customers   = new SelectList(_context.Customers, "Id", "FullName");
            var orderStatus = _htmlHelper.GetEnumSelectList <OrderStatus>();

            // the keys for the dictionary are specified via the data annotations of the class
            vm.SelectItemsDictionary = new Dictionary <string, IEnumerable <SelectListItem> >()
            {
                { "Customers", customers }, { "OrderStatus", orderStatus }
            };
            // return the view
            return(View("BladeEdit", vm));
        }
Exemple #2
0
        public IActionResult Create()
        {
            var vm = new BladeViewModel(new Customer());

            // set the items for the select list in the view model
            vm.SelectItems = _htmlHelper.GetEnumSelectList <CustomerType>();
            return(View("BladeCreate", vm));
        }
        public IActionResult Create()
        {
            var vm = new BladeViewModel(new Order());
            // setup the items dictionary for the select lists
            // we use the dictionary now because we have two select lists - otherwiwe use SelectItems instead
            var customers   = new SelectList(_context.Customers, "Id", "FullName");
            var orderStatus = _htmlHelper.GetEnumSelectList <OrderStatus>();

            // the keys for the dictionary are specified via the data annotations of the class
            vm.SelectItemsDictionary = new Dictionary <string, IEnumerable <SelectListItem> >()
            {
                { "Customers", customers }, { "OrderStatus", orderStatus }
            };
            // return the view
            return(View("BladeCreate", vm));
        }
Exemple #4
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var customer = await _context.Customers.FindAsync(id);

            if (customer == null)
            {
                return(NotFound());
            }
            var vm = new BladeViewModel(new Customer());

            // set the items for the select list in the view model
            vm.SelectItems = _htmlHelper.GetEnumSelectList <CustomerType>();
            return(View("BladeEdit", vm));
        }