Esempio n. 1
0
        public async Task AddCarContainerTypeAsync(long id, long containerTypeId)
        {
            if (dataStore.GetAll <CarContainerType>().Any(x => x.CarId == id && x.ContainerTypeId == containerTypeId))
            {
                throw new KeyExistsException("Для автомобиля уже добавлен указанный тип контейнера");
            }

            var carContainerType = new CarContainerType
            {
                CarId           = id,
                ContainerTypeId = containerTypeId
            };

            await dataStore.SaveAsync(carContainerType);
        }
Esempio n. 2
0
        public static void CreateTestData(IDataStore dataStore)
        {
            if (!Settings.TestEnvironment || dataStore.GetAll <Car>().Any())
            {
                return;
            }

            var cars = new[]
            {
                new Car {
                    Number = "Р 261 ТК", Mark = "МАЗ", Serviceability = Enums.CarServiceability.Serviceable
                },
                new Car {
                    Number = "С 013 НЕ", Mark = "МАЗ", Serviceability = Enums.CarServiceability.Serviceable
                },
                new Car {
                    Number = "Х 773 КМ", Mark = "МАЗ", Serviceability = Enums.CarServiceability.Serviceable
                },
                new Car {
                    Number = "А 509 ВН", Mark = "МАЗ", Serviceability = Enums.CarServiceability.Serviceable
                },
                new Car {
                    Number = "А 258 НТ", Mark = "МАЗ", Serviceability = Enums.CarServiceability.Serviceable
                }
            };

            foreach (var car in cars)
            {
                dataStore.Save(car);
            }

            if (!dataStore.GetAll <ContainerType>().Any())
            {
                ContainerTypeService.CreateTestData(dataStore);
            }

            var dict = new Dictionary <string, decimal[]>
            {
                { "Р 261 ТК", new[] { 8m } },
                { "С 013 НЕ", new[] { 8m } },
                { "Х 773 КМ", new[] { 13m, 15m, 20m } },
                { "А 509 ВН", new[] { 13m, 15m, 20m } },
                { "А 258 НТ", new[] { 13m, 15m, 20m } },
            };

            foreach (var kvp in dict)
            {
                var car            = dataStore.GetAll <Car>().FirstOrDefault(x => x.Number == kvp.Key);
                var containerTypes = dataStore.GetAll <ContainerType>()
                                     .Where(x => kvp.Value.Contains(x.Capacity))
                                     .ToList();

                if (car == null || !containerTypes.Any())
                {
                    continue;
                }

                foreach (var containerType in containerTypes)
                {
                    var carContainerType = new CarContainerType
                    {
                        Car           = car,
                        ContainerType = containerType
                    };
                    dataStore.Save(carContainerType);
                }
            }
        }