Esempio n. 1
0
        public async Task CheckoutAsync(int basketId, string firstName, string lastName, string emailAddress, string phoneNumber, string city,
                                        string addressLine1, string addressLine2, short zipCode)
        {
            var basket = await _basketRepository.GetByIdAsync(basketId);

            if (basket == null)
            {
                throw new RecordNotFoundException(basketId, nameof(CustomerBasket));
            }

            await _orderingService.CreateOrderAsync(firstName, lastName, emailAddress, phoneNumber, city, addressLine1,
                                                    addressLine2, zipCode, basket.Items.ToDictionary(bi => bi.ProductId, bi => bi));

            basket.Items.Clear();
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(Order model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var order = await _orderService.CreateOrderAsync(model);


                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex.Message);
            }


            return(View("Create", model));
        }