Exemplo n.º 1
0
        public Response DeleteCoach(DeleteCoachRequest request)
        {
            var coach = memberQuery.GetCoach(request.CoachId);

            if (coach == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified coach does not exist")));
            }

            if (coach.ClubId != request.ClubId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified coach does not belong to this club")));
            }

            try {
                coachRepository.DeleteCoach(coach);
                var members = memberQuery.GetMembersByEmail(request.ClubId, coach.Email);
                if (members.Count() == 0)
                {
                    var result = identityManager.RemoveUser(coach.Email).Result;
                }
                else if (!members.Any(m => m.Membership == Membership.Coach))
                {
                    var result = identityManager.RemoveUserRole(coach.Email, Membership.Coach).Result;
                }

                return(Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
        }
Exemplo n.º 2
0
        public ActionResult NewReview(Guid eventId)
        {
            var @event = eventsQuery.GetEvent(eventId);
            var squadsNotYetReviewed = GetNotYetReviewedSquads(@event);

            if (squadsNotYetReviewed?.Count() == 0)
            {
                return(RedirectToAction(nameof(Reviews)));
            }

            var email   = User.Identity.Name;
            var members = memberQuery.GetMembersByEmail(club.Guid, email);
            var coach   = members?.FirstOrDefault(m => m.Membership == Membership.Coach);

            if (coach == null || coach.Guid.IsEmpty())
            {
                TempData[Temp_Data_Error] = "This user has not been setup as a coach. To submit reviews, add this user as a coach";
                return(RedirectToAction(nameof(Reviews)));
            }


            var model = new NewEventReviewViewModel
            {
                EventTitle           = @event.Title,
                EventDetails         = $"{@event.EventType.GetDescription()}<br/>{@event.StartDate.ToString("ddd dd-MMM-yyyy h:mm tt")}<br/>{@event.Location}<br/>{string.Join(", ", @event.Squads.Select(s => s.Name))}",
                SquadsNotYetReviewed = squadsNotYetReviewed,
                MemberId             = coach.Guid
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public IActionResult PublishFeedback(FeedbackPublishModel model)
        {
            var email   = User.Identity.Name;
            var members = memberQuery.GetMembersByEmail(club.Guid, email);
            var coach   = members?.FirstOrDefault(m => m.Membership == Membership.Coach);

            if (coach == null)
            {
                return(BadRequest("Only a registered coach can provide feedback"));
            }
            else if (model.Comments.IsEmpty())
            {
                return(BadRequest("Comments cannot be empty"));
            }

            var response = feedbackRepository.PublishFeedback(
                new FeedbackPublishRequest {
                ClubId   = club.Guid,
                PlayerId = model.PlayerId,
                Week     = model.Week,
                Year     = model.Year,
                Comments = model.Comments ?? "No feedback to provide",
                CoachId  = coach.Guid
            }
                );

            return(new JsonResult(response));
        }
Exemplo n.º 4
0
        private Member GetCoach()
        {
            var email   = User.Identity.Name;
            var members = memberQuery.GetMembersByEmail(club.Guid, email);

            return(members?.FirstOrDefault(m => m.Membership == Membership.Coach));
        }
Exemplo n.º 5
0
        public Response SendInvitation(AccountRequest request)
        {
            var validationResult = accountRequestValidator.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")));
            }

            IEnumerable <Member> members = memberQuery.GetMembersByEmail(club.Guid, request.Email);

            if (!members.Any())
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified member (email) does not exist in the specified club")));
            }

            var invite = new Invitation {
                ClubId = club.Guid,
                Email  = request.Email,
                Expiry = DateTime.Now.AddDays(10)
            };

            try {
                var    token   = Protect(invite, cryptographicSettings.RegistrationPurposeKey);
                string message = "<html><body><p>Dear Member,</p>" +
                                 "<p>You're invited to join Mapola Online - a platform that Mapola FC uses to manage team's activity, sessions, games and track player performance.</p>" +
                                 "<p>Please click on the link below to register.</p>" +
                                 $"<p><a href='{club.Url}/accounts/register?token={token}' target='_blank'>Register Now</a></p><p>Thank you</p><p>Mapola Admin</p></body></html>";

                var emailRequest = new EmailRequest {
                    Subject = "Invitation To Use Mapola Online",
                    Body    = message
                };
                emailRequest.AddEmailAddress(request.Email, Recipient.To);
                Task.Run(() => emailSender.EmailAsync(emailRequest));
                return(Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
        }
Exemplo n.º 6
0
        public IActionResult New(AssignmentDetailsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PromptForSubmission(model));
            }
            else if (model.AssignedTo == AssignedTo.IndividualPlayers && (model.Players == null || model.Players.Count() == 0))
            {
                ModelState.AddModelError("", "Please specify which players this is assigned to");
                return(PromptForSubmission(model));
            }
            else if (model.AssignedTo == AssignedTo.SelectedSquads && (model.Squads == null || model.Squads.Count() == 0))
            {
                ModelState.AddModelError("", "Please specify which squads this is assigned to");
                return(PromptForSubmission(model));
            }

            var email   = User.Identity.Name;
            var members = memberQuery.GetMembersByEmail(club.Guid, email);
            var coach   = members?.FirstOrDefault(m => m.Membership == Membership.Coach);

            if (coach == null)
            {
                ModelState.AddModelError("", "Coach could not be resolved");
                PromptForSubmission(model);
            }

            var response = assignmentService.CreateAssignment(new AssignmentRequest {
                Title             = model.Title,
                ClubId            = club.Guid,
                CoachId           = coach.Guid,
                DueDate           = model.DueDate,
                Instructions      = model.Instructions,
                Players           = model.AssignedTo == AssignedTo.IndividualPlayers ? model.Players : null,
                Squads            = model.AssignedTo == AssignedTo.SelectedSquads ? model.Squads : null,
                TrainingMaterials = model.TrainingMaterials,
                AssignedTo        = model.AssignedTo.Value
            });

            if (!response.RequestIsFulfilled)
            {
                foreach (var error in response.Errors)
                {
                    ModelState.AddModelError("", error);
                }

                PromptForSubmission(model);
                return(View("Create", model));
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 7
0
        public async Task <IdentityOperationResult> SetupUser(Credential credential)
        {
            var roles   = memberQuery.GetMembersByEmail(club.Guid, credential.Email).Select(m => m.Membership).Distinct();
            var newUser = new ApplicationUser {
                UserName = credential.Email, Email = credential.Email
            };

            try {
                var result = await userManager.CreateAsync(newUser, credential.Password);

                if (result.Succeeded)
                {
                    foreach (var role in roles)
                    {
                        var roleResult = await userManager.AddToRoleAsync(newUser, role.ToString().ToLowerInvariant());

                        if (!roleResult.Succeeded)
                        {
                            var operationResult = new IdentityOperationResult(false);
                            foreach (var e in result.Errors)
                            {
                                operationResult.AddError(e.Description);
                            }

                            return(operationResult);
                        }
                    }
                    return(new IdentityOperationResult(true));
                }
                else
                {
                    var operationResult = new IdentityOperationResult(false);
                    foreach (var e in result.Errors)
                    {
                        operationResult.AddError(e.Description);
                    }

                    return(operationResult);
                }
            }catch (Exception ex) {
                var operationResult = new IdentityOperationResult(false);
                operationResult.AddError(ex.Message);
                return(operationResult);
            }
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Index()
        {
            var  user    = userManager.GetUserAsync(User).Result;
            bool isAdmin = await userManager.IsInRoleAsync(user, "Administrator");

            var members = memberQuery.GetMembersByEmail(club.Guid, user.Email);

            if (isAdmin)
            {
                return(RedirectToAction("Index", "Home", new { Area = "Administration" }));
            }
            else if (!members.Any())
            {
                ModelState.AddModelError("", "Invalid login");
                await signInManager.SignOutAsync();

                return(RedirectToActionPreserveMethod("Login", "Accounts"));
            }
            else if (members.Count() > 1)
            {
                return(View(members));
            }
            else if (members.Any(m => m.Membership == Membership.Coach))
            {
                bool isCoach = await userManager.IsInRoleAsync(user, "Coach");

                if (isCoach)
                {
                    return(RedirectToAction("Index", "Home", new { Area = "Coaches", memberid = members.FirstOrDefault().Guid }));
                }
            }
            else if (members.Any(m => m.Membership == Membership.Player))
            {
                return(RedirectToAction("Index", "Home", new { Area = "Players", memberid = members.FirstOrDefault().Guid }));
            }

            return(RedirectToAction("Lockout", "Accounts"));
        }
Exemplo n.º 9
0
        public Response DeletePlayer(DeletePlayerRequest request)
        {
            var player = memberQuery.GetPlayer(request.PlayerId);

            if (player == null || player.SquadId != request.SquadId)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified player does not exist")));
            }

            var squad = squadQuery.GetSquad(request.SquadId);

            if (squad == null)
            {
                return(Response.CreateResponse(new EntityNotFoundException("The specified squad does not exist")));
            }
            else if (squad.ClubId != request.ClubId)
            {
                return(Response.CreateResponse(new IllegalOperationException("The specified squad does not belong to this club")));
            }

            try {
                playerRepository.DeletePlayer(player);
                var members = memberQuery.GetMembersByEmail(request.ClubId, player.Email);
                if (members.Count() == 0)
                {
                    var result = identityManager.RemoveUser(player.Email).Result;
                }
                else if (!members.Any(m => m.Membership == Membership.Player))
                {
                    var result = identityManager.RemoveUserRole(player.Email, Membership.Player).Result;
                }

                return(Response.CreateSuccessResponse());
            } catch (Exception ex) {
                return(Response.CreateResponse(ex));
            }
        }
Exemplo n.º 10
0
        public IActionResult AddPlayer(Guid assignmentId, Guid playerId)
        {
            var email   = User.Identity.Name;
            var members = memberQuery.GetMembersByEmail(club.Guid, email);
            var coach   = members?.FirstOrDefault(m => m.Membership == Membership.Coach);

            if (coach == null)
            {
                ModelState.AddModelError("", "Coach could not be resolved");
                return(BadRequest(ModelState));
            }

            if (playerId.IsEmpty() || assignmentId.IsEmpty())
            {
                ModelState.AddModelError("", "AssignmentId and PlayerId are required");
                return(BadRequest(ModelState));
            }

            var response = assignmentService.AddPlayerToAssignment(new PlayerAssignmentRequest {
                AssignmentId = assignmentId,
                ClubId       = club.Guid,
                CoachId      = coach.Guid,
                PlayerId     = playerId
            });

            if (response.Errors.Any())
            {
                foreach (var error in response.Errors)
                {
                    ModelState.AddModelError("", error);
                }
                return(BadRequest(ModelState));
            }

            return(Ok());
        }