public void PlaceOrder(Guid userID, Guid addressID, Shared.DTO.Cart.CartItemsDTO cartItemsDTO)
        {
            Guid  OrderId       = Guid.NewGuid();
            Guid  OrderPlacedId = Guid.NewGuid();
            Order order         = new Order {
                ID        = OrderId, DeliveryAddressID = addressID, TotalAmount = cartItemsDTO.TotalAmount, isCancelled = "N",
                OrderDate = DateTime.Now, DeliveryDate = DateTime.Now, StatusID = 1
            };

            FutureKartContext.Orders.Add(order);
            FutureKartContext.SaveChanges();
            OrderPlaced orderPlaced = new OrderPlaced {
                ID = OrderPlacedId, OrderID = OrderId, UserID = userID
            };

            FutureKartContext.OrderPlaceds.Add(orderPlaced);
            FutureKartContext.SaveChanges();
            foreach (var cartItem in cartItemsDTO.CartItems)
            {
                OrderPlacedVariant orderPlacedVariant = new OrderPlacedVariant {
                    ID = Guid.NewGuid(), OrderPlacedID = OrderPlacedId, VariantID = cartItem.Variant.ID, SellingPrice = cartItem.Variant.DiscountedPrice, Quantity = cartItem.Quantity
                };
                FutureKartContext.OrderPlacedVariants.Add(orderPlacedVariant);
                FutureKartContext.SaveChanges();
            }
        }
Beispiel #2
0
        public void PlaceOrder(Guid UserID, CartVariantItemsDTO cartVariantItemsDTO, Guid addressID)
        {
            Guid     orderID       = Guid.NewGuid();
            Guid     orderPlacedID = Guid.NewGuid();
            DateTime dateTime      = DateTime.Now;
            Order    order         = new Order {
                ID = orderID, DeliveryAddressID = addressID, TotalAmount = cartVariantItemsDTO.SubTotal, isCancelled = "N", OrderDate = dateTime, DeliveryDate = dateTime, StatusID = 1
            };

            shoppingCartEntities.Orders.Add(order);
            shoppingCartEntities.SaveChanges();
            OrderPlaced orderPlaced = new OrderPlaced {
                ID = orderPlacedID, OrderID = orderID, UserID = UserID
            };

            shoppingCartEntities.OrderPlaceds.Add(orderPlaced);
            shoppingCartEntities.SaveChanges();

            foreach (var cartItem in cartVariantItemsDTO.CartItems)
            {
                OrderPlacedVariant orderPlacedVariant = new OrderPlacedVariant
                {
                    ID            = Guid.NewGuid(),
                    OrderPlacedID = orderPlacedID,
                    VariantID     = cartItem.Variant.ID,
                    SellingPrice  = cartItem.Variant.DiscountedPrice,
                    Quantity      = cartItem.Quantity
                };

                shoppingCartEntities.OrderPlacedVariants.Add(orderPlacedVariant);
                shoppingCartEntities.SaveChanges();
            }
            return;
        }
        public bool PlacedOrder(Guid UserId, OrderDataDTO orderData, OrderVariantDTO order)
        {
            DateTime today = System.DateTime.Now;

            orderData.OrderDate    = today;
            orderData.DeliveryDate = today.AddDays(6);

            int statusid = dbContext.Status.Where(s => s.description == "Progessing").Select(s => s.ID).FirstOrDefault();

            Debug.WriteLine(dbContext.Status.Where(s => s.description == "Progessing").Select(s => s.ID).FirstOrDefault());

            orderData.StatusID = statusid;
            orderData.ID       = Guid.NewGuid();
            Order newOrder = OrderDataMapper.Map <OrderDataDTO, Order>(orderData);

            dbContext.Orders.Add(newOrder);

            //orderplcaed mapping insertion
            OrderPlaced orderPlaced = new OrderPlaced();

            orderPlaced.ID      = Guid.NewGuid();
            orderPlaced.UserID  = UserId;
            orderPlaced.OrderID = orderData.ID;
            ///end

            dbContext.OrderPlaceds.Add(orderPlaced);

            foreach (CartVariantDTO variant in order.ItemOrders.Items)
            {
                OrderPlacedVariant variantData = VariantMapper.Map <CartVariantDTO, OrderPlacedVariant>(variant);
                variantData.ID            = Guid.NewGuid();
                variantData.OrderPlacedID = orderPlaced.ID;
                dbContext.OrderPlacedVariants.Add(variantData);
            }
            foreach (var cartitem in order.ItemOrders.Items)
            {
                dbContext.Variants.FirstOrDefault(p => p.ID == cartitem.VariantID).Inventory    -= cartitem.Quantity;
                dbContext.Variants.FirstOrDefault(p => p.ID == cartitem.VariantID).QuantitySold += cartitem.Quantity;
                dbContext.Categories.FirstOrDefault(c => c.ID == cartitem.Variant.Product.CategoryID).ProductsSold += cartitem.Quantity;
            }

            dbContext.SaveChanges();
            return(true);
        }