Esempio n. 1
0
        public IHttpActionResult PutDriver(int id, MicWay.Driver.Library.Models.Driver driver)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != driver.Id)
            {
                return(BadRequest());
            }

            db.Entry(driver).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DriverExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public DeleteDriverCommandHandlerTest()
        {
            var rnd = new Random();

            _driverContext = new DriverContext(new DbContextOptionsBuilder <DriverContext>()
                                               .UseInMemoryDatabase("Test" + rnd.NextDouble().ToString())
                                               .Options);
            var driver = new Driver
            {
                FirstName = "Fulano",
                LastName  = "da Silva",
                Car       = new Car
                {
                    Brand             = "Ford",
                    Model             = "Focus",
                    RegistrationPlate = "LUJ1234"
                },
                Address = new Address
                {
                    Line1        = "Av Brasil, 9020",
                    Line2        = "Olaria",
                    Municipality = "Rio de Janeiro",
                    State        = "RJ",
                    ZipCode      = "21030-001",
                    Coordinates  = new Coordinates(-22.8370646, -43.2556345)
                }
            };

            _driverContext.Drivers.Add(driver);
            _driverContext.SaveChanges();

            _driverId = driver.DriverId;
        }
Esempio n. 3
0
        public ListDriversQueryHandlerTest()
        {
            var rnd = new Random();

            _driverContext = new DriverContext(new DbContextOptionsBuilder <DriverContext>()
                                               .UseInMemoryDatabase("Test" + rnd.NextDouble().ToString())
                                               .Options);
            _driverContext.Drivers.Add(new Driver
            {
                FirstName = "Raphael",
                LastName  = "de Abreu",
                Car       = new Car(),
                Address   = new Address()
            });
            _driverContext.Drivers.Add(new Driver
            {
                FirstName = "Aline",
                LastName  = "Maia",
                Car       = new Car(),
                Address   = new Address()
            });
            _driverContext.SaveChanges();

            _mapper = new Mapper(new MapperConfiguration(
                                     cfg => cfg.AddProfile(new DomainProfile())));
        }
Esempio n. 4
0
 public ActionResult ChangeAddressForm([Bind(Include = "DriverID,DateOfBirth,FullName,Address,City,State,ZipCode,County,DateOfChange")]
                                       Driver driver)
 {
     if (ModelState.IsValid)
     {
         database.Drivers.Add(driver);
         database.SaveChanges();
         return(RedirectToAction("AddressChanges"));
     }
     return(View(driver));
 }
Esempio n. 5
0
        private void AddDriversInfo()
        {
            using (var cont = new DriverContext())
            {
                var anatolii  = new TaxiDriver("Mykytyn", "Anatolii", 27, "BC1567AC", 5, 50, 29);
                var volodymyr = new TaxiDriver("Berkela", "Volodymyr", 19, "BC7898BM", 3, 75, 0);
                var lukyana   = new TaxiDriver("Kiral", "Lukyana", 20, "BC8765", 3, 23, 0);
                var bogdan    = new TaxiDriver("Shomko", "Bogdan", 12, "BC3456AM1", 3, 23, 50);

                cont.Drivers.Add(anatolii);
                cont.Drivers.Add(volodymyr);
                cont.Drivers.Add(lukyana);
                cont.Drivers.Add(bogdan);

                cont.SaveChanges();
            }
        }
Esempio n. 6
0
        private void AddClientsInfo()
        {
            using (var cont = new DriverContext())
            {
                var andrii  = new TaxiClient("Andrii", "+380639786514");
                var mykola  = new TaxiClient("Mykola", "+380739706543");
                var danylo  = new TaxiClient("Danylo", "+380966785432");
                var vasyl   = new TaxiClient("Vasyl", "+380967689854");
                var natalia = new TaxiClient("Natalia", "+380960807654");

                cont.Clients.Add(andrii);
                cont.Clients.Add(mykola);
                cont.Clients.Add(danylo);
                cont.Clients.Add(vasyl);
                cont.Clients.Add(natalia);
                cont.SaveChanges();
            }
        }
Esempio n. 7
0
        private void AddOrdersInfo()
        {
            using (var cont = new DriverContext())
            {
                var andrii  = (from elem in cont.Clients where elem.ClientId == 1 select elem).First();
                var mykola  = (from elem in cont.Clients where elem.ClientId == 2 select elem).First();
                var natalia = (from elem in cont.Clients where elem.ClientId == 5 select elem).First();

                var anatoliiDriver  = (from elem in cont.Drivers where elem.DriverId == 1 select elem).First();
                var volodymyrDriver = (from elem in cont.Drivers where elem.DriverId == 2 select elem).First();

                cont.Orders.Add(new TaxiOrder(mykola, anatoliiDriver, Convert.ToDateTime("2017-12-07 18:00"), "Університетська,1", "Федьковича,60", 19, 15, true));
                cont.Orders.Add(new TaxiOrder(andrii, anatoliiDriver, Convert.ToDateTime("2017-12-07 19:00"), "Наукова,7А", "Стрийська,89", 0, 0, false));
                cont.Orders.Add(new TaxiOrder(natalia, anatoliiDriver, Convert.ToDateTime("2017-12-07 15:00"), "Пасічна,70", "Сихівська,34", 0, 0, false));
                cont.Orders.Add(new TaxiOrder(andrii, volodymyrDriver, Convert.ToDateTime("2017-12-07 14:00"), "Пасічна,23", "Галицька,30", 0, 0, false));
                cont.Orders.Add(new TaxiOrder(natalia, volodymyrDriver, Convert.ToDateTime("2017-12-07 18:00"), "Університетська,1", "Вашингтона,12", 0, 0, false));
                cont.SaveChanges();
            }
        }
        public ActionResult Edit([Bind(Include = "Id, Status, Comments")] TestResult testResult)
        {
            if (ModelState.IsValid)
            {
                var result = db.TestResults.SingleOrDefault(r => r.Id == testResult.Id);
                if (result != null)
                {
                    result.Status       = testResult.Status;
                    result.Comments     = testResult.Comments;
                    result.LastModified = DateTime.Now;

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.DriverId    = new SelectList(db.Drivers, "Id", "UserName", testResult.DriverId);
            ViewBag.TestBatchId = new SelectList(db.TestBatches, "Id", "Id", testResult.TestBatchId);
            return(View(testResult));
        }
Esempio n. 9
0
 public void Save()
 {
     context.SaveChanges();
 }
Esempio n. 10
0
        public void Generate()
        {
            var db = new DriverContext();

            try
            {
                var testBatch = new TestBatch();

                // Create the batch to use below.
                db.TestBatches.Add(testBatch);

                int    batchValue;
                int    alcoholValue;
                string batchCriteria;

                // Get the settings.
                var alcoholSetting = AppSettings.GetAppSettings("AlcoholPercentage");
                var drugSetting    = AppSettings.GetAppSettings("DrugPercentage");

                // Convert to a percentage.
                var alcoholPercentage = (int.Parse(alcoholSetting) / 100.0);
                var drugPercentage    = (int.Parse(drugSetting) / 100.0);

                // Get the quantity of alcohol and drug drivers to pull.
                int alcoholToPull = Convert.ToInt16(Math.Ceiling(db.Drivers.Count(d => d.Active) * alcoholPercentage));
                int drugToPull    = Convert.ToInt16(Math.Ceiling(db.Drivers.Count(d => d.Active) * drugPercentage));

                // Check to see which one is greater to base the initial pull quantity from.
                if (drugPercentage > alcoholPercentage)
                {
                    batchValue   = drugToPull;
                    alcoholValue = alcoholToPull;
                }
                else
                {
                    batchValue   = alcoholToPull;
                    alcoholValue = alcoholToPull;
                }

                // Get the drivers based off the condition.
                var drivers = db.Drivers.OrderBy(r => Guid.NewGuid()).Take(batchValue);
                var batchId = db.TestBatches.Local.OrderByDescending(b => b.Id).Select(b => b.Id).First();

                // Insert a test result and batchId for each driver.
                foreach (var driver in drivers)
                {
                    TestResult testResult = new TestResult
                    {
                        DriverId    = driver.Id,
                        UserName    = driver.UserName,
                        TestBatchId = batchId
                    };

                    db.TestResults.Add(testResult);
                }

                // Get the quantity of drivers for alcohol testing from the existing context.
                // If the alcohol setting is greater than the drug setting all flags will be flipped.
                var alcoholCanidates = db.TestResults.Local.AsQueryable().Take(alcoholValue);

                // Flip the flag for alcohol test applicants.
                foreach (var canidate in alcoholCanidates)
                {
                    canidate.Alcohol = Alcohol.IsAlcohol;
                }

                // Insert batch criteria.
                var updateBatch = db.TestBatches.Local.OrderByDescending(b => b.Id).First();
                batchCriteria        = $"Drivers Pulled: {drivers.Count()}, Alcohol: {alcoholCanidates.Count()}, Drug: {drugSetting}%, Alcohol: {alcoholSetting}%";
                updateBatch.Criteria = batchCriteria;

                // Save changes to the context.
                db.SaveChanges();
            }
            catch (Exception e)
            {
                var error = new Error
                {
                    ErrorDesc = e.ToString()
                };

                db.Errors.Add(error);
                db.SaveChanges();
            }
        }