public async Task <ActionResult> AddSpot_ShouldReturnCorrectStatusCode(SpotDto dto) { _service = new SpotController(_fakeRepository); var serviceCall = _service.AddSpot(dto); return(await serviceCall as ObjectResult); }
public void EditSpot(int id, SpotDto spotDto) { var updatedSpot = _context.Spots.FirstOrDefault(s => s.Id == id); updatedSpot = Mapper.Map(spotDto, updatedSpot); _context.Spots.Update(updatedSpot); }
public SpotDto GetById(int id) { var spotDto = new SpotDto { Id = id, Name = "Fairy Bower", WaveType = "Beach" }; return(spotDto); }
private SpotDto CreateLinksForSpot(SpotDto spot) { spot.Links.Add(new LinkDto(_urlHelper.Link("GetSpot", new { id = spot.Id }), "self", "GET")); return(spot); }
public async Task <IActionResult> Post(SpotDto model) { try { var spot = _mapper.Map <Spot>(model); _repo.Add(spot); if (await _repo.SaveChangesAsync()) { return(Created("/api/spot/{model.Id}", _mapper.Map <SpotDto>(spot))); } } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Internal error 500")); } return(BadRequest()); }
public async Task CheckEndpointReturnsCorrectJson() { var server = TestServer.Create <TestStartup>(); const int expectedId = 10000; var expectedSpot = new SpotDto { Id = expectedId, Name = "Fairy Bower", WaveType = "Beach" }; //get http response var response = await server.HttpClient.GetAsync("spot/" + expectedId); //extract json from http response var spot = await response.Content.ReadAsAsync <SpotDto>(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(expectedSpot.Id, spot.Id); Assert.Equal(expectedSpot.Name, spot.Name); Assert.Equal(expectedSpot.WaveType, spot.WaveType); }
public async Task <ActionResult> AddSpot([FromBody] SpotDto spot) { if (spot == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var finalSpot = Mapper.Map <Spot>(spot); _repository.AddSpot(finalSpot); if (!_repository.SaveChanges()) { return(StatusCode(500, "Could not save changes.")); } var addedSpot = Mapper.Map <SpotDto>(finalSpot); return(Ok(_repository.GetSpot(finalSpot.Id))); }
public async Task <IActionResult> SaveSpot([FromForm] SpotDto spot) { try { var imagePath = SaveImage(spot.Image); var spotToSave = new Spot() { Title = spot.Title, Description = spot.Description, PhotoUrl = imagePath.ToString(), UserId = spot.UserId }; _spotBusiness.Add(spotToSave); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }