Ejemplo n.º 1
0
        public async Task <ActionResult> AddSpot_ShouldReturnCorrectStatusCode(SpotDto dto)
        {
            _service = new SpotController(_fakeRepository);
            var serviceCall = _service.AddSpot(dto);

            return(await serviceCall as ObjectResult);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public SpotDto GetById(int id)
        {
            var spotDto = new SpotDto {
                Id = id, Name = "Fairy Bower", WaveType = "Beach"
            };

            return(spotDto);
        }
Ejemplo n.º 4
0
        private SpotDto CreateLinksForSpot(SpotDto spot)
        {
            spot.Links.Add(new LinkDto(_urlHelper.Link("GetSpot",
                                                       new { id = spot.Id }),
                                       "self",
                                       "GET"));

            return(spot);
        }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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)));
        }
Ejemplo n.º 8
0
        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));
            }
        }