Пример #1
0
        public OrderedProducts Add(string orderId, string productCode, string productName, string packegesCount, string packegesWeight)
        {
            var product = _context.Products.FirstOrDefault(x => x.ProductCode == productCode && x.Name == productName);

            var orderedProduct = new OrderedProducts()
            {
                OrderedPackagesCount  = int.Parse(packegesCount),
                OrderedPackagesWeight = decimal.Parse(packegesWeight),
                ProductId             = product.Id,
                OrderId = orderId, // TODO to find current orderId
            };

            _context.OrderedProducts.Add(orderedProduct);
            _context.SaveChanges();

            return(orderedProduct);
        }
Пример #2
0
        public Order Create(string userId,
                            string purpose,
                            string deliveryAddress,
                            string receiverName,
                            string carrierName,
                            string driverName,
                            string vehicleNumber)
        {
            OrderPurpose    deliveryPurpose = Enum.Parse <OrderPurpose>(purpose);
            DeliveryAddress address         = _context.DeliveryAddresses.FirstOrDefault(x => x.Street == deliveryAddress);
            Receiver        receiver        = _context.Receivers.FirstOrDefault(x => x.Name == receiverName);
            Carrier         carrier         = _context.Carriers.FirstOrDefault(x => x.Name == carrierName);
            Driver          driver          = _context.Drivers.FirstOrDefault(x => x.FullName == driverName && x.CarrierId == carrier.Id);
            Vehicle         vehicle         = _context.Vehicles.FirstOrDefault(x => x.RegNumber == vehicleNumber && x.CarrierId == carrier.Id);

            //int lastSequence = _context.Orders.Max(x => int.Parse(x.SequenceNumber));

            var order = new Order()
            {
                //SequenceNumber = (lastSequence + 1).ToString(),
                CreatedOn       = DateTime.UtcNow,
                Purpose         = deliveryPurpose,
                Status          = OrderStatus.Uncompleted,
                OilsUserId      = userId,
                DeliveryAddress = address,
                Receiver        = receiver,
                Carrier         = carrier,
                Driver          = driver,
                Vehicle         = vehicle
            };

            _context.Orders.Add(order);
            _context.SaveChanges();

            return(order);
        }
Пример #3
0
        public void Seed()
        {
            for (int i = 1; i < 10; i++)
            {
                this._context.Products.Add(new Product()
                {
                    Name            = $"Oil{i}",
                    ProductCode     = $"0101010{i}",
                    PackageCapacity = 205,
                    Viscosity       = $"{i * 5}/40",
                    Lots            = new List <Lot>
                    {
                        new Lot()
                        {
                            SerialNumber   = $"12{i*10}/121212",
                            PackagesCount  = 20 + i,
                            PackagesWeight = 3700,
                            Density        = 0.905m,
                        }
                    },
                });
            }

            for (int i = 1; i < 10; i++)
            {
                this._context.Receivers.Add(new Receiver()
                {
                    Name = $"Receiver{i}",
                    DeliveryAddresses = new List <DeliveryAddress>()
                    {
                        new DeliveryAddress
                        {
                            Town   = $"Town{i}",
                            Street = $"Street {i})"
                        },
                        new DeliveryAddress
                        {
                            Town   = $"Town{i + 1}",
                            Street = $"Street ({i + 1})",
                        },
                        new DeliveryAddress
                        {
                            Town   = $"Town{i + 2}",
                            Street = $"Street ({i + 2})",
                        },
                    },
                    Orders = new List <Order>()
                });
            }

            for (int i = 1; i < 10; i++)
            {
                this._context.Carriers.Add(new Carrier()
                {
                    Name    = $"Carrier{i}",
                    Drivers = new List <Driver>()
                    {
                        new Driver
                        {
                            FullName = $"Driver Driverov {i}",
                        },
                        new Driver
                        {
                            FullName = $"Driver Driverov {i + 1}",
                        },
                        new Driver
                        {
                            FullName = $"Driver Driverov {i + 2}"
                        }
                    },
                    Vehicles = new List <Vehicle>()
                    {
                        new Vehicle
                        {
                            RegNumber = $"PB{i}{i}{i}{i}AH"
                        },
                        new Vehicle
                        {
                            RegNumber = $"PB{i+1}{i+1}{i+1}{i+1}AH"
                        },
                        new Vehicle
                        {
                            RegNumber = $"PB{i+2}{i+2}{i+2}{i+2}AH"
                        },
                    },
                });
            }

            _context.SaveChanges();

            // OrderSeeding();
        }