public Response UpdatePlayerProfile(PlayerRequest request) { var validationResult = validator.Validate(request); if (!validationResult.IsValid) { return(Response.CreateResponse(validationResult.Messages)); } if (request.PlayerId.IsEmpty()) { return(Response.CreateResponse(new ArgumentNullException("PlayerId cannot be null"))); } var player = memberQuery.GetPlayer(request.PlayerId.Value); if (player == null || player.SquadId != request.SquadId) { return(Response.CreateResponse(new EntityNotFoundException("The specified player does not exist"))); } player = MapPlayer(request); try { playerRepository.UpdatePlayer(player); return(Response.CreateSuccessResponse()); } catch (Exception ex) { return(Response.CreateResponse(ex)); } }
public IActionResult Edit(string squadId, string playerId) { var player = playerQuery.GetPlayer(System.Guid.Parse(playerId)); if (player == null) { return(View("PlayerNotFound", squadId)); } var squad = squadQuery.GetSquad(player.SquadId); var model = new PlayerViewModel { DateOfBirth = player.DateOfBirth, DominantFoot = player.DominantFoot.ToString(), Email = player.Email, FirstName = player.FirstName, LastName = player.LastName, Nationality = player.Nationality, SquadNumber = player.SquadNumber, SquadId = player.SquadId, PlayerId = player.Guid, SquadName = squad.Name }; return(View("Edit", model)); }
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, MembershipRequirement requirement) { if (context.Resource is AuthorizationFilterContext mvcContext) { // Examine MVC-specific things like routing data. if (mvcContext.RouteData.Values.ContainsKey("memberid")) { string memberid = mvcContext.RouteData.Values["memberid"] as string; if (!requirement.Membership.IsEmpty()) { if (requirement.Membership.Equals("Player")) { var member = memberQuery.GetPlayer(Guid.Parse(memberid)); if (member != null) { context.Succeed(requirement); } } else if (requirement.Membership.Equals("Coach")) { var member = memberQuery.GetCoach(Guid.Parse(memberid)); if (member != null) { context.Succeed(requirement); } } } } } return(Task.CompletedTask); }
private Member GetPlayer(Guid memberId) { //var email = User.Identity.Name; //var members = memberQuery.GetMembersByEmail(club.Guid, email); //return members?.FirstOrDefault(m => m.Membership == Membership.Player); var member = memberQuery.GetPlayer(memberId); return(member); }
public Response UpdateEventAttendance(EventAttendanceRequest request) { var validationResult = eventAttendanceRequestValidator.Validate(request); if (!validationResult.IsValid) { return(Response.CreateResponse(validationResult.Messages)); } var club = clubQuery.GetClub(request.ClubId); if (club == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist"))); } var squad = squadQuery.GetSquad(request.SquadId); if (squad == null || squad.ClubId != club.Guid) { return(Response.CreateResponse(new IllegalOperationException("The specified squad does not belong to this club"))); } var @event = eventQuery.GetEvent(request.EventId); if (@event == null || [email protected](s => s.Guid == squad.Guid)) { return(Response.CreateResponse(new IllegalOperationException("The specified squad is not bound to this event"))); } var player = memberQuery.GetPlayer(request.PlayerId); if (player == null || player.SquadId != squad.Guid) { return(Response.CreateResponse(new IllegalOperationException("The specified player does not belong this squad"))); } try { eventRepository.UpdateAttendance(request.SquadId, request.EventId, request.PlayerId, request.Attendance); } catch (Exception ex) { return(Response.CreateResponse(ex)); } return(Response.CreateSuccessResponse()); }
public Response AddAvailability(NewAvailabilityRequest request) { var validationResult = newAvailabilityValidator.Validate(request); if (!validationResult.IsValid) { return(Response.CreateResponse(validationResult.Messages)); } var club = clubQuery.GetClub(request.ClubId); if (club == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist"))); } var player = memberQuery.GetPlayer(request.PlayerId); if (player == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified player does not exist"))); } var squad = squadQuery.GetSquad(player.SquadId); if (squad == null || squad.ClubId != club.Guid) { return(Response.CreateResponse(new IllegalOperationException("The specified player does not belong to this club"))); } try { repository.AddAvailability(request); return(Response.CreateSuccessResponse()); } catch (Exception ex) { return(Response.CreateResponse(ex)); } }
private Response CheckReportCardRequestIntegrity(Guid clubId, Guid squadId, Guid termId, Guid playerId) { var club = clubQuery.GetClub(clubId); if (club == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified club does not exist"))); } var squad = squadQuery.GetSquad(squadId); if (squad == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified squad does not exist"))); } else if (club.Guid != squad.ClubId) { return(Response.CreateResponse(new IllegalOperationException("The specified squad does not belong to this club"))); } var term = evaluationQuery.GetTerm(termId); if (term == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified term does not exist"))); } else if (term.ClubId != club.Guid) { return(Response.CreateResponse(new IllegalOperationException("The specified term does not belong to this club"))); } else if (term.TermStatus == TermStatus.Closed) { return(Response.CreateResponse(new IllegalOperationException("Report cards cannot be generated for closed terms"))); } var player = memberQuery.GetPlayer(playerId); if (player == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified player does not exist"))); } else if (player.SquadId != squad.Guid) { return(Response.CreateResponse(new IllegalOperationException("The specified player does not belong to this squad"))); } return(Response.CreateSuccessResponse()); }
private List <SelectListItem> GetSquadList(Guid memberId) { var squads = squadQuery.GetSquads(club.Guid); if (!memberId.IsEmpty()) { var player = memberQuery.GetPlayer(memberId); squads = squadQuery.GetMemberSquads(memberId, Membership.Player); } var squadList = squads.Select(s => new SelectListItem { Text = $"{s.Name}", Value = s.Guid.ToString() }) .OrderBy(s => s.Text) .ToList(); return(squadList); }
public Response Track(EventTrainingMaterialViewRequest request) { var validationResult = eventTrainingMaterialViewValidator.Validate(request); if (!validationResult.IsValid) { return(Response.CreateResponse(validationResult.Messages)); } var club = clubQuery.GetClub(request.ClubId); if (club == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified club doesn not exist"))); } var @event = eventQuery.GetEvent(request.EventId); if (@event == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified event was not found"))); } else if (@event.ClubId != request.ClubId) { return(Response.CreateResponse(new IllegalOperationException("The specified event does not belong to this club"))); } else if ([email protected]()) { return(Response.CreateResponse(new IllegalOperationException("The specified event is not attributed to any squad"))); } var trainingMaterial = libraryQuery.GetTrainingMaterial(request.TrainingMaterialId); if (trainingMaterial == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified training material does not exist"))); } else if ([email protected](t => t.Guid == request.TrainingMaterialId)) { return(Response.CreateResponse(new IllegalOperationException("The specified training material does not belong to this event"))); } var clubSquads = squadQuery.GetSquads(request.ClubId); Member member = request.Membership == Core.Membership.Coach ? memberQuery.GetCoach(request.MemberId) as Member : memberQuery.GetPlayer(request.MemberId) as Member; var l1 = member.Squads.Intersect(clubSquads.Select(s => s.Guid)).ToList(); var l2 = clubSquads.Select(s => s.Guid).Intersect(member.Squads).ToList(); if (member == null) { return(Response.CreateResponse(new EntityNotFoundException("The specified member does not exist"))); } else if (clubSquads == null || !member.Squads.Intersect(clubSquads.Select(s => s.Guid)).Any()) { return(Response.CreateResponse(new IllegalOperationException("The specified member does not belong to any squad"))); } else if ([email protected](s => s.Guid).Intersect(member.Squads).Any()) { return(Response.CreateResponse(new IllegalOperationException("This member is not concerned by this event"))); } try { trackerRepository.Track(request); return(Response.CreateSuccessResponse()); } catch (Exception ex) { return(Response.CreateResponse(ex)); } }