public async Task <CompetitionResponse> UpdateCompetition(Guid competitionId, CompetitionRequest request) { var existingCompetition = await _competitionRepo.GetWithInfo(competitionId); var updatedChallenge = _mappingService.UpdateChallenge(existingCompetition.Challenge, request); var updatedCompetition = _mappingService.UpdateCompetition(existingCompetition, request); _challengeRepo.Update(updatedChallenge); _competitionRepo.Update(updatedCompetition); await _competitionRepo.Save(); //userId is not required if user is admin return(new CompetitionResponse(updatedCompetition, true, Guid.NewGuid())); }
public async Task <GoalResponse> UpdateGoal(Guid userId, Guid goalId, GoalRequest request) { var existingGoal = await _goalRepo.Get(goalId); existingGoal.EnsureExists("Goal not found."); VerifyUserOwnsGoal(userId, existingGoal); var updatedChallenge = _mappingService.UpdateChallenge(existingGoal.Challenge, request); var updatedGoal = _mappingService.UpdateGoal(existingGoal, request); _challengeRepo.Update(updatedChallenge); _goalRepo.Update(updatedGoal); await _goalRepo.Save(); return(new GoalResponse(updatedGoal)); }