Beispiel #1
0
        public async Task <IActionResult> Post(CreateRewardDto rewardDto)
        {
            var rewardEntity = SimpleMapper.Map <CreateRewardDto, RewardEntity>(rewardDto);

            var createdId = await _rewardService.CreateAsync(rewardEntity);

            if (createdId == Guid.Empty)
            {
                return(BadRequest());
            }
            return(Ok(createdId));
        }
Beispiel #2
0
        public async Task <RewardDto> CreateRewardAsync(CreateRewardDto dto)
        {
            // Get minimum member level record for ID
            // Validation of member level existence already handled by DTO validator
            var memberLevel = await _memberLevelRepository.GetMemberLevelByLevelAsync(dto.MinimumMemberLevel);

            // Insert reward record
            var rewardEntity = dto.ToReward();

            rewardEntity.MinimumMemberLevelId = memberLevel.Id;
            var resultEntity = await _rewardRepository.InsertAsync(rewardEntity);

            return(new RewardDto(resultEntity));
        }
Beispiel #3
0
        public DomainResult <Reward> CreateReward(CreateRewardDto createReward)
        {
            var result = new DomainResult <Reward>();
            var player = playerRepository.GetPlayer(createReward.RewardCreatorId);

            if (player == null)
            {
                result.Errors.Add(new MissingPlayerErrorModel(createReward.RewardCreatorId));
                return(result);
            }

            var rewardModel = Mapper.Map <Reward>(createReward);

            result.Entity = rewardRepository.CreateReward(rewardModel);
            rewardRepository.SaveChanges();

            return(result);
        }
Beispiel #4
0
        public IActionResult AddReward([FromBody] CreateRewardDto createReward)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _logger.LogDebug($"Creating reward");
                    var result = rewardDomain.CreateReward(createReward);
                    if (result.Invalid)
                    {
                        return(BadRequest(new ErrorDto(result)));
                    }

                    return(Created(this.Request.Path, result.Entity));
                }
                catch (Exception e)
                {
                    _logger.LogExceptions(e, this);
                    return(this.HandleErrors(e));
                }
            }

            return(BadRequest(new ErrorDto(ModelState)));
        }
        public async Task <IActionResult> CreateReward([FromBody] CreateRewardDto dto)
        {
            var result = await _rewardService.CreateRewardAsync(dto);

            return(new JsonResult(result));
        }