Example #1
0
        public async Task <IActionResult> CreateLocation(LocationCreationDto dto)
        {
            var newLocation = new LocationCreationDto
            {
                Description = dto.Description,
                ProvinceId  = dto.ProvinceId
            };

            await _locationRepository.Create(newLocation);

            return(Ok(dto));
        }
Example #2
0
        public async Task <IActionResult> DeleteLocation(LocationCreationDto dto)
        {
            try
            {
                await _locationRepository.Delete(dto);

                return(Ok());
            }
            catch (Exception e)
            {
                return(NotFound("This Location cannot be delete"));
            }
        }
        public async Task <IActionResult> AddLocation(LocationCreationDto location)
        {
            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity());
            }
            var locationAdd = _mapper.Map <Location>(location);

            if (location == null)
            {
                return(UnprocessableEntity());
            }
            if (await _location.AddLocation(locationAdd))
            {
                return(CreatedAtRoute("GetCategory", new { id = locationAdd.LocationID }, _mapper.Map <LocationReturnDto>(locationAdd)));
            }
            return(BadRequest());
        }
Example #4
0
        public async Task <IActionResult> UpdateLocation(LocationCreationDto dto)
        {
            try
            {
                var update = new LocationCreationDto
                {
                    Description = dto.Description,
                    ProvinceId  = dto.ProvinceId
                };

                await _locationRepository.Update(dto);

                return(Ok(update));
            }
            catch (Exception e)
            {
                return(NotFound("This Location cannot be changed"));
            }
        }