Example #1
0
        public async Task <ActionResult <TravelRestrictionDto> > PostCountry(TravelRestrictionDto travelRestrictionDto)
        {
            try
            {
                var mappedEntity = _mapper.Map <TravelRestrictionModel>(travelRestrictionDto);
                _travelRestrictionRepo.Add(mappedEntity);

                if (await _travelRestrictionRepo.Save())
                {
                    return(Created($"/api/v1.0/travelrestriction/{mappedEntity.TravelRestrictionId}", _mapper.Map <TravelRestrictionModel>(mappedEntity)));
                }
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }

            return(BadRequest());
        }
Example #2
0
        public async Task <ActionResult <TravelRestrictionDto> > ChangeTravelRestrictionByID(int id, [FromBody] TravelRestrictionDto travelRestrictionDto)
        {
            try
            {
                var oldTravelRestriction = await _travelRestrictionRepo.GetTravelRestrictionByID(id);

                if (oldTravelRestriction == null)
                {
                    return(NotFound($"Couldn't find any travel restriction with ID: {id}"));
                }

                var newTravelRestriction = _mapper.Map(travelRestrictionDto, oldTravelRestriction);
                _travelRestrictionRepo.Update(newTravelRestriction);

                if (await _travelRestrictionRepo.Save())
                {
                    return(NoContent());
                }
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}"));
            }
            return(BadRequest());
        }