示例#1
0
        /// <summary>
        /// Adds a team to the database with the given name and the current logged 
        /// in user as the coach.
        /// </summary>
        /// <returns>Success of the addition.</returns>
        public ActionResult AJAX_AddTeam(string teamName)
        {
            // Make sure the user is authenticated
            string result = "Request not authenticated.";
            if (Request.IsAuthenticated) {

                if (teamName != null && !teamName.Equals("")) {

                    // Get the person id for the user currently logged in
                    DBAccessor dba = new DBAccessor();
                    long coachID = dba.GetPersonID(User.Identity.Name);

                    // Add the team to the database
                    result = "Error adding the team.";
                    Team newTeam = new Team();
                    newTeam.name = teamName;
                    if (dba.AddNewTeam(newTeam, coachID)) {
                        result = teamName + " successfully added.";
                    }
                }
                else {
                    result = "Please enter a name for the new team.";
                }
            }

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