public async Task <IActionResult> UpdateAsync(Guid?id, VehicleModelView vehicle)
        {
            try
            {
                if (id == null)
                {
                    return(BadRequest());
                }

                IVehicleModelDomain vehicleUpdate = await _service.GetIdModelAsync(vehicle.Id);

                if (vehicleUpdate == null)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    await _service.UpdateModelAsync(_mapper.Map <IVehicleModelDomain>(vehicle));
                }
            }

            catch
            {
                return(NotFound());
            }

            return(NoContent());
        }
Esempio n. 2
0
        public void ModelServiceReadTest()
        {
            //Arange
            IncludeAllMappings.include();
            var context         = new VehicleContext();
            var repository      = new Repository.Repositorys.Repository(context, new UnitOfWorkFactory(new UnitOfWork(context)));
            var makeRepository  = new MakeRepository(repository);
            var modelRepository = new ModelRepository(repository);
            var makeService     = new MakeService(makeRepository, modelRepository);
            var testService     = new ModelService(modelRepository);

            //Add make
            var vMake = new VehicleMakeDomain()
            {
                Name = "ModelServiceReadTest", Abrv = "ModelServiceReadTest", VehicleModel = null
            };

            Task.Run(async() =>
            {
                var response = await makeService.Add(vMake);
                Assert.AreEqual(1, response);
            }).GetAwaiter().GetResult();

            IVehicleMakeDomain targetMake = null;

            //Get make
            Task.Run(async() =>
            {
                var response = await makeService.ReadAll();
                Assert.IsNotNull(response);
                targetMake = response.LastOrDefault();
            }).GetAwaiter().GetResult();

            //Create model
            var vModel = new VehicleModelDomain()
            {
                Name = "ModelServiceReadTest", Abrv = "ModelServiceReadTest", VehicleMakeId = targetMake.VehicleMakeId
            };

            //Add model
            Task.Run(async() =>
            {
                var response = await testService.Add(vModel);
                Assert.AreEqual(1, response);
            }).GetAwaiter().GetResult();

            //Get model
            IVehicleModelDomain targetModel = null;

            Task.Run(async() =>
            {
                var response = await testService.ReadAll();
                Assert.IsNotNull(response);
                targetModel = response.LastOrDefault();
            }).GetAwaiter().GetResult();

            Task.Run(async() =>
            {
                //Act
                var result = await testService.Read(targetModel.VehicleModelId);
                //Assert
                Assert.AreEqual(targetModel.VehicleModelId, result.VehicleModelId);
            }).GetAwaiter().GetResult();
        }
Esempio n. 3
0
 public async Task <int> Update(IVehicleModelDomain entry)
 {
     return(await ModelRepository.Update(entry));
 }
Esempio n. 4
0
 public async Task <int> Add(IVehicleModelDomain entry)
 {
     return(await ModelRepository.Add(entry));
 }
Esempio n. 5
0
 public async Task <int> Update(IVehicleModelDomain entity)
 {
     return(await Repository.Update <VehicleModel>(AutoMapper.Mapper.Map <VehicleModel>(entity)));
 }
Esempio n. 6
0
        public void ModelRepositoryGetTest()
        {
            //Arrange
            //Init repo
            IncludeAllMappings.include();
            var context        = new VehicleContext();
            var repository     = new Repositorys.Repository(context, new UnitOfWorkFactory(new UnitOfWork(context)));
            var testRepository = new ModelRepository(repository);
            var makeRepository = new MakeRepository(repository);

            //Create maker
            var vMake = new VehicleMakeDomain()
            {
                Name = "ModelRepositoryGetTest", Abrv = "ModelRepositoryGetTest"
            };

            Task.Run(async() =>
            {
                var response = await makeRepository.Add(vMake);
                Assert.AreEqual(1, response);
            }).GetAwaiter().GetResult();

            //Get maker
            IEnumerable <IVehicleMakeDomain> getAllMakers = null;
            IVehicleMakeDomain targetMaker = null;

            Task.Run(async() =>
            {
                getAllMakers = await makeRepository.GetAll();
                Assert.IsNotNull(getAllMakers);

                foreach (var item in getAllMakers)
                {
                    targetMaker = item;
                }
            }).GetAwaiter().GetResult();

            //Create model
            var vModel = new VehicleModelDomain()
            {
                Name = "ModelRepositoryGetTest", Abrv = "ModelRepositoryGetTest", VehicleMakeId = targetMaker.VehicleMakeId
            };

            //Add model
            Task.Run(async() =>
            {
                var response = await testRepository.Add(vModel);

                Assert.AreEqual(1, response);
            }).GetAwaiter().GetResult();

            //Get model
            IEnumerable <IVehicleModelDomain> getAll;
            IVehicleModelDomain targetModel = null;

            Task.Run(async() =>
            {
                getAll = await testRepository.GetAll();
                Assert.IsNotNull(getAll);

                foreach (var item in getAll)
                {
                    targetModel = item;
                }

                var result = await testRepository.Get(targetModel.VehicleModelId);
                //Assert
                Assert.AreEqual(targetModel.VehicleModelId, result.VehicleModelId);
            }).GetAwaiter().GetResult();
        }
Esempio n. 7
0
        public async Task UpdateModelAsync(IVehicleModelDomain vehicleModel)
        {
            await _unitOfWork.Models.UpdateModelAsync(vehicleModel);

            await _unitOfWork.CompleteAsync();
        }
 public async Task UpdateModelAsync(IVehicleModelDomain vehicleModel)
 {
     VehicleModel vehicle = _mapper.Map <VehicleModel>(vehicleModel);
     await base.UpdateAsync(vehicle);
 }
 public async Task InsertModelAsync(IVehicleModelDomain vehicleModel)
 {
     VehicleModel vehicle = _mapper.Map <VehicleModel>(vehicleModel);
     await base.InsertAsync(vehicle);
 }