Beispiel #1
0
        public async Task <IActionResult> Create(CreateOrderInputViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                var hasProducts = await this.shoppingCartService.AnyProductsAsync(this.userId);

                if (!hasProducts)
                {
                    this.TempData["Error"] = ShoppingCartIsEmptyMessage;
                    return(this.RedirectToAction("Index", "Home"));
                }

                var suppliers = this.suppliersService.GetAll <SupplierViewModel>();

                var addresses = this.addressesService.GetAll <AddressViewModel>(this.userId);

                foreach (var address in addresses)
                {
                    address.Description = this.stringService.TruncateAtWord(address.Description, 30);
                }

                var countries = this.countriesService.GetAll();

                var email = this.User.Identity.Name;

                model.Suppliers = suppliers;
                model.Addresses = addresses;
                model.Email     = email;
                model.Countries = countries;

                return(this.View(model));
            }

            await this.ordersService.CreateAsync <CreateOrderInputViewModel>(model, this.userId);

            return(this.RedirectToAction(nameof(this.Complete)));
        }
Beispiel #2
0
        public async Task <IActionResult> Create()
        {
            var hasProducts = await this.shoppingCartService.AnyProductsAsync(this.userId);

            if (!hasProducts)
            {
                this.TempData["Error"] = ShoppingCartIsEmptyMessage;
                return(this.RedirectToAction("Index", "Home"));
            }

            var suppliers = this.suppliersService.GetAll <SupplierViewModel>();

            var addresses = this.addressesService.GetAll <AddressViewModel>(this.userId);

            foreach (var address in addresses)
            {
                address.Description = this.stringService.TruncateAtWord(address.Description, 30);
            }

            var countries = this.countriesService.GetAll();

            var email = this.User.Identity.Name;

            var model = new CreateOrderInputViewModel
            {
                Suppliers = suppliers,
                Addresses = addresses,
                Email     = email,
                Countries = countries,
            };

            // cancel any processing orders
            await this.ordersService.CancelAnyProcessingOrders(this.userId);

            return(this.View(model));
        }