public IActionResult Index()
        {
            ApplicationUser     user       = QueryController.GetCurrentUserAsync(_userManager, User);
            EventIndexViewModel indexModel = new EventIndexViewModel
            {
                CreatedEvents       = QueryController.GetUserEvents(_context, user),
                ParticipatingEvents = QueryController.GetUserParticipation(_context, user)
            };

            ViewData["Message"] = "Event Dashboard";
            return(View(indexModel));
        }
        public async Task <IActionResult> Invite(ViewEventViewModel model)
        {
            Event e = QueryController.GetEventFromId(_context, model.Invite.eventID);

            if (ModelState.IsValid)
            {
                ApplicationUser user = QueryController.GetCurrentUserAsync(_userManager, User);

                await _emailSender.SendEmailAsync(model.Invite.email, "You have been invited to join this event by " + user.details.FirstName + " " + user.details.LastName, "Dear future competition participant, \n \n" + user.details.FirstName + " " + user.details.LastName +
                                                  " has invited you to join their event: " + e.Name + ". To become a part of this event please go here: http://localhost:49494/Event/ViewEvent?eventID=" + e.id);

                TempData["modal"] = "Invited email address: " + model.Invite.email + " to join this event";
                return(RedirectToLocal("/Event/ViewEvent?eventID=" + e.id));
            }
            TempData["modal"] = "Error occured whilst inviting the entered email. Please try again.";
            return(RedirectToLocal("/Event/ViewEvent?eventID=" + e.id));
        }
Beispiel #3
0
        public async Task <IActionResult> Index(UpdateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = QueryController.GetCurrentUserAsync(_userManager, User);

            if (user != null)
            {
                user.Email    = model.Email;
                user.UserName = model.Email;
                user.details  = new UserDetails
                {
                    FirstName          = model.FirstName,
                    EmergencyContactNo = model.EmergencyContactNo,
                    EmergencyContact   = model.EmergencyContact,
                    MobilePhone        = model.MobilePhone,
                    HomePhone          = model.HomePhone,
                    MiddleName         = model.MiddleName,
                    LastName           = model.LastName,
                    DateOfBirth        = model.DateOfBirth,
                    Street             = model.Street,
                    Suburb             = model.Suburb,
                    Gender             = user.details.Gender,
                    PostCode           = model.PostCode
                };
                var result = await _userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation(3, "User updated their info successfully");
                    return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.UpdatedInfoSuccess }));
                }
                AddErrors(result);
                return(View(model));
            }
            return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.Error }));
        }
Beispiel #4
0
        public async Task <IActionResult> Index(ManageMessageId?message = null)
        {
            ViewData["StatusMessage"] =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : message == ManageMessageId.UpdatedInfoSuccess ? "Your information was successfully changed."
                : "";

            var user = QueryController.GetCurrentUserAsync(_userManager, User);

            if (user == null)
            {
                return(View("Error"));
            }
            var model = new UpdateViewModel
            {
                Email              = user.Email,
                FirstName          = user.details.FirstName,
                MiddleName         = user.details.MiddleName,
                LastName           = user.details.LastName,
                DateOfBirth        = user.details.DateOfBirth,
                Street             = user.details.Street,
                Suburb             = user.details.Suburb,
                PostCode           = user.details.PostCode,
                HomePhone          = user.details.HomePhone,
                MobilePhone        = user.details.MobilePhone,
                EmergencyContact   = user.details.EmergencyContact,
                EmergencyContactNo = user.details.EmergencyContactNo
            };

            return(View(model));
        }
Beispiel #5
0
        public async Task <IActionResult> SetPassword(SetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = QueryController.GetCurrentUserAsync(_userManager, User);

            if (user != null)
            {
                var result = await _userManager.AddPasswordAsync(user, model.NewPassword);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.SetPasswordSuccess }));
                }
                AddErrors(result);
                return(View(model));
            }
            return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.Error }));
        }
Beispiel #6
0
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = QueryController.GetCurrentUserAsync(_userManager, User);

            if (user != null)
            {
                var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation(3, "User changed their password successfully.");
                    return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.ChangePasswordSuccess }));
                }
                AddErrors(result);
                return(View(model));
            }
            return(RedirectToAction(nameof(Index), new { Message = ManageMessageId.Error }));
        }
        public async Task <IActionResult> JoinCompetition(string eventID, string competitionID, JoinCompetitionViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"]     = returnUrl;
            ViewData["eventID"]       = eventID;
            ViewData["competitionID"] = competitionID;
            Event           evnt = QueryController.GetEventFromId(_context, eventID);
            Competition     comp = evnt.Competitions.Where(o => o.id == competitionID).First();
            ApplicationUser user = QueryController.GetCurrentUserAsync(_userManager, User);

            model.Competition = comp;
            if (ModelState.IsValid) //&& QueryController.IsUserParticipatingInCompetition(_context,user.details.id,competitionID) > 0)
            {                       //If model is valid and the user isn't already participating
                int  participants = comp.getParticipants();
                Team team         = null;
                if (model.JoinIndividual)
                {
                    if (model.TeamName == "" || model.TeamName == null)
                    {
                        model.TeamName = user.details.FirstName + " " + user.details.LastName + "'s team";
                    }
                    if (+1 <= comp.EntryCapacity)
                    { //If adding one participant is within capacity add team
                        team = new Team
                        {
                            ManagerID            = user.Id,
                            TeamName             = model.TeamName,
                            TeamMembers          = null,
                            ManagerParticipation = true
                        };
                    }
                    else
                    {
                        TempData["modal"] = "This competition is unfortunately full.";
                        return(View(model));
                    }
                }
                else if (model.TeamMembers != null)
                {
                    int teamSize = model.TeamMembers.Length + (model.ManagerParticipation ? 1 : 0);

                    //Firstly check if Team Size is between the competitions Min and Max team sizes otherwise let user know
                    if (teamSize >= model.Competition.TeamSizeMin && teamSize <= model.Competition.TeamSizeMax)
                    {
                        if (model.TeamName == "" || model.TeamName == null)
                        {
                            model.TeamName = user.details.FirstName + " " + user.details.LastName + "'s team";
                        }
                        if (model.ManagerParticipation)
                        {     //Manager competing
                            if (participants + model.TeamMembers.Length + 1 <= comp.EntryCapacity)
                            { //Competition not full
                                List <TeamMember> members = new List <TeamMember>();
                                foreach (String s in model.TeamMembers)
                                {
                                    members.Add(new TeamMember {
                                        MemberName = s
                                    });
                                }

                                team = new Team
                                {
                                    ManagerID            = user.Id,
                                    TeamName             = model.TeamName,
                                    TeamMembers          = members,
                                    ManagerParticipation = model.ManagerParticipation
                                };
                            }
                            else
                            { //Competition full
                                TempData["modal"] = "This competition only has room for " + (comp.EntryCapacity - participants) + "participants. You tried to add: " + (model.TeamMembers.Length + 1);
                                return(View(model));
                            }
                        }
                        else
                        {     //Manager not competing
                            if (participants + model.TeamMembers.Length + 1 <= comp.EntryCapacity)
                            { //Competition not full
                                List <TeamMember> members = new List <TeamMember>();
                                foreach (String s in model.TeamMembers)
                                {
                                    members.Add(new TeamMember {
                                        MemberName = s
                                    });
                                }

                                team = new Team
                                {
                                    ManagerID            = user.Id,
                                    TeamName             = model.TeamName,
                                    TeamMembers          = members,
                                    ManagerParticipation = model.ManagerParticipation
                                };
                            }
                            else
                            { //Competition full
                                TempData["modal"] = "This competition only has room for " + (comp.EntryCapacity - participants) + "participants.You tried to add: " + model.TeamMembers.Length;
                                return(View(model));
                            }
                        }
                        //team will never be null here but check anyway
                        if (team != null)
                        {
                            comp.Teams.Add(team);
                            await _context.SaveChangesAsync();

                            TempData["modal"] = "Successfully joined competition.";
                        }
                        else
                        {
                            TempData["modal"] = "Unknown error occured please try again.";
                        }

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("TeamMembers", "Invalid amount of team members added. Please review competition min and max team sizes");
                        return(View(model));
                    }
                }
                if (team != null)
                {
                    comp.Teams.Add(team);
                    await _context.SaveChangesAsync();

                    TempData["modal"] = "Successfully joined competition.";
                }
                else
                { //They entered no team members
                    ModelState.AddModelError("TeamMembers", "Invalid amount of team members added. Please review competition min and max team sizes");
                    return(View(model));
                }

                return(RedirectToLocal(returnUrl));
            }
            else
            {
                return(View(model));
            }
        }
        public async Task <IActionResult> EditEvent(CreateEventViewModel model, string eventID, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                List <Competition> competitions = new List <Competition>();
                if (model.Competitions != null)
                {
                    foreach (CompetitionValidationModel c in model.Competitions)
                    {
                        Sport sportType = new Sport
                        {
                            Name        = c.SportName,
                            Description = c.SportDescription
                        };

                        Division div = new Division
                        {
                            DivisionName        = c.DivisionName,
                            DivisionDescription = c.DivisionDescription
                        };

                        Competition comp = new Competition
                        {
                            Name              = c.CompName,
                            DivisionType      = div,
                            SportType         = sportType,
                            Location          = c.Location,
                            StartTime         = c.CompStartTime,
                            EndTime           = c.CompEndTime,
                            EntryCapacity     = c.EntryCapacity,
                            TeamSizeMin       = c.TeamSizeMin,
                            TeamSizeMax       = c.TeamSizeMax,
                            MinimumAge        = c.MinimumAge,
                            MaximumAge        = c.MaximumAge,
                            GenderRestriction = c.GenderRestriction
                        };
                        competitions.Add(comp);
                    }
                }

                var e = QueryController.GetEventFromId(_context, eventID);
                e.Name          = model.Name;
                e.VenueName     = model.VenueName;
                e.Description   = model.Description;
                e.StreetAddress = model.StreetAddress;
                e.Suburb        = model.Suburb;
                e.PostCode      = model.PostCode;
                e.StartTime     = model.StartTime;
                e.EndTime       = model.EndTime;
                e.RegStartTime  = model.RegStartTime;
                e.RegEndTime    = model.RegEndTime;
                e.OrganiserName = model.OrganiserName;
                e.OrganiserClub = model.OrganiserClub;
                e.IsPrivate     = model.IsPrivate;
                e.ownerID       = QueryController.GetCurrentUserAsync(_userManager, User).Id;
                e.Competitions  = competitions;

                _context.Events.Update(e);
                await _context.SaveChangesAsync();

                //Loop over each competition, notify the participating users that the events changed and remove them from the event.
                foreach (Competition c in e.Competitions)
                {
                    if (c.Teams != null)
                    {
                        foreach (Team t in c.Teams)
                        {
                            ApplicationUser manager = QueryController.GetUserFromUserID(_userManager, t.ManagerID);
                            await _emailSender.SendEmailAsync(manager.Email, "Event details changed notice!", "Dear, " + manager.details.FirstName + " " + manager.details.LastName +
                                                              ", \n this email is to notify you that the event you are participating in has had a change of details." +
                                                              " Please review the changed details and decide if you wish to stay participating: http://localhost:49494/Event/JoinCompetition?eventID=" + e.id + "&competitionID=" + c.id);
                        }
                    }
                }
                TempData["modal"] = "Successfully modified event details. Participants have been emailed and asked to confirm if they wish to stay participating.";
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                // If we got this far, something failed, redisplay form
                return(View(model));
            }
        }
        public async Task <IActionResult> CreateEvent(CreateEventViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                List <Competition> competitions = new List <Competition>();
                if (model.Competitions != null)
                {
                    foreach (CompetitionValidationModel c in model.Competitions)
                    {
                        Sport sportType = new Sport
                        {
                            Name        = c.SportName,
                            Description = c.SportDescription
                        };

                        Division div = new Division
                        {
                            DivisionName        = c.DivisionName,
                            DivisionDescription = c.DivisionDescription
                        };

                        Competition comp = new Competition
                        {
                            Name              = c.CompName,
                            DivisionType      = div,
                            SportType         = sportType,
                            Location          = c.Location,
                            StartTime         = c.CompStartTime,
                            EndTime           = c.CompEndTime,
                            EntryCapacity     = c.EntryCapacity,
                            TeamSizeMin       = c.TeamSizeMin,
                            TeamSizeMax       = c.TeamSizeMax,
                            MinimumAge        = c.MinimumAge,
                            MaximumAge        = c.MaximumAge,
                            GenderRestriction = c.GenderRestriction
                        };
                        competitions.Add(comp);
                    }
                }

                var e = new Event
                {
                    Name          = model.Name,
                    VenueName     = model.VenueName,
                    Description   = model.Description,
                    StreetAddress = model.StreetAddress,
                    Suburb        = model.Suburb,
                    PostCode      = model.PostCode,
                    StartTime     = model.StartTime,
                    EndTime       = model.EndTime,
                    RegStartTime  = model.RegStartTime,
                    RegEndTime    = model.RegEndTime,
                    OrganiserName = model.OrganiserName,
                    OrganiserClub = model.OrganiserClub,
                    IsPrivate     = model.IsPrivate,
                    ownerID       = QueryController.GetCurrentUserAsync(_userManager, User).Id,
                    Competitions  = competitions
                };

                _context.Events.Add(e);
                await _context.SaveChangesAsync();

                TempData["modal"] = "Successfully created event.";
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                // If we got this far, something failed, redisplay form
                return(View(model));
            }
        }