Exemplo n.º 1
0
        public async Task <SportResponse> SaveAsync(Sport sport)
        {
            try
            {
                await _repository.AddAsync(sport);

                await _unitOfWork.CompleteAsync();

                return(new SportResponse(sport));
            }
            catch (System.Exception ex)
            {
                // Do some logging stuff
                return(new SportResponse($"An error occurred when saving the category: {ex.Message}"));
            }
        }
        public async Task <IActionResult> Create([Bind("SportId,SportName")] Sport sport)
        {
            if (sportRepository.DoesSportExist(sport.SportName))
            {
                ModelState.AddModelError("SportName", "Sport already exists. Please enter another sport.");
            }

            if (ModelState.IsValid)
            {
                sport = await sportRepository.AddAsync(sport);

                await auditLogger.log(GetUserId(), $"Created Sport {sport.SportName}");

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sport));
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
 public async Task <int> AddAsync(ISport entity)
 {
     return(await Repository.AddAsync(entity));
 }