Пример #1
0
        static void InsertCarTechState(string comment, CarServiceContext context)
        {
            var rand = new Random();

            int firstInspectorId = context.Inspectors.First().InspectorId;
            int firstCarId       = context.Cars.First().CarId;

            int lastInspectorId = context.Inspectors.Last().InspectorId;
            int lastCarId       = context.Cars.Last().CarId;

            var state = new CarTechState
            {
                CarId       = rand.Next(firstCarId, lastCarId + 1),
                InspectorId = rand.Next(firstInspectorId, lastInspectorId + 1),
                Date        = new DateTime(rand.Next(2000, DateTime.Now.Year + 1), rand.Next(1, 13), rand.Next(1, 29)),
                Mileage     = rand.NextDouble() * 1000.0,
                BrakeSystem = "Тормозная_система_" + rand.Next(1, 6),
                Suspension  = "Подвеска_" + rand.Next(1, 6),
                Wheels      = "Колёса_" + rand.Next(1, 6),
                Lightning   = "Осветительный_прибор_" + rand.Next(1, 6),
                MarkOnPassageOfServiceStation = rand.NextBool()
            };

            Insert(comment, "Car tech state", state, context);
        }
Пример #2
0
        static void Remove(string comment, CarServiceContext context)
        {
            Console.WriteLine(comment);

            var inspectorCountBefore = context.Inspectors.Count();
            var statesCountBefore    = context.CarTechStates.Count();

            var inspectors    = context.Inspectors.Where(i => i.Subdivision.Contains("5"));
            var carTechStates = context
                                .CarTechStates
                                .Include("Inspector")
                                .Where(c => c.Inspector.Subdivision.Contains("5"));

            context.CarTechStates.RemoveRange(carTechStates);
            context.SaveChanges();

            context.Inspectors.RemoveRange(inspectors);
            context.SaveChanges();

            var inspectorCountAfter = context.Inspectors.Count();
            var statesCountAfter    = context.CarTechStates.Count();

            Console.WriteLine("Кол-во инспекторов до удаления - " + inspectorCountBefore);
            Console.WriteLine("Кол-во инспекторов после удаления - " + inspectorCountAfter);

            Console.WriteLine("\nКол-во записей о тех. состоянии автомобилей до удаления - " + statesCountBefore);
            Console.WriteLine("Кол-во записей о тех. состоянии автомобилей после удаления - " + statesCountAfter);

            Console.WriteLine();
            Console.WriteLine("Для продолжения нажмите клавишу Enter...");
            Console.ReadLine();
        }
        public void InitializeDatabaseWithDataTest()
        {
            using (var context = new CarServiceContext(_options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var car1 = new Car()
                {
                    Producer       = "Volkswagen",
                    Model          = "Golf IV",
                    ProductionDate = new DateTime(2009, 01, 01),
                    IsOnWarranty   = false
                };

                var car2 = new Car()
                {
                    Producer       = "Peugeot",
                    Model          = "206",
                    ProductionDate = new DateTime(2000, 01, 01),
                    IsOnWarranty   = false
                };

                context.Cars.AddRange(car1, car2);
                context.SaveChanges();
            }
        }
Пример #4
0
        public ImplCarService()
        {
            var autoContext = new CarServiceContext();
            var unitOfWork  = new UnitOfWork(autoContext);

            var autoRepository           = new Repository <Auto>(unitOfWork);
            var clientRepository         = new Repository <Client>(unitOfWork);
            var comandaRepository        = new Repository <Comanda>(unitOfWork);
            var detaliuComandaRepository = new Repository <DetaliuComanda>(unitOfWork);
            var imagineRepository        = new Repository <Imagine>(unitOfWork);
            var materialRepository       = new Repository <Material>(unitOfWork);
            var mecanicRepository        = new Repository <Mecanic>(unitOfWork);
            var operatieRepository       = new Repository <Operatie>(unitOfWork);
            var sasiuRepository          = new Repository <Sasiu>(unitOfWork);

            clientService         = new ClientService(clientRepository, unitOfWork);
            autoService           = new AutoService(autoRepository, unitOfWork);
            comandaService        = new ComandaService(comandaRepository, unitOfWork);
            detaliuComandaService = new DetaliuComandaService(detaliuComandaRepository, unitOfWork);
            imagineService        = new ImagineService(imagineRepository, unitOfWork);
            materialService       = new MaterialService(materialRepository, unitOfWork);
            mecanicService        = new MecanicService(mecanicRepository, unitOfWork);
            operatieService       = new OperatieService(operatieRepository, unitOfWork);
            sasiuService          = new SasiuService(sasiuRepository, unitOfWork);
        }
 public WorksheetsController(CarServiceContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     _context = context;
 }
        public async Task Invoke(HttpContext context, CarServiceContext carContext, IMemoryCache cache)
        {
            CheckExistance <Car>("CarsTuple", carContext, cache);
            CheckExistance <Inspector>("InspectorsTuple", carContext, cache);
            CheckExistance <CarTechState>("StatesTuple", carContext, cache);

            await _next(context);
        }
Пример #7
0
        public void Setup()
        {
            var options = new DbContextOptionsBuilder <CarServiceContext>()
                          .UseInMemoryDatabase("CarServiceTest")
                          .Options;

            _context = new CarServiceContext(options);
            _context.Database.EnsureCreated();
        }
        public void Setup()
        {
            var options = new DbContextOptionsBuilder <CarServiceContext>()
                          .UseInMemoryDatabase("CarServiceTest" + DateTime.Now.ToFileTimeUtc())
                          .Options;

            _context = new CarServiceContext(options);
            _context.Database.EnsureCreated();
            AddTestUsers();
        }
Пример #9
0
        public static IEnumerable <SelectListItem> GetOrderTypes()
        {
            var dbContext = new CarServiceContext();

            return(dbContext.OrderType.Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text = n.Name
            }));
        }
        void CheckExistance <T>(string key, CarServiceContext context, IMemoryCache cache) where T : class
        {
            if (!cache.TryGetValue(key, out T obj))
            {
                obj = context.Set <T>().Last();

                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetAbsoluteExpiration(TimeSpan.FromSeconds(252));

                cache.Set(key, obj, cacheEntryOptions);
            }
        }
Пример #11
0
        static void InsertInspector(string comment, CarServiceContext context)
        {
            var rand = new Random();

            var inspector = new Inspector
            {
                FullName    = new FullName().ToString(),
                Subdivision = "Подразделение_" + rand.Next(1, 6)
            };

            Insert(comment, "Инспектор", inspector, context);
        }
Пример #12
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Database.SetInitializer(new CarServiceInitializer());
            using (var context = new CarServiceContext())
            {
                context.Database.Initialize(force: true);
            }
        }
Пример #13
0
        static void Insert <T>(string comment, string type, T obj, CarServiceContext context)
            where T : class
        {
            Console.WriteLine(comment);
            Console.WriteLine(type);
            Console.WriteLine(obj);

            Console.WriteLine("Кол-во записей до добавления: " + context.Set <T>().Count());

            context.Set <T>().Add(obj);
            context.SaveChanges();

            Console.WriteLine("Кол-во записей после добавления: " + context.Set <T>().Count());

            Console.WriteLine();
            Console.WriteLine("Для продолжения нажмите клавишу Enter...");
            Console.ReadLine();
        }
Пример #14
0
        static void UpdateMileage(string comment, CarServiceContext context)
        {
            Console.WriteLine(comment);

            var states = context.CarTechStates.Where(c => c.Date > DateTime.Now.AddYears(-10));

            PrintQuery("До обновления:", states.Take(10));

            foreach (var item in states)
            {
                item.Mileage += 1000.0;
            }

            context.SaveChanges();

            PrintQuery("После обновления:", states.Take(10));

            Console.WriteLine();
            Console.WriteLine("Для продолжения нажмите клавишу Enter...");
            Console.ReadLine();
        }
Пример #15
0
        public void ThatServiceCreatesCar()
        {
            // Arrange
            var ownerId        = Guid.NewGuid();
            var context        = CarServiceContext.GivenContext();
            var singleEvent    = context.WithSingleEvent(ownerId);
            var before         = context.Repository.Find(new GetCars()).Count();
            var carForCreation = context
                                 .Fixture
                                 .Build <CarForCreation>()
                                 .With(x => x.EventId, singleEvent.EventId)
                                 .Create();

            // Act
            context.CarService.CreateCarForEvent(ownerId.ToString(), carForCreation);

            // Assert
            var after = context.Repository.Find(new GetCars()).Count();

            Assert.That((after - before).Equals(1));
        }
Пример #16
0
        static void Main(string[] args)
        {
            var autoContext = new CarServiceContext();
            var unitOfWork  = new UnitOfWork(autoContext);

            var autoRepository   = new Repository <Auto>(unitOfWork);
            var clientRepository = new Repository <Client>(unitOfWork);
            var sasiuRepository  = new Repository <Sasiu>(unitOfWork);


            var clientService = new ClientService(clientRepository, unitOfWork);
            var autoService   = new AutoService(autoRepository, unitOfWork);
            var sasiuService  = new SasiuService(sasiuRepository, unitOfWork);

            var sasiuDto = new SasiuDto
            {
                Denumire = "Fara Denumire",
                CodSasiu = "8D"
            };

            var updateSasiu = sasiuService.FindById(3);

            updateSasiu.CodSasiu = "8D";

            //sasiuService.CreateNew(sasiuDto);
            sasiuService.Update(updateSasiu);

            /*var client = new ClientDto
             * {
             *  Nume = "Nume1",
             *  Prenume = "Prenume1",
             *  Email = "*****@*****.**",
             *  Adresa = "Adresa1",
             *  Judet = "Judet1",
             *  Localitate = "Localitate1"
             * };*/

            //clientService.CreateNew(client);
            //clientService.Delete(5);
        }
 public RequestServiceByClientService(CarServiceContext context, IMapper mapper)
 {
     _mapper  = mapper;
     _context = context;
 }
 public CarTechStatesController(CarServiceContext context)
 {
     _context = context;
 }
Пример #19
0
 public WorksheetRepository(CarServiceContext context, IMapper mapper)
     : base(context, mapper)
 {
 }
 public ScheduleSecondService(CarServiceContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Пример #21
0
 public CarServiceService(CarServiceContext context)
 {
     _context   = context;
     _validator = new AppointmentDateValidator(_context);
 }
Пример #22
0
 public OfferItemsService(CarServiceContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Пример #23
0
 public BaseCRUDService(CarServiceContext context, IMapper mapper) : base(context, mapper)
 {
 }
Пример #24
0
        static void Main(string[] args)
        {
            using (var context = new CarServiceContext())
            {
                CarServiceInitializer.Initialize(context);

                PrintQuery(
                    "Выборка всех данных из таблицы, стоящей в схеме базы" +
                    " данных нас стороне отношения «один»:",
                    context.Inspectors.ToList()
                    );

                PrintQuery(
                    "Выборка данных из таблицы, стоящей в схеме базы данных" +
                    " нас стороне отношения «один», отфильтрованные по" +
                    " определенному условию, налагающему ограничения на одно" +
                    " или несколько полей:",
                    context.Inspectors.Where(i => i.Subdivision.Contains("1"))
                    );

                PrintQuery(
                    "Выборка данных, сгруппированных по любому из полей данных" +
                    " с выводом какого-либо итогового результата (min," +
                    " max, avg, сount или др.) по выбранному полю из таблицы," +
                    " стоящей в схеме базы данных нас стороне отношения «многие»:",
                    context
                    .CarTechStates
                    .GroupBy(c => c.MarkOnPassageOfServiceStation, c => c.CarTechStateId)
                    .Select(group => new
                {
                    MarkOnPassage    = group.Key,
                    PassedCarService = group.Count()
                })
                    );

                PrintQuery(
                    "Выборка данных из двух полей двух таблиц, связанных" +
                    " между собой отношением «один-ко-многим»:",
                    context.CarTechStates.Include("Inspector").Select(c => new
                {
                    c.CarTechStateId,
                    InspectorName = c.Inspector.FullName
                })
                    );

                PrintQuery(
                    "Выборка данных из двух таблиц, связанных между собой" +
                    " отношением «один-ко-многим» и отфильтрованным по" +
                    " некоторому условию, налагающему ограничения на значения" +
                    " одного или нескольких полей:",
                    context
                    .CarTechStates
                    .Include("Inspector")
                    .Where(c => c.Date < DateTime.Now.AddYears(-10))
                    .Select(c => new {
                    c.CarTechStateId,
                    c.Date,
                    InspectorName = c.Inspector.FullName
                })
                    );

                InsertInspector("Вставка данных в таблицу, стоящей на стороне" +
                                " отношения «Один»:", context
                                );

                InsertCarTechState("Вставка данных в таблицу, стоящей на" +
                                   " стороне отношения «Многие»", context
                                   );

                Remove(
                    "Удаление данных из таблиц, стоящих на стороне отношения" +
                    " «Один» и «Многие»", context
                    );

                UpdateMileage(
                    "Обновление удовлетворяющих определенному условию записей" +
                    " в любой из таблиц базы данных", context
                    );
            }
        }
 public RecommenderService(CarServiceContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public ReservationRepository(CarServiceContext context, IMapper mapper)
     : base(context, mapper)
 {
 }
Пример #27
0
 public InspectorsController(CarServiceContext context)
 {
     _context = context;
 }
 public HomeController(CarServiceContext context, IMemoryCache cache)
 {
     _context = context;
     _cache   = cache;
 }
Пример #29
0
 public RatingsService(CarServiceContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Пример #30
0
 public UserService(CarServiceContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }