예제 #1
0
        public OrderModel IntiateOrderCreation(string UserId)
        {
            var order        = new OrderModel();
            var cartItems    = queryService.GetCartByUserId(UserId).ToList();
            var cartPrice    = cartItems.Sum(c => c.Price);
            var deliveryCost = (cartPrice <= 50) ? 10 : 20;

            order.UserId       = UserId;
            order.TotalPrice   = cartPrice;
            order.DeliveryCost = deliveryCost;
            order.OrderNumber  = GenerateOrderNumber(UserId);
            order.Status       = "Submitted";

            order.Items = new List <OrderItems>();
            foreach (var item in cartItems)
            {
                order.Items.Add(new OrderItems
                {
                    ProductId   = item.ProductId,
                    Price       = item.Price,
                    ProductName = item.Product.Name,
                    Quantity    = item.Quantity
                });
            }

            return(order);
        }
예제 #2
0
 public IActionResult GetCartForUser(string usermail)
 {
     return(Ok(mapper.Map <IList <CartModel> >(queryService.GetCartByUserId(usermail).ToList())));
 }