public async Task <ActionResult> JoinTeam(GuardianModel model)
        {
            try
            {
                string BNETId   = model.DisplayName.Replace("#", "%23");
                long   memberId = 0;
                if (ModelState.IsValid)
                {
                    Bungie.Responses.SearchPlayersResponse member = await service.SearchPlayers(MembershipType.Blizzard, BNETId);

                    memberId = member[0].MembershipId;
                }
                using (var context = new CoCodbEntities1())
                {
                    var g = new GuardianModel
                    {
                        MembershipId   = memberId.ToString(),
                        DisplayName    = BNETId,
                        MembershipType = 4,
                        TeamID         = model.TeamModel.Id
                    };
                    if (_db.GuardianModels.Any(guardian => guardian.MembershipId == g.MembershipId))
                    {
                        TempData["UserMessage"] = new MessageVM()
                        {
                            ClassName = "alert-error", Title = "Error!", Message = "This Guardian has already been registered. Please sign up with a different Battle Net ID."
                        };
                        return(RedirectToAction("Error"));
                    }
                    else
                    {
                        context.GuardianModels.Add(g);
                        context.SaveChanges();
                        TempData["UserMessage"] = TempData["UserMessage"] = new MessageVM()
                        {
                            ClassName = "alert-success", Title = "Success!", Message = "Joined the Team Successfully."
                        };
                        return(RedirectToAction("Success"));
                    }
                }
            }
            catch (Exception ex)
            {
                TempData["UserMessage"] = TempData["UserMessage"] = new MessageVM()
                {
                    ClassName = "alert-error", Title = "Error!", Message = ex.Message
                };
                return(RedirectToAction("Success"));
            }
        }
        public async Task <ActionResult> CreateTeam(GuardianModel model)
        {
            try
            {
                string BNETId   = model.DisplayName.Replace("#", "%23");
                long   memberId = 0;
                if (ModelState.IsValid)
                {
                    Bungie.Responses.SearchPlayersResponse member = await service.SearchPlayers(MembershipType.Blizzard, BNETId);

                    memberId = member[0].MembershipId;
                    Bungie.Responses.GetGroupsForMemberResponse group = await groupService.GetGroupsForMember(MembershipType.Blizzard, memberId, GroupsForMemberFilter.All, GroupType.Clan);

                    using (var context = new CoCodbEntities1())
                    {
                        var t = new TeamModel
                        {
                            TeamName = model.TeamModel.TeamName,
                            ClanName = group.Results[0].Group.Name
                        };
                        var g = new GuardianModel
                        {
                            MembershipId   = memberId.ToString(),
                            DisplayName    = BNETId,
                            MembershipType = 4,
                            TeamID         = t.Id
                        };

                        if (_db.TeamModels.Any(team => team.TeamName == t.TeamName))
                        {
                            TempData["UserMessage"] = new MessageVM()
                            {
                                ClassName = "alert-error", Title = "Error!", Message = "The team name you entered has already been used. Please select another team name."
                            };
                        }
                        else
                        {
                            context.TeamModels.Add(t);
                            if (_db.GuardianModels.Any(guardian => guardian.MembershipId == g.MembershipId))
                            {
                                TempData["UserMessage"] = new MessageVM()
                                {
                                    ClassName = "alert-error", Title = "Error!", Message = "This Guardian has already been registered. Please sign up with a different Battle Net ID."
                                };
                            }
                            else
                            {
                                context.GuardianModels.Add(g);
                                context.SaveChanges();
                                TempData["UserMessage"] = new MessageVM()
                                {
                                    ClassName = "alert-success", Title = "Success!", Message = "Your Team has been saved."
                                };
                            }
                        }
                        return(RedirectToAction("Success"));
                    }
                }
            }
            catch (Exception ex)
            {
                TempData["UserMessage"] = new MessageVM()
                {
                    ClassName = "alert-error", Title = "Error!", Message = ex.Message
                };
                return(RedirectToAction("Error"));
            }


            return(View(model));
        }