示例#1
0
        public async Task <CourtResponse> SaveAsync(CourtSaveResource sportSaveResource)
        {
            try
            {
                var sport = await _sportRepository.FindByIdAsync(sportSaveResource.SportId);

                if (sport == null)
                {
                    return(new CourtResponse(404, "Item id not found", "SportId", "Sport id not found."));
                }

                var item = _mapper.Map <CourtSaveResource, Court>(sportSaveResource);
                await _courtRepository.AddAsync(item);

                var responseResource = _mapper.Map <Court, CourtResource>(item);
                return(new CourtResponse(responseResource));
            }
            catch (Exception ex)
            {
                return(new CourtResponse(400, "Unexpected error", "Error", ex.Message));
            }
        }
 public async Task <int> Add(Court model)
 {
     return(await _courtRepository.AddAsync(model));
 }