Ejemplo n.º 1
0
        public async Task <bool> UpdateBet(BetViewModel betToUpdate)
        {
            if (betToUpdate == null)
            {
                return(false);
            }

            // TODO Map BetViewModel to UpdateBetDto
            var updateBetDto = new UpdateBetDto();

            var updateResourceUrl = $"{_configProvider.UpdateBetResourceUrl}/{betToUpdate.Id}";

            var updatedBet = await _httpClient.ExecutePostRequest <UpdateBetDto, BetDto>(updateBetDto, updateResourceUrl, true);

            return(updatedBet != null);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateBet(int betId, [FromBody] UpdateBetDto updateBetDto)
        {
            try
            {
                if (updateBetDto == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var existingBet = await _betRepository.GetBet(betId);

                if (existingBet == null)
                {
                    return(NotFound());
                }

                var user = await GetUser();

                if (existingBet.User.Id != user.Id)
                {
                    return(BadRequest());
                }

                Mapper.Map(updateBetDto, existingBet);

                if (!await _betRepository.Save())
                {
                    return(GetErrorStatusCodeAndGenericMessage());
                }

                return(NoContent());
            }
            catch (Exception)
            {
                return(GetErrorStatusCodeAndGenericMessage());
            }
        }