Exemplo n.º 1
0
        public async Task <IEnumerable <CarModel> > Get()
        {
            var cars = await carsService.Get();

            var models = carMapper.Map(cars);

            return(models);
        }
Exemplo n.º 2
0
        public List <CarDTO> GetAllCars()
        {
            var cars   = _unitOfWork.CarRepository.GetAll();
            var result = _carMapper.Map(cars);

            foreach (var carDto in result)
            {
                var rentalArea = _unitOfWork.RentalAreaRepository.Get(carDto.RentalAreaId);
                carDto.RentalAreaName = rentalArea.Name;
            }

            return(result);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateAsync([FromBody] InCarDTO carDTO)
        {
            var car = CarMapper.Map(carDTO);

            car = _repositoryManager.CarRepository.Create(car);

            await _repositoryManager.SaveAsync();

            return(Ok(CarMapper.Map(car)));
        }
Exemplo n.º 4
0
        public void DirectMappingTest()
        {
            // Check entity to model mapping is correct
            var entity = new Car()
            {
                PublicId    = generator.Next(1, 10000),
                Name        = Guid.NewGuid().ToString("N"),
                Description = Guid.NewGuid().ToString("N")
            };

            var model = mapper.Map(entity);

            Assert.AreEqual(entity.PublicId, model.Id);
            Assert.AreEqual(entity.Name, model.Name);
            Assert.AreEqual(entity.Description, model.Description);

            // Set triggers on entity and model property list changed. Test must fail in this case
            Assert.AreEqual(4, GetPropertiesCount(entity), $"Property list at class '{ nameof(Car) }' changed. Test must be updated");
            Assert.AreEqual(3, GetPropertiesCount(model), $"Property list at class '{ model.GetType().Name }' changed. Test must be updated");
        }
Exemplo n.º 5
0
 /// <summary>
 /// Get all car records
 /// </summary>
 /// <returns></returns>
 public IEnumerable <Car> GetAllCars()
 {
     using (var command = new SqlCommand("sp_GetAllCars", _connection))
     {
         var carsList = new List <Car>();
         command.CommandType = CommandType.StoredProcedure;
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var car = CarMapper.Map(reader);
                 carsList.Add(car);
             }
         }
         return(carsList);
     }
 }
Exemplo n.º 6
0
        public async Task <IActionResult> UpdateAsync([FromRoute] int id,
                                                      [FromBody] InCarDTO carDTO)
        {
            var car = await _repositoryManager.CarRepository.GetAsync(id);

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

            car.Update(carDTO);

            _repositoryManager.CarRepository.Update(car);

            await _repositoryManager.SaveAsync();

            return(Ok(CarMapper.Map(car)));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Get car by id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Car GetCarById(int id)
 {
     using (var command = new SqlCommand("sp_GetCarById", _connection))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@CarID", id);
         var findCar = new Car();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 var car = CarMapper.Map(reader);
                 findCar = car;
             }
         }
         return(findCar);
     }
 }
Exemplo n.º 8
0
 public bool IsCarIdBooked(int id)
 {
     using (var command = new SqlCommand("sp_GetCarById", _connection))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@CarID", id);
         var car = new Car();
         using (var reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 car = CarMapper.Map(reader);
             }
         }
         if (car.Id == id)
         {
             return(true);
         }
     }
     return(false);
 }