Пример #1
0
        public void EditIncludedDriver_works_Properly()
        {
            string errorMessagePrefix = "CarriersService EditIncludedDriver() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name    = "Carrier1",
                Drivers = new List <Driver>
                {
                    new Driver
                    {
                        FullName = "Driver1"
                    },
                }
            };

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

            var driverId = context.Drivers.First().Id;

            var result = carriersService.EditIncludedDriver(driverId, "Driver2");

            Assert.True(context.Drivers.First().FullName == "Driver2");
        }
Пример #2
0
        public IActionResult EditIncludedDriver(EditDriverViewModel input)
        {
            if (!ModelState.IsValid)
            {
                var modelCarrier = _carriersService.GetCarrierByDriverId(input.Id);
                var modelDriver  = modelCarrier.Drivers.FirstOrDefault(x => x.Id == input.Id);

                return(this.View(modelDriver));
            }

            var driver  = _carriersService.EditIncludedDriver(input.Id, input.FullName);
            var carrier = _carriersService.GetCarrierByDriverId(input.Id);

            return(this.Redirect($"/Carriers/Edit?id={carrier.Id}"));
        }