public GoalCreateDtoTest() { _goal = new GoalCreateDto() { Title = "Learn Vue", Description = "Learn Vue and create a project with it", Completed = false, GoalType = "yearly", UserId = 2 }; }
public ActionResult <GoalReadDto> CreateGoal(GoalCreateDto goalCreateDto) { var goalModel = _mapper.Map <Goal>(goalCreateDto); _goalRepo.CreateGoal(goalModel); _goalRepo.SaveChanges(); var goalReadDto = _mapper.Map <GoalReadDto>(goalModel); return(CreatedAtAction(nameof(GetGoalById), new { id = goalReadDto.Id }, goalReadDto)); }
public async Task Execute(GoalCreateDto goalCreateDto) { var goal = new Goal(Guid.NewGuid().ToString(), goalCreateDto.Title, goalCreateDto.Description, GoalState.Incomplete); await goalsWriteDbOperations.Create(goal); await messageBus.Publish(new GoalCreatedEventV1 { Id = goal.Id, Title = goal.Title, Description = goal.Description }); }
public async Task Create([FromBody] GoalCreateDto goalCreateDto) { await createGoalCommand.Execute(goalCreateDto); }
public async Task <IActionResult> CreateGoal(int matchId, [FromBody] GoalCreateDto goalCreateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var match = await _matchService.GetByIdAsync(matchId); var player = await _playerService.GetByIdAsync(goalCreateDto.PlayerId); if (match == null || player == null) { return(BadRequest()); } if (goalCreateDto.ClubId != match.HomeClubId && goalCreateDto.ClubId != match.AwayClubId) { return(BadRequest()); } var goalToCreate = _mapper.Map <Goal>(goalCreateDto); goalToCreate.MatchId = matchId; 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 && goalCreateDto.ClubId != match.HomeClubId) || (!isHomePlayer && goalCreateDto.ClubId != match.AwayClubId)) { goalToCreate.IsOwnGoal = true; } else { goalToCreate.IsOwnGoal = false; } await _goalService.CreateAsync(goalToCreate); var goal = await _goalService.GetDetailByIdAsync(goalToCreate.Id); var returnGoal = _mapper.Map <GoalDetailDto>(goal); return(Ok(returnGoal)); }