Example #1
0
        public IActionResult CreateNewDriver(CreateDriverViewModel input)
        {
            if (!ModelState.IsValid)
            {
                List <SelectListItem> list = new List <SelectListItem>
                {
                    new SelectListItem("Choose >>>", "Choose >>>")
                };

                var carrierNames = _carriersService.GetAllCarriers()
                                   .Select(x => x.Name)
                                   .ToList();

                foreach (var carrier in carrierNames)
                {
                    list.Add(new SelectListItem(carrier, carrier));
                }

                ViewBag.Carriers = list;

                return(this.View());
            }
            var vehicle = _carriersService.CreateNewDriver(input.FullName, input.CarrierName);

            return(Redirect("/Nomenclatures/Drivers"));
        }
Example #2
0
        public void CreateNewDriver_works_Properly()
        {
            string errorMessagePrefix = "CarriersService CreateNewDriver() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name = "Carrier1"
            };

            context.Carriers.Add(carrier);
            context.SaveChanges();

            var result = carriersService.CreateNewDriver("Driver1", carrier.Name);

            Assert.True(context.Drivers.Count() == 1);
            Assert.True(context.Drivers.First().FullName == "Driver1");
        }