Beispiel #1
0
        public async Task <ActionResult <AttractionDto> > PutAttraction(int attractionid, [FromBody] AttractionDto attractionDto)
        {
            try
            {
                var oldattraction = await _attractionRepo.GetAttractionByID(attractionid);

                if (oldattraction == null)
                {
                    return(NotFound($"There is no attraction with id:{attractionid}"));
                }
                var newAttraction = _mapper.Map(attractionDto, oldattraction);
                _attractionRepo.Update(newAttraction);
                if (await _attractionRepo.Save())
                {
                    return(NoContent());
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure:{e.Message}"));
            }
            return(BadRequest());
        }
        public async Task <ActionResult <AttractionDto> > PostEvent(AttractionDto attractionDto)
        {
            try
            {
                var mappedEntity = _mapper.Map <AttractionModel>(attractionDto);
                _attractionRepo.Add(mappedEntity);
                if (await _attractionRepo.Save())
                {
                    return(Created($"/api/v1.0/attraction/{mappedEntity.AttractionId}", _mapper.Map <AttractionDto>(mappedEntity)));
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }

            return(BadRequest());
        }