Exemplo n.º 1
0
        public async Task <SportResponse> SaveAsync(SportSaveResource sportSaveResource)
        {
            try
            {
                var existingItem = await _sportRepository.FindByName(sportSaveResource.Name);

                if (existingItem != null)
                {
                    return(new SportResponse(400, "Item already exists", "Name", "Sport name is taken"));
                }

                var sport = _mapper.Map <SportSaveResource, Sport>(sportSaveResource);
                await _sportRepository.AddAsync(sport);

                var responseResource = _mapper.Map <Sport, SportResource>(sport);
                return(new SportResponse(responseResource));
            }
            catch (Exception ex)
            {
                return(new SportResponse(400, "Unexpected error", "Error", ex.Message));
            }
        }