Пример #1
0
        public ActionResult Create(string TeamName)
        {
            if (string.IsNullOrEmpty(TeamName) || string.IsNullOrWhiteSpace(TeamName))
                return View("Create");

            var team = new Team();
            team.TeamName = TeamName;
            team.HoldID = TeamName;
            var raceFromSession = (int)Session["RaceId"];
            var race = context.Races.Where(r => r.Id == raceFromSession).FirstOrDefault();
            if (race == null)
                return RedirectToAction("Index", "Home");

            team.Race = race;
            context.Teams.Add(team);
            context.SaveChanges();
            Session["TeamId"] = team.Id;
            return RedirectToAction("ShowPostForAnswer", "Home", new { postid=Session["PostToAnswer"] });
        }
Пример #2
0
        public ActionResult AdminCreate(string TeamName)
        {
            if (string.IsNullOrEmpty(TeamName) || string.IsNullOrWhiteSpace(TeamName))
                return View("AdminCreate");

            var team = new Team();
            team.TeamName = TeamName;
            team.HoldID = TeamName;
            var raceFromSession = (int)Session["RaceId"];
            var race = context.Races.Where(r => r.Id == raceFromSession).FirstOrDefault();
            if (race == null)
                return RedirectToAction("Index", "Home");

            team.Race = race;
            context.Teams.Add(team);
            context.SaveChanges();
            Session["TeamCreated"] = "Team was created";
            return RedirectToAction("AdminCreate", "Teams");
        }
Пример #3
0
 private string CreateTeam(string sender, List<string> data)
 {
     var return_msg = "";
     var teamid = data[1];
     var teamname = data[1];
     if (!string.IsNullOrEmpty(data[2]))
         teamname = data[2];
     var race = context.Races.Find(int.Parse(data[0]));
     if (race == null)
         return "LØB IKKE FUNDET";
     var team = context.Teams.Where(t => t.HoldID.Equals(teamid) && t.Race.Id == race.Id).FirstOrDefault();
     //Delete all old entries using that number
     var old_team_members = context.TeamMembers.Where(t => t.Number == sender).ToList();
     if (old_team_members.Count > 0)
     {
         return_msg += "Gammel hold tilmeldning slettet. ";
         context.TeamMembers.RemoveRange(old_team_members);
         context.SaveChanges();
     }
     if (team == null)
     {
         team = new Team
         {
             Race = race,
             TeamName = teamname,
             HoldID = data[1]
         };
         var tm = new TeamMember
         {
             Number = sender
         };
         context.TeamMembers.Add(tm);
         context.SaveChanges();
         context.Teams.Add(team);
         context.SaveChanges();
         team.Members.Add(tm);
         context.SaveChanges();
         return_msg += "Hold oprettet og du er tilmeldt. ";
     }
     else
     {
         var tm = new TeamMember
         {
             Number = sender
         };
         context.TeamMembers.Add(tm);
         context.SaveChanges();
         team.Members.Add(tm);
         context.SaveChanges();
         return_msg += "Du er tilmeldt. ";
     }
     return return_msg;
 }