Пример #1
0
 public GoalUpdateDtoTest()
 {
     _goal = new GoalUpdateDto()
     {
         Title       = "Learn Vue",
         Description = "Learn Vue and create a project with it",
         Completed   = false,
         GoalType    = "yearly"
     };
 }
Пример #2
0
        public async Task Execute(GoalUpdateDto goalUpdateDto)
        {
            await goalsWriteDbOperations.Update(goalUpdateDto.Id, goalUpdateDto.Title, goalUpdateDto.Description);

            await messageBus.Publish(new GoalUpdatedEventV1
            {
                Id       = goalUpdateDto.Id,
                GoalPart = new GoalUpdatedEventV1GoalPart
                {
                    Title       = goalUpdateDto.Title,
                    Description = goalUpdateDto.Description
                }
            });
        }
Пример #3
0
        public ActionResult <GoalReadDto> UpdateGoal(int id, int userId, GoalUpdateDto goalUpdateDto)
        {
            var goalModelFromRepo = _goalRepo.GetGoalById(id);

            if (goalModelFromRepo == null)
            {
                return(NotFound());
            }
            else if (goalModelFromRepo.UserId == userId)
            {
                // maps the goal objects with the new values to the goal object that has been created, and updates the new changes
                _mapper.Map(goalUpdateDto, goalModelFromRepo);
                _goalRepo.UpdateGoal(goalModelFromRepo);
                _goalRepo.SaveChanges();
                var goalReadDto = _mapper.Map <GoalReadDto>(goalModelFromRepo);

                return(CreatedAtAction(nameof(GetGoalById), new { id = goalReadDto.Id }, goalReadDto));
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #4
0
 public async Task Update([FromRoute] string id, [FromBody] GoalUpdateDto goalUpdateDto)
 {
     goalUpdateDto.Id = id;
     await updateGoalCommand.Execute(goalUpdateDto);
 }
Пример #5
0
        public async Task <IActionResult> UpdateGoal(int matchId, int id, [FromBody] GoalUpdateDto goalUpdateDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var match = await _matchService.GetByIdAsync(matchId);

            var player = await _playerService.GetByIdAsync(goalUpdateDto.PlayerId);

            if (match == null || player == null)
            {
                return(BadRequest());
            }

            var goal = await _goalService.GetByIdAsync(id);

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

            if (goal.MatchId != matchId)
            {
                return(BadRequest());
            }

            _mapper.Map(goalUpdateDto, goal);

            var homeClubSquad = await _squadService
                                .GetDetailBySeasonIdAndClubIdAsync(match.SeasonId, match.HomeClubId);

            var awayClubSquad = await _squadService
                                .GetDetailBySeasonIdAndClubIdAsync(match.SeasonId, match.AwayClubId);

            bool isHomePlayer;

            if (player.SquadPlayers.Any(sp => sp.SquadId == homeClubSquad.Id))
            {
                isHomePlayer = true;
            }
            else if (player.SquadPlayers.Any(sp => sp.SquadId == awayClubSquad.Id))
            {
                isHomePlayer = false;
            }
            else
            {
                return(BadRequest());
            }

            if ((isHomePlayer && goalUpdateDto.ClubId != match.HomeClubId) ||
                (!isHomePlayer && goalUpdateDto.ClubId != match.AwayClubId))
            {
                goal.IsOwnGoal = true;
            }
            else
            {
                goal.IsOwnGoal = false;
            }

            await _goalService.UpdateAsync(goal);

            var updatedGoal = await _goalService.GetDetailByIdAsync(id);

            var returnGoal = _mapper.Map <GoalDetailDto>(updatedGoal);

            return(Ok(returnGoal));
        }