コード例 #1
0
        public void Update(OrderDto orderDto)
        {
            var order = Database.Orders.Get(orderDto.Id);

            order.Sum = 0;
            order.QuantityProducts = 0;
            foreach (var product in orderDto.ProductsForOrderDto)
            {
                var productForOrder = order.ProductsForOrder.Find(m => m.Id == product.Id);
                if (product.Quantity != productForOrder.Quantity)
                {
                    productForOrder.Quantity = product.Quantity;
                    productForOrder.Sum      = product.Quantity * productForOrder.Price;
                    Database.ProductsForOrder.Update(productForOrder);
                }
                order.Sum += productForOrder.Sum;
                order.QuantityProducts += productForOrder.Quantity;
            }

            OrderStatusService orderderStatusService = new OrderStatusService(Database);
            var newOrderStatus = orderderStatusService.MakeOrderStatus(orderDto.Orderstatus);

            order.OrderStatuses.Add(newOrderStatus);
            order.Address       = orderDto.Address;
            order.PaymentMethod = orderDto.PaymentMethod;
            order.Orderstatus   = newOrderStatus.StatusName;
            Database.Orders.Update(order);
            Database.Save();
        }
コード例 #2
0
        public void AddNewOrderStatus(int orderId, string orderderStatusName)
        {
            var order = Database.Orders.Get(orderId);
            OrderStatusService orderderStatusService = new OrderStatusService(Database);
            var newOrderStatus = orderderStatusService.MakeOrderStatus(orderderStatusName);

            order.OrderStatuses.Add(newOrderStatus);
            order.Orderstatus = newOrderStatus.StatusName;
            Database.Orders.Update(order);
            Database.Save();
        }
コード例 #3
0
        public void MakeOrder(OrderDto orderDto)
        {
            ShoppingCartServices shoppingCartServices = new ShoppingCartServices(Database);

            OrderStatusService orderderStatusService = new OrderStatusService(Database);
            var orderStatus = orderderStatusService.MakeOrderStatus();

            ProductForOrderService productForOrderService = new ProductForOrderService(Database);
            var productForOrder = productForOrderService.CreateProductsForOrder(orderDto.ProductsForOrderDto);

            int quantityProducts = 0;

            foreach (var product in productForOrder)
            {
                quantityProducts += product.Quantity;
            }

            Order order = new Order
            {
                Date             = DateTime.Now,
                Address          = orderDto.Address,
                QuantityProducts = quantityProducts,
                Sum = orderDto.Sum,
                ApplicationUserId = orderDto.UserId,
                PhoneNumber       = orderDto.PhoneNumber,
                Orderstatus       = orderStatus.StatusName,
                PaymentMethod     = orderDto.PaymentMethod
            };

            order.OrderStatuses.Add(orderStatus);
            order.ProductsForOrder.AddRange(productForOrder);

            Database.Orders.Create(order);
            shoppingCartServices.ClearShoppingCart(orderDto.UserId);
            Database.Save();
        }