Пример #1
0
        public IActionResult Delete(int id)
        {
            var truck = _service.FindTruckById(id);

            if (truck != null)
            {
                var truckmodel = new TruckViewModel(truck);
                return(View(truckmodel));
            }
            return(RedirectToAction("Error"));
        }
        public async Task <IActionResult> Save(Guid?idTruck)
        {
            var models = await _modelService.ListModels();

            ViewData["ModelId"] = new SelectList(models, "Id", "Name");

            if (idTruck.HasValue)
            {
                var truck = await _truckService.FindTruckById(idTruck.GetValueOrDefault());

                return(await ViewAsync(truck));
            }
            return(View());
        }
Пример #3
0
        public void TruckServiceFunctions()
        {
            ITruckService _service = serviceProvider.GetService <ITruckService>();

            List <TruckModel> models = _service.ListAvailableModels();

            Assert.NotNull(models);
            Assert.AreEqual(2, models.Count);
            // Get first available model
            var model = models[0];

            // Saving new Truck with specific information
            Truck truck = new Truck()
            {
                Description       = "TEST",
                ManufacturingYear = 1944,
                ModelYear         = 1944,
                Model             = model,
                TruckModelId      = model.TruckModelId
            };

            List <Truck> receivedTrucks = _service.ListAllTrucks();
            List <Truck> filtered       = receivedTrucks.Where(t => t.ManufacturingYear == 1944 || t.ModelYear == 1944).ToList();

            Assert.AreEqual(0, filtered.Count);

            _service.SaveOrUpdateTruck(truck);

            receivedTrucks = _service.ListAllTrucks();
            filtered       = receivedTrucks.Where(t => t.ManufacturingYear == 1944 || t.ModelYear == 1944).ToList();

            Assert.AreEqual(1, filtered.Count);

            Truck saved = filtered[0];

            Assert.AreEqual(1944, saved.ManufacturingYear);
            Assert.AreEqual(1944, saved.ModelYear);
            Assert.AreEqual("TEST", saved.Description);

            int id = saved.TruckId;

            Truck toUpdate = _service.FindTruckById(id);

            Assert.NotNull(toUpdate);

            toUpdate.ModelYear = 1950;
            _service.SaveOrUpdateTruck(toUpdate);

            receivedTrucks = _service.ListAllTrucks();
            filtered       = receivedTrucks.Where(t => t.ManufacturingYear == 1944 && t.ModelYear == 1950).ToList();

            Assert.AreEqual(1, filtered.Count);

            Truck updated = filtered[0];

            Assert.AreEqual(1944, updated.ManufacturingYear);
            Assert.AreEqual(1950, updated.ModelYear);
            Assert.AreEqual("TEST", updated.Description);

            _service.DeleteTruck(id);

            receivedTrucks = _service.ListAllTrucks();
            filtered       = receivedTrucks.Where(t => t.ManufacturingYear == 1944 || t.ModelYear == 1950).ToList();

            Assert.AreEqual(0, filtered.Count);
        }