public async Task <IActionResult> Create([FromBody] VehicleModelDto vehicleModelDto) { var vehicleModel = mapper.Map <VehicleModel>(vehicleModelDto); await vehicleModelRepository.Insert(vehicleModel); return(Ok(vehicleModel.Id)); }
public async void Create_Returns_CreatedAtRoute_With_Value() { VehicleModelDto createVehicleModelDto = new VehicleModelDto() { Name = "test" }; var createdModel = mapper.Map <IVehicleModel>(createVehicleModelDto); createdModel.Id = Guid.NewGuid(); service.Setup(s => s.AddModelAsync(It.IsAny <IVehicleModel>())).Returns(Task.FromResult(createdModel)); var result = await controller.Create(createVehicleModelDto); var CreatedAtRouteResult = result as CreatedAtRouteResult; var modelId = CreatedAtRouteResult.RouteValues.Values as IList <object>; //Assert Assert.NotNull(result); Assert.IsAssignableFrom <CreatedAtRouteResult>(result); Assert.Equal(createdModel.Id.ToString(), modelId[0].ToString()); Assert.Equal("GetModel", CreatedAtRouteResult.RouteName); }
[HttpPost] // NE RADI --> PROVJERITI ZASTO :/ UPdate: Radi ali baca neku gresku --> provjeriti! public async Task <IActionResult> Create(VehicleModelDto newModelDto) { var newModel = await vehicleModelService.CreteAsync(mapper.Map <VehicleModel>(newModelDto)); var readModelDto = mapper.Map <VehicleMakeDto>(newModel); return(Ok()); //return CreatedAtRoute(nameof(GetModel), new { Id = readModelDto.Id }, readModelDto); }
public async Task <IActionResult> Create(VehicleModelDto createVehicleModelDto) { var modelToCreate = mapper.Map <Model.VehicleModel>(createVehicleModelDto); var createdModel = await modelService.AddModelAsync(modelToCreate); var modelToReturn = mapper.Map <VehicleModelDto>(await modelService.GetModelAsync(createdModel.Id)); return(CreatedAtRoute("GetModel", new { id = createdModel.Id }, modelToReturn)); }
public async Task <IActionResult> Update(int id, [FromBody] VehicleModelDto vehicleModelDto) { if (!await vehicleModelRepository.Exists(id)) { return(NotFound("No such vehicle model.")); } var vehicleModel = mapper.Map <VehicleModel>(vehicleModelDto); await vehicleModelRepository.Update(vehicleModel); return(Ok()); }
public async Task <IActionResult> Put(Guid id, VehicleModelDto modelUpdate) { if (id.Equals(null) || id == Guid.Empty) { return(BadRequest("Model don't exsist")); } var model = await modelService.GetModelAsync(id); if (model == null) { return(NotFound()); } var res = await modelService.UpdateModelAsync(mapper.Map(modelUpdate, model)); if (res > 0) { return(NoContent()); } throw new Exception($"Updating model {id} failed on save"); }