public static Car Map(this UpdateCarRequest request) { return(new Car { CarName = request.CarName, CarPrice = request.CarPrice, IsAvailable = request.IsAvailable }); }
public async Task update_car_should_update_car_information_in_repository() { // setup var givenId = 1; var givenRequest = new UpdateCarRequest { Colour = "silver", CountryManufactured = "japan", Make = "subaru", Model = "outback", Price = 8000m, Year = 2009 }; var carBeforeUpdate = await _carsService.Get(givenId); // act var result = await _carsController.Put(1, givenRequest); var okResult = result as OkObjectResult; var response = okResult.Value as AddCarResponse; // verify var carAfterUpdate = await _carsService.Get(givenId); Assert.Equal(200, okResult.StatusCode.Value); Assert.True(response.IsSuccess); Assert.Empty(response.ErrorMessage); Assert.Equal(carBeforeUpdate.Id, carAfterUpdate.Id); Assert.NotEqual(carBeforeUpdate.Colour, carAfterUpdate.Colour); //Assert.NotEqual(carBeforeUpdate.CountryManufactured, carAfterUpdate.CountryManufactured); Assert.NotEqual(carBeforeUpdate.Make, carAfterUpdate.Make); Assert.NotEqual(carBeforeUpdate.Model, carAfterUpdate.Model); Assert.NotEqual(carBeforeUpdate.Price, carAfterUpdate.Price); Assert.NotEqual(carBeforeUpdate.Year, carAfterUpdate.Year); }
public async Task <Car> CreateItemAsync(UpdateCarRequest updateRequest) { var res = updateRequest.Map(); await this.context.Cars.AddAsync(res); await this.context.SaveChangesAsync(); return(res); }
public async Task <IActionResult> Update([FromRoute] int id, [FromBody] UpdateCarRequest request) { var command = _mapper.Map <UpdateCarCommand>(request); command.Id = id; await _mediator.Send(command); return(Ok()); }
public HttpResponseMessage UpdateSong(string plate, [FromBody] UpdateCarDto request) { var carRequest = new UpdateCarRequest( request.Plate, request.Kilometers, new Brand(request.Brand.Name, request.Brand.Country), new Model(request.Model.Name, request.Model.Year) ); var updatedSong = carRepository.UpdateCar(plate, carRequest); return(this.Request.CreateResponse(HttpStatusCode.OK, updatedSong)); }
public static Task <UpdateCarResponse> UpdateCarResponseAsync(Car car, IEndpointInstance endpointInstance) { var message = new UpdateCarRequest(car); var sendOptions = new SendOptions(); sendOptions.SetDestination("NServiceBusCore.Server"); var responseTask = endpointInstance .Request <UpdateCarResponse>(message, sendOptions); return(responseTask); }
public async Task <IActionResult> AddItem([FromBody] UpdateCarRequest createRequest) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var item = await this.service.CreateItemAsync(createRequest); var location = $"/api/cars/{item.CarId}"; return(this.Created(location, item)); }
public async Task <Car> UpdateItemAsync(int id, UpdateCarRequest updateRequest) { var res = await this.context.Cars.SingleOrDefaultAsync(item => item.CarId == id); if (res == null) { throw new CarNotFoundException($"{id} not found."); } res = updateRequest.Map(); await this.context.SaveChangesAsync(); return(res); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateCarRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var carDomain = new CarDomain(id, request.Colour, request.CountryManufactured, request.Make, request.Model, request.Price, request.Year); var result = await _carsService.Update(carDomain); return(Ok(new AddCarResponse { IsSuccess = result.IsSuccess, ErrorMessage = result.IsSuccess ? string.Empty : result.Message })); }
public UpdateCarResponse Update(UpdateCarRequest request) { if (!ModelState.IsValid) { var errors = ModelState.Keys.SelectMany(key => ModelState[key].Errors.Select(x => x.ErrorMessage)); var response = new UpdateCarResponse { Success = false, Message = "Form has validation errors", Errors = errors.ToArray() }; return(response); } //send request to the car service and return the //response (success or fail) return(CarService.UpdateCar(request)); }
protected override async Task ArrangeAsync() { await base.ArrangeAsync(); var carToAdd = Fixture.Create <AddCarRequest>(); carToAdd.Year = new Random().Next(1908, DateTime.Now.Year); var result = await CarsApiClient.AddCar(carToAdd); var responseString = await result.Content.ReadAsStringAsync(); dynamic response = JsonConvert.DeserializeObject <ExpandoObject>(responseString, new ExpandoObjectConverter()); _carToUpdate = Fixture.Create <UpdateCarRequest>(); _carToUpdate.Year = new Random().Next(1908, DateTime.Now.Year); _carIdToUpdate = (int)response.id; }
public async Task <IActionResult> UpdateItem(int id, [FromBody] UpdateCarRequest updateRequest) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } try { await this.service.UpdateItemAsync(id, updateRequest); return(this.NoContent()); } catch (InvalidOperationException) { return(this.Conflict()); } catch (CarNotFoundException) { return(this.NotFound()); } }
public void CarUpdate_InsideCityLimits_DoesUpdate() { //testing within allowable drop off zone //Arrange var request = new UpdateCarRequest { Id = 95, CarCategory = "Sedan", Make = "Mercedes-Benz", Model = "CLS250", Transmission = "AT", Status = "Available", LatPos = (decimal)-37.813600, LongPos = (decimal)144.963100 }; // Act UpdateCarResponse result = Controller.Update(request); //Assert Assert.IsTrue(result.Success); }
public void CarUpdate_OutsideCityLimits_DoesNotUpdate() { //Unit testing against locations outside allowable drop off zone //Arrange var request = new UpdateCarRequest { Id = 95, CarCategory = "Sedan", Make = "Mercedes-Benz", Model = "CLS250", Transmission = "AT", Status = "Available", LatPos = (decimal)-17.571280, LongPos = (decimal)152.964494 }; // Act UpdateCarResponse result = Controller.Update(request); //Assert Assert.AreEqual("No cities are within a 50000m radius", result.Message); }
public async Task <IActionResult> UpdateAsync([FromRoute] int carId, [FromBody] UpdateCarRequest request) { Car car = (await _fleetService.GetAsync(x => x.Id == carId)).FirstOrDefault(); if (car == null) { return(NotFound(new NotFoundObjectResult($"There is no car with Id {carId}. Please try with another carId"))); } car.Registration = request.Registration; car.BonusPointsPerRental = request.BonusPointsPerRental; car.PricePerDay = request.PricePerDay; var updated = await _fleetService.UpdateAsync(car); if (!updated) { return(NotFound(new NotFoundObjectResult($"Car was not updated."))); } return(Ok(new Response <CarResponse>(_mapper.Map <CarResponse>(car)))); }
public UpdateCarResponse UpdateCar(int carId, UpdateCarRequest request) { var response = new UpdateCarResponse { Errors = new List <string>() }; _carRepository.Update(carId, new Car { Make = request.Make, Manufacturer = request.Manufacturer, Plant = request.Plant, ModelYear = request.ModelYear, Model = request.Model, Body = request.Body, Drive = request.Drive, NumberofSeats = request.NumberofSeats, NumberofDoors = request.NumberofDoors, Steering = request.Steering, EngineDisplacement = request.EngineDisplacement, EngineCylinders = request.EngineCylinders, NumberofGears = request.NumberofGears, Engine = request.Engine, Made = request.Made, Color = request.Color, Fuel = request.Fuel, Cc = request.Cc, Power = request.Power, Emissions = request.Emissions, Odometer = request.Odometer, Vin = request.Vin, License = request.License, CarImage = request.CarImage }); response.Success = true; return(response); }
public JsonResult UpdateCar(int carId, [FromBody] UpdateCarRequest request) { return(Json(_carService.UpdateCar(carId, request))); }
public Task <Car> Put(UpdateCarRequest request) { return(_updateCarService.Update(request)); }
public Engine Put(UpdateCarRequest request) { return(new Engine()); }
public Car Put(UpdateCarRequest request) { return(new Car()); }
public UpdateCarResponse UpdateCar(UpdateCarRequest request) { //this method allows cars to be updated after passing some basic checks //validate the a car category exists and fail if it doesnt var category = CarCategoryRepository.Find(request.CarCategory); if (category == null) { return new UpdateCarResponse { Message = $"Category {request.CarCategory} does not exist", Success = false } } ; //validate the a car exists and fail if it doesnt Car car; if (request.Id.HasValue) { car = CarRepository.Find(request.Id.Value); if (car == null) { return new UpdateCarResponse { Message = $"Vehicle {request.Id} does not exist", Success = false } } ; } else { car = new Car(); } //look through cities and ensure one is close enough for check in var cities = CityRepository.FindAll(); City selectedCity = null; foreach (var city in cities) { //use microsofts haversine formula (returns metres) var cityCoordinate = new GeoCoordinate((double)city.LatPos, (double)city.LongPos); var currentCoordinate = new GeoCoordinate((double)request.LatPos, (double)request.LongPos); var distance = cityCoordinate.GetDistanceTo(currentCoordinate); if (distance < Constants.BookingMaxRangeFromCityCentre) { selectedCity = city; break; } } //validates that a selected city exists if (selectedCity == null) { return(new UpdateCarResponse { Message = "No cities are within a " + $"{Constants.BookingMaxRangeFromCityCentre}m radius", Success = false }); } //assigns car values based on the parsed request to change the car car.CarCategory = request.CarCategory; car.Make = request.Make; car.Model = request.Model; car.Status = request.Status; car.Suburb = selectedCity.CityName; car.LatPos = request.LatPos; car.LongPos = request.LongPos; car.Transmission = request.Transmission; //switch to determine whether the car needs to be updated or added //to the car table if (request.Id.HasValue) { var updatedCar = CarRepository.Update(car); } else { var updatedCar = CarRepository.Add(car); } //message returned after car has been updated var response = new UpdateCarResponse { Success = true, Message = $"{request.Make} {request.Model} has been updated", Errors = null }; return(response); }