Beispiel #1
0
        public void UpdateTruck(TruckViewModel truck)
        {
            var truckToRemove = _truckRepository.GetById(truck.TruckC);
            var updateTruck   = Mapper.Map <TruckViewModel, Truck_M>(truck);

            _truckRepository.Delete(truckToRemove);
            _truckRepository.Add(updateTruck);

            SaveTruck();
        }
 public void DeleteTruck(int id)
 {
     if (id > 0)
     {
         _truckRepo.Delete(id);
     }
 }
        public void TruckRepositoryCRUD()
        {
            ITruckModelRepository _modelRepo = serviceProvider.GetService <ITruckModelRepository>();
            ITruckRepository      _truckRepo = serviceProvider.GetService <ITruckRepository>();

            Assert.NotNull(_modelRepo.FindAllAvailableModels());
            Assert.AreEqual(2, _modelRepo.FindAllAvailableModels().Count);

            // Get first available model
            var model = _modelRepo.FindAllAvailableModels()[0];

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

            _truckRepo.Save(truck);

            // List existing trucks
            List <Truck> trucks = _truckRepo.FindAllTrucks();

            // Checking for id for that specific truck saved above
            Truck savedTruck = trucks.AsQueryable().Where(el => el.ManufacturingYear == 1929).First();

            Assert.NotNull(savedTruck);
            Assert.AreEqual(1929, savedTruck.ManufacturingYear);
            Assert.AreEqual(1929, savedTruck.ModelYear);
            Assert.AreEqual("TEST", savedTruck.Description);

            int id = savedTruck.TruckId;

            // Updating truck
            Truck toUpdate = _truckRepo.FindById(id);

            toUpdate.ModelYear = 1930;
            _truckRepo.Update(toUpdate);

            // Refetching truck
            Truck updated = _truckRepo.FindById(id);

            Assert.NotNull(updated);
            Assert.AreEqual(1929, updated.ManufacturingYear);
            Assert.AreEqual(1930, updated.ModelYear);
            Assert.AreEqual("TEST", updated.Description);

            // Deleting truck
            _truckRepo.Delete(id);

            Truck deleted = _truckRepo.FindById(id);

            Assert.Null(deleted);
        }
Beispiel #4
0
        public IActionResult Delete(TruckViewModel truck)
        {
            Truck t = truckRepository.GetSingle(truck.Chassis);

            if (t == null)
            {
                return(View("Delete", truck.Chassis));
            }

            truckRepository.Delete(t);
            return(RedirectToAction("Index"));
        }