public IActionResult Decoration(Order order)
        {
            var countDeviceInBasket = basket.GetCountProductFromBasket();

            if (countDeviceInBasket == 0)
            {
                ModelState.AddModelError(string.Empty, "Для того чтобы совершить покупку для начало необходимо добавить товар в корзину");
            }

            if (ModelState.IsValid)
            {
                orders.CreateOrder(order);
                return(RedirectToAction("Successful", order));
            }
            return(View(order));
        }
Exemplo n.º 2
0
        public IActionResult Checkout(Order order)
        {
            _shopCart.ListShopItems = _shopCart.GetShopItems();

            if (_shopCart.ListShopItems.Count == 0)
            {
                ModelState.AddModelError("", "У вас должны быть товары!");
            }

            if (ModelState.IsValid)
            {
                _orders.CreateOrder(order);
                return(RedirectToAction("Complete"));
            }
            return(View(order));
        }
Exemplo n.º 3
0
        public async Task <object> CreateOrder([FromBody] Messages.Order.CreateTempOrderCommand cmd)
        {
            ProductResponseSuccess productResponse = (ProductResponseSuccess)await products.GetProductById(cmd.ProductId);

            decimal price = productResponse.Product.Price;

            if (productResponse.Product.Stock < 1)
            {
                throw new Exception("Invalid request");
            }

            Console.WriteLine("Order/CreateOrder");
            var result = await orders.CreateOrder(cmd.ProductId, price, GetJwt());

            Console.WriteLine("Order/CreateOrder /result");
            if (result is Messages.Order.TempOrderCreateSuccess)
            {
                Console.WriteLine("result is Success");
                //talk to the tracking service
                var resultCmd = (Messages.Order.TempOrderCreateSuccess)result;

                var reserveProductResult = await products.ReserveProduct(cmd.ProductId, resultCmd.OrderId);

                if (!(reserveProductResult is ProductReservedStatus) ||
                    ((ProductReservedStatus)reserveProductResult).Status != true)
                {
                    //TODO: await orders.ForceRemoveOrder(resultCmd.OrderId);
                    Console.WriteLine("Order/CreateOrder Error Occured");
                    return(reserveProductResult);
                }

                await tracking.CreateTrackingOrder(resultCmd.OrderId, "London", DateTime.Now + new TimeSpan(1, 2, 0, 0), GetJwt());

                Console.WriteLine("Order/CreateOrder return resultcmd");
                return(resultCmd);
            }

            Console.WriteLine("Order/CreateOrder return result");
            return(result);
        }
 public IActionResult Post([FromBody] OrderCreate newOrder)
 {
     try
     {
         return(Ok(_orders.CreateOrder(newOrder)));
     }
     catch (CustomerCanNotBeNullException)
     {
         return(BadRequest("Customer details can not be null"));
     }
     catch (MustContainOrderItemException)
     {
         return(BadRequest("Must contain at-least one order item"));
     }
     catch (OrderCreateException)
     {
         return(StatusCode(500, "Order can not be created currently, please try again later"));
     }
     catch (Exception)
     {
         return(StatusCode(500, "There was an unexpected error, please try again later"));
     }
 }