public ActionResult Index() { // create their team AspNetUser currentUser = ORM.AspNetUsers.SingleOrDefault(u => u.Email == User.Identity.Name); if (currentUser != null) { Team currentUserTeam = CSharpDbDAL.GetTeam(currentUser.Id); if (currentUserTeam == null) { currentUserTeam = new Team() { Name = $"Team {currentUser.Email.Split('@')[0]}", OwnerId = currentUser.Id, Location = "Earth" }; if (!CSharpDbDAL.AddTeam(currentUserTeam)) { Console.WriteLine("Failed to add team"); } } } return(View()); }
public ActionResult AddTeam(Team team) { team.Draw = team.Lost = team.Win = 0; if (Session["CurrentUser"] is null) { Session["CurrentUser"] = CSharpDbDAL.GetContextUser(User.Identity.Name); } AspNetUser user = (AspNetUser)Session["CurrentUser"]; team.OwnerId = user.Id; CSharpDbDAL.AddTeam(team); ViewBag.Message = $"Team {team.Name} added successfully!"; return(View()); }