Ejemplo n.º 1
0
 public async Task CreateOrUpdateDetails(OrderDetail detail)
 {
     var result = await _db.OrdersDetails.FindAsync(detail.IdOrder, detail.IdProduct);
     _db.Entry(detail).State = result == null ? detail.Count > 0 ? EntityState.Added : EntityState.Deleted : EntityState.Modified;
 }
Ejemplo n.º 2
0
        private IEnumerable<Cart> SaveCartItemsToOrder(Order order)
        {
            decimal orderTotal = 0;

            var cartItems = GetCartItems();
            // Iterate over the items in the cart, 
            // adding the order details for each
            foreach (var item in cartItems)
            {
                //Decimal price = 0;
                //if (item.Product.Price == null)
                //    price = 0;
                //else
                //    price = item.Product.Price;
                var orderDetail = new OrderDetail
                {
                    CourseId = item.CourseId,
                    OrderId = order.OrderId,
                    UnitPrice = item.Course.Price,
                    Quantity = item.Count
                };
                // Set the order total of the shopping cart
                orderTotal += item.Count * orderDetail.UnitPrice;
                _db.OrderDetails.Add(orderDetail);
            }
            // Set the order's total to the orderTotal count
            order.Total = orderTotal;

            // Save the order
            _db.SaveChanges();
            return cartItems;
        }
Ejemplo n.º 3
0
        private async Task CreateOrder(CreateOrderViewModel model)
        {
            var order = await GetOrder(model.GetOrder, model);
            var products = model.Products.Where(o => o.Count > 0).ToList();

            order = await OrderManager.CreateOrUpdate(order);
            foreach (var el in products)
            {
                var product = await ProductManager.FindAsync(el.Id);
                if (product == null) continue;
                var detail = new OrderDetail
                {
                    IdOrder = order.Id,
                    Product = product,
                    Order = order,
                    IdProduct = product.Id,
                    Count = el.Count,
                    Price = product.Price
                };
                await OrderManager.CreateOrUpdateDetails(detail);
            }
            await OrderManager.Save();
        }