예제 #1
0
        /// <summary>
        /// Accepts the given invite to join a team. The player invited to join 
        /// the team is linked as a player of that team. The entry in the invites 
        /// table is then deleted.
        /// </summary>
        /// <param name="inviteID">The ID of the invite which was accepted.</param>
        /// <returns>The result of the accept.</returns>
        public ActionResult AJAX_AcceptInvite(long inviteID)
        {
            // Make sure the user is authenticated
            string result = "Request not authenticated.";

            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();

                // Get the invite from the database
                Invitation invite = dba.GetInvite(inviteID);

                // Get the current user's ID from the database
                long userID = dba.GetPersonID(User.Identity.Name);

                // Ensure the get invite call worked
                if (invite == null) {
                    result = "Error finding the invite in the database.";
                }
                else {
                    if (invite.invitee.Equals(User.Identity.Name)) {

                        // Link the player to the team
                        if (dba.AddPlayerToTeam(userID, invite.team.ID)) {

                            // Remove the invite entry from the database
                            if (dba.RemoveInvite(inviteID)) {
                                result = "You've been added to " + invite.team.name + " successfully.";

                                // Indicate the accept went through but the request wasn't removed
                            }
                            else {
                                result = "You've been added to " + invite.team.name + " but the invite wasn't removed.";
                            }

                            // If the link failed set an appropriate message
                        }
                        else {
                            result = "An error occured adding you to " + invite.team.name + ".";
                        }
                    }
                    else {
                        result = "Invalid attempt to accept an invite.";

                        LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.ACCEPT_INVITE, LogAction.NA);
                        entry.User = new Person("NA", "NA", User.Identity.Name, "NA");
                        entry.Message = "Attempt to accept invite (ID " + invite.ID + ").";
                        dba.LogMessage(entry);
                    }
                }
            }

            // Return the success message of the accept
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #2
0
        /// <summary>
        /// Removes the invite matching the given invite ID from the database.
        /// </summary>
        /// <param name="inviteID">The ID of the invite to remove.</param>
        /// <returns>Success message of the invite removal.</returns>
        public ActionResult AJAX_RemoveInvite(long inviteID)
        {
            // Make sure the user is authenticated
            string result = "Request not authenticated.";

            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();
                Invitation invite = dba.GetInvite(inviteID);

                if (invite.invitor.email.Equals(User.Identity.Name) || invite.invitee == User.Identity.Name) {
                    // Remove the request to the database
                    result = "Error making the request.";
                    if (dba.RemoveInvite(inviteID)) {
                        result = "Invitation removed.";
                    }
                }
                else {
                    result = "Invalid request to remove invite.";

                    LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.REMOVE_INVITE, LogAction.NA);
                    entry.User = new Person("NA", "NA", User.Identity.Name, "NA");
                    entry.Message = "Attempt to remove invite (ID " + invite.ID + ").";
                    dba.LogMessage(entry);
                }
            }

            // Return the success message of the removal
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #3
0
        /// <summary>
        /// Accepts the given request to join a team. The player that requested to 
        /// join the team is linked as a player of that team. The entry in the 
        /// request table is then deleted.
        /// </summary>
        /// <param name="requestID">The ID of the request which was accepted.</param>
        /// <returns>The result of the accept.</returns>
        public ActionResult AJAX_AcceptRequest(long requestID)
        {
            // Make sure the user is authenticated
            string result = "Request not authenticated.";

            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();

                // Get the player and team IDs from the database
                Request request = dba.GetRequest(requestID, RequestType.JOIN_TEAM);

                // Ensure the get request call worked
                if (request == null) {
                    result = "Error finding the request in the database.";

                } else {
                    Person user = new Person();
                    user.email = User.Identity.Name;
                    if (request.team.coaches.Contains(user, new PersonComparer())) {

                        // Link the player to the team
                        if (dba.AddPlayerToTeam(request.requestee.ID, request.team.ID)) {

                            // Remove the request entry from the database
                            long requesteeID = dba.GetPersonID(User.Identity.Name);
                            if (dba.RemoveRequest(requestID)) {
                                result = request.requestee.firstName + " " + request.requestee.lastName + " added to " + request.team.name + " successfully.";

                                // Indicate the accept went through but the request wasn't removed
                            }
                            else {
                                result = request.requestee.firstName + " " + request.requestee.lastName + " added to " + request.team.name + " but the request wasn't removed.";
                            }

                            // If the link failed set an appropriate message
                        }
                        else {
                            result = "Error adding " + request.requestee.firstName + " " + request.requestee.lastName + " to " + request.team.name;
                        }
                    }
                    else {
                        result = "Invalid attempt to accept request.";
                        String message = "Attempt to accept request from " + request.requestee.firstName + " " + request.requestee.lastName + " (ID " + request.requestee.ID + ") ";
                        message += "to join " + request.team.name + " (ID " + request.team.ID + ").";

                        LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.ACCEPT_REQUEST_JOIN, LogAction.NA);
                        entry.User = user;
                        entry.Message = message;
                        dba.LogMessage(entry);
                    }
                }
            }

            // Return the success message of the accept
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #4
0
        /// <summary>
        /// Sends an invite email to the given email with the given message.
        /// </summary>
        /// <param name="inviteEmail">The email of the person to invite.</param>
        /// <param name="inviteMessage">The message to send with the invitation.</param>
        /// <returns>Success of the call.</returns>
        public ActionResult AJAX_InviteUser(string inviteEmail, string inviteMessage, long teamID)
        {
            string successMessage = "Message sent to " + inviteEmail;

            // Make sure the request is authenticated
            if (Request.IsAuthenticated) {

                // Make sure the invite email is bound
                if (inviteEmail != null && !inviteEmail.Equals("")) {

                    // Validate the request
                    DBAccessor dba = new DBAccessor();
                    Person user = dba.GetPersonInformation(User.Identity.Name);
                    string name = user.firstName + " " + user.lastName;
                    Team team = dba.GetTeamDetails(teamID);

                    if (team.coaches.Contains(user, new PersonComparer())) {

                        try {
                            // Add the invite to the database
                            long inviteID = dba.AddInvite(inviteEmail, user.ID, teamID);

                            // Form an email
                            String body = "";
                            if (inviteMessage != null && !inviteMessage.Equals("")) {
                                body += "See " + name + "'s message below:\n\n" + inviteMessage + "\n\n";
                            }
                            body += "To join the " + team.name + " visit http://dugoutdigits.com/Team/Join?id=" + inviteID + "&email=" + inviteEmail + " and follow the instructions.";
                            MailMessage newMessage = new MailMessage();
                            SmtpClient mailService = new SmtpClient();

                            //set the addresses
                            newMessage.From = new MailAddress(AppConstants.EMAIL_ADMIN);
                            newMessage.To.Add(inviteEmail);

                            //set the content
                            newMessage.Subject = name + " has invited you to join the " + team.name;
                            newMessage.Body = body;

                            //send the message
                            mailService.UseDefaultCredentials = false;
                            mailService.DeliveryMethod = SmtpDeliveryMethod.Network;
                            mailService.Host = AppConstants.EMAIL_SMTP_ADDRESS;
                            mailService.Credentials = new NetworkCredential(AppConstants.EMAIL_SMTP_USERNAME, AppConstants.EMAIL_SMTP_PASSWORD);
                            mailService.Send(newMessage);
                        }
                        catch (Exception) {
                            successMessage = "Error sending email to " + inviteEmail;
                        }
                    }
                    else {
                        successMessage = "Invalid attempt to invite user.";

                        LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.INVITE_USER, LogAction.NA);
                        entry.User = user;
                        entry.Message = "Attempt to invite "+inviteEmail+" to join "+team.name+" (ID "+team.ID+").";
                        dba.LogMessage(entry);
                    }
                }
                else {
                    successMessage = "Please enter the email of the person you are trying to invite.";
                }
            }
            else {
                successMessage = "The request was not authenticated.";
            }

            // Return the success message of the addition
            return Json(
                new { message = successMessage },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #5
0
        /// <summary>
        /// Returns a list of the players tied to the team with the given team ID in the form 
        /// of an unordered list.
        /// </summary>
        /// <param name="teamID">The ID of the team in interest.</param>
        /// <returns>An unordered list of the players on the team.</returns>
        public ActionResult AJAX_GetTeamMembers(long teamID)
        {
            string result = "Request is not authenticated.";
            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();
                Team team = dba.GetTeamDetails(teamID);
                Person user = new Person();
                user.email = User.Identity.Name;

                if (team.coaches.Contains(user, new PersonComparer()) || team.players.Contains(user, new PersonComparer())) {
                    result = "<ul>";
                    foreach (Person player in team.players) {
                        result += "<li>" + player.firstName + " " + player.lastName + "</li>";
                    }
                    result += "</ul>";

                }
                else {
                    result = "You must be on the team or a coach of the team to view the players.";

                    LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.GET_TEAM_MEMBERS, LogAction.NA);
                    entry.User = user;
                    entry.Message = "Attempt to view players of " + team.name + " (" + team.ID + ").";
                    dba.LogMessage(entry);
                }
            }

            // Return the success message of the removal
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #6
0
        /// <summary>
        /// Get's the seasons tied to the team with the given ID in the form of an 
        /// unordered list.
        /// </summary>
        /// <param name="teamID">The ID of the team in interest.</param>
        /// <returns>An unordered list of the seasons.</returns>
        public ActionResult AJAX_GetSeasons(long teamID)
        {
            string result = "Request is not authenticated.";
            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();
                Team team = dba.GetTeamDetails(teamID);
                Person user = new Person();
                user.email = User.Identity.Name;

                if (team.coaches.Contains(user, new PersonComparer()) || team.players.Contains(user, new PersonComparer())) {
                    List<Season> seasons = dba.GetSeasons(teamID);
                    if (seasons.Any()) {
                        result = "<ul>";
                        foreach (Season season in seasons) {
                            result += "<li>" + season.year + "</li>";
                        }
                        result += "</ul>";
                    }
                    else {
                        result = "<p>There are currently no seasons for this team.</p>";
                    }
                }
                else {
                    result = "You must be on the team or a coach of the team to view the seasons.";

                    LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.GET_SEASONS, LogAction.NA);
                    entry.User = user;
                    entry.Message = "Attempt to view seasons of " + team.name + " ("+team.ID+").";
                    dba.LogMessage(entry);
                }
            }

            // Return the success message of the removal
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #7
0
        /// <summary>
        /// Adds the given season to the team with the matching team ID.
        /// </summary>
        /// <param name="teamID">The ID of the team of interest.</param>
        /// <param name="season">The season to be added to the team of interest.</param>
        /// <returns>A message detailing the result of the addition.</returns>
        public ActionResult AJAX_AddSeason(long teamID, short season)
        {
            string result = "Request is not authenticated.";
            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();
                Team team = dba.GetTeamDetails(teamID);
                Person user = new Person();
                user.email = User.Identity.Name;

                if (team.coaches.Contains(user, new PersonComparer())) {
                    result = "Error adding season " + season + " to " + team.name + ".";
                    if (dba.AddSeason(teamID, season)) {
                        result = "Season " + season + " added to " + team.name + ".";
                    }
                } else {
                    result = "You must be a coach of the team to add a season.";

                    LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.ADD_SEASON, LogAction.NA);
                    entry.User = user;
                    entry.Message = "Attempt to add a season to "+team.name + " (" + team.ID + ").";
                    dba.LogMessage(entry);
                }
            }

            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #8
0
        /// <summary>
        /// Creates a practice object with the given information, ties it to the team with 
        /// the given team ID and saved the game to the database.
        /// </summary>
        /// <param name="teamID">The ID of the team of interest.</param>
        /// <param name="location">The location of the practice.</param>
        /// <param name="date">The date of the practice (M/D).</param>
        /// <param name="time">The time of the practice (H/MM TT).</param>
        /// <param name="seasonID">The ID of the season is is being added to.</param>
        /// <returns>A message detailing the result of the addition.</returns>
        public ActionResult AJAX_AddPractice(long teamID, string location, string date, string time, long seasonID)
        {
            string result = "Request is not authenticated.";
            if (Request.IsAuthenticated) {
                DBAccessor dba = new DBAccessor();
                Team team = dba.GetTeamDetails(teamID);
                Person user = new Person();
                user.email = User.Identity.Name;
                Season season = dba.GetSeason(seasonID);

                if (team.coaches.Contains(user, new PersonComparer())) {
                    try {
                        DateTime practiceDate = Parser.ParseDateAndTime(date, time, season.year);
                        Practice practice = new Practice();
                        practice.location = location;
                        practice.season = season;
                        practice.date = practiceDate;

                        if (dba.AddPractice(practice)) {
                            result = "Practice sucessfully added to the season.";
                        }
                        else {
                            result = "Error adding the practice to the season.";
                        }
                    }
                    catch {
                        result = "An invalid date was given.";
                    }
                }
                else {
                    result = "You must be a coach of the team to add a practice.";

                    LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.ADD_PRACTICE, LogAction.NA);
                    entry.User = user;
                    entry.Message = "Attempt to add a practice to " + team.name + " (" + team.ID + ").";
                    dba.LogMessage(entry);
                }
            }

            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #9
0
        /// <summary>
        /// Removes a team from the database with the matching teamID.
        /// </summary>
        /// <param name="teamID">The ID of the team to remove from the database.</param>
        /// <returns>A message telling if the removal was successful.</returns>
        public ActionResult AJAX_RemoveTeam(long teamID)
        {
            string result = "Request not authenticated.";

            if (Request.IsAuthenticated) {
                // Get the team that is to be removed to validate the authenticated user can remove it
                DBAccessor dba = new DBAccessor();
                Team team = dba.GetTeamDetails(teamID);
                Person user = new Person();
                user.email = User.Identity.Name;

                if (team.coaches.Contains(user, new PersonComparer())) {
                    if (dba.RemoveTeam(teamID)) {
                        result = "Team removed successfully.";
                    }
                    else {
                        result = "Error removing the team from the database.";
                    }
                }
                else {
                    result = "Invalid attempt to remove team.";

                    LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.REMOVE_TEAM, LogAction.NA);
                    entry.User = user;
                    entry.Message = "Attempt to remove the team " + team.name + "(ID: " + team.ID + ").";
                    dba.LogMessage(entry);
                }
            }

            // Return the success message of the addition
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }
예제 #10
0
        /// <summary>
        /// Removes a request entry from the database.
        /// </summary>
        /// <param name="requestID">The ID of the request entry to remove.</param>
        /// <returns>Success message of the request removal.</returns>
        public ActionResult AJAX_RemoveRequest(long requestID)
        {
            // Make sure the user is authenticated
            string result = "Request not authenticated.";

            if (Request.IsAuthenticated) {
                // Get the person id for the user currently logged in
                DBAccessor dba = new DBAccessor();
                Person requestee = dba.GetPersonInformation(User.Identity.Name);

                // Get the request that's trying to be removed
                Request request = dba.GetRequest(requestID, RequestType.JOIN_TEAM);

                if (request.requestee.email == requestee.email || request.team.coaches.Contains(requestee, new PersonComparer())) {
                    // Remove the request to the database
                    result = "Error making the request.";
                    if (dba.RemoveRequest(requestID)) {
                        result = "Request removed.";
                    }
                } else {
                    result = "Invalid attempt to remove request.";
                    String message = "Attempt to remove request from " + request.requestee.firstName + " " + request.requestee.lastName + " (ID " + request.requestee.ID + ") ";
                    message += "to join " + request.team.name + " (ID " + request.team.ID + ").";

                    LogEntry entry = new LogEntry(LogType.INVALID_REQUEST, LogFunction.REMOVE_REQUEST_JOIN, LogAction.NA);
                    entry.User = requestee;
                    entry.Message = message;
                    dba.LogMessage(entry);
                }
            }

            // Return the success message of the removal
            return Json(
                new { message = result },
                JsonRequestBehavior.AllowGet
            );
        }