Beispiel #1
0
 public IActionResult RegisterMember(ClubMember club)
 {
     if (ModelState.IsValid)
     {
         _memberRepo.RegisterMember(club);
         _memberRepo.SaveMember();
         return(Ok(club.MemberId));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Beispiel #2
0
        public async Task <IActionResult> RegisterMember([FromQuery] int athleteId, [FromQuery] int clubId, [FromQuery] string dateJoined)
        {
            var existingMember = new ListModelResponse <ClubMember>()
                                 as IListModelResponse <ClubMember>;
            var response = new SingleModelResponse <ClubMember>()
                           as ISingleModelResponse <ClubMember>;

            try
            {
                if (athleteId < 1)
                {
                    throw new Exception("Athlete ID is missing");
                }
                existingMember.Model = await Task.Run(() =>
                {
                    return(_context.AthletClubs(athleteId));
                });

                //check if member is part of club
                if (existingMember.Model != null)
                {
                    foreach (ClubMember member in existingMember.Model)
                    {
                        if (member.Status == ClubStatus.Joined)
                        {
                            throw new Exception("Athlete is already part of a club");
                        }
                    }
                }
                response.Model = await Task.Run(() =>
                {
                    ClubMember clb = _context.RegisterMember(athleteId, clubId, dateJoined);
                    return(clb);
                });
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }
            return(response.ToHttpResponse());
        }