Esempio n. 1
0
        public void EditIncludedVehicle_works_Properly()
        {
            string errorMessagePrefix = "CarriersService EditIncludedVehicle() method does not work properly.";

            var context = OilsProDbContextInMemoryFactory.InitializeContext();

            this.carriersService = new CarriersService(context);

            var carrier = new Carrier
            {
                Name     = "Carrier1",
                Vehicles = new List <Vehicle>
                {
                    new Vehicle()
                    {
                        RegNumber = "RegNumber1"
                    },
                }
            };

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

            var vehicleId = context.Vehicles.First().Id;

            var result = carriersService.EditIncludedVehicle(vehicleId, "RegNumber2");

            Assert.True(context.Vehicles.First().RegNumber == "RegNumber2");
        }
Esempio n. 2
0
        public IActionResult EditIncludedVehicle(EditVehicleViewModel input)
        {
            if (!ModelState.IsValid)
            {
                var modelCarrier = _carriersService.GetCarrierByVehicleId(input.Id);
                var modelVehicle = modelCarrier.Vehicles.FirstOrDefault(x => x.Id == input.Id);
                return(this.View(modelVehicle));
            }

            var vehicle = _carriersService.EditIncludedVehicle(input.Id, input.RegNumber);
            var carrier = _carriersService.GetCarrierByVehicleId(input.Id);

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