Exemple #1
0
        public async Task <IHttpActionResult> RemoveCoachFromAthleteAsync(CoachAthleteIds coachAthleteIds)
        {
            if (coachAthleteIds == null)
            {
                return(InternalServerError());
            }

            var athleteProfile = await _entitiesDb.AthleteProfiles.FirstOrDefaultAsync(p => p.IdentityId == coachAthleteIds.AthleteId);

            if (athleteProfile == null)
            {
                return(InternalServerError());
            }

            var coachProfile = await _entitiesDb.CoachProfiles.FirstOrDefaultAsync(p => p.IdentityId == coachAthleteIds.CoachId);

            if (coachProfile == null)
            {
                return(InternalServerError());
            }

            var coachAthlete = await _entitiesDb.CoachAthlete.FirstOrDefaultAsync(u => u.AthlethProfileId == athleteProfile.Id && u.CoachProfileId == coachProfile.Id);

            _entitiesDb.CoachAthlete.Remove(coachAthlete);
            await _entitiesDb.SaveChangesAsync();

            return(Ok());
        }
Exemple #2
0
        public async Task <IHttpActionResult> AddCoachToAthleteAsync(CoachAthleteIds coachAthleteIds)
        {
            if (coachAthleteIds == null)
            {
                return(InternalServerError());
            }

            var athleteProfile = await _entitiesDb.AthleteProfiles.FirstOrDefaultAsync(p => p.IdentityId == coachAthleteIds.AthleteId);

            if (athleteProfile == null)
            {
                return(InternalServerError());
            }

            var coachProfile = await _entitiesDb.CoachProfiles.FirstOrDefaultAsync(p => p.IdentityId == coachAthleteIds.CoachId);

            if (coachProfile == null)
            {
                return(InternalServerError());
            }

            var coachAthlete = new CoachAthlete {
                AthlethProfileId = athleteProfile.Id,
                CoachProfileId   = coachProfile.Id
            };

            var alreadyInDb = await _entitiesDb.CoachAthlete.FirstOrDefaultAsync(u => u.AthlethProfileId == coachAthlete.AthlethProfileId && u.CoachProfileId == coachAthlete.CoachProfileId);

            if (alreadyInDb != null)
            {
                return(BadRequest("Already have this coach."));
            }

            _entitiesDb.CoachAthlete.Add(coachAthlete);
            await _entitiesDb.SaveChangesAsync();


            return(Ok());
        }