public ActionResult Create(UpsertBlacklistUserViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    UserBlackList newBlacklistUser = new UserBlackList();

                    newBlacklistUser.clanUserId = model.ClanUserId;
                    newBlacklistUser.clanId     = (int)ClanManager.GetClanId(User.Identity.GetUserId());
                    newBlacklistUser.note       = model.Notes;

                    BlacklistManager.Insert(newBlacklistUser);

                    ClanUser blUser = ClanUserManager.SelectByClanUserId(model.ClanUserId);
                    blUser.clanId = null;
                    ClanUserManager.Update(blUser);
                }
            }
            catch
            {
                return(View(new UpsertBlacklistUserViewModel()));
            }

            return(RedirectToAction("EditMode", "Members"));
        }
Ejemplo n.º 2
0
        public static List <ClanWarPickViewModel> GetAllByWar(int warId)
        {
            List <ClanWarPickViewModel> clanWarPickList = new List <ClanWarPickViewModel>();
            int  warTypeId = ClanWarManager.SelectByClanWarId(warId).warTypeId;
            byte count     = WarTypeManager.Get(warTypeId).value;

            foreach (Models.ClanWarPick warPick in ClanWarPicksManager.SelectAllByWarId(warId))
            {
                clanWarPickList.Add(new ClanWarPickViewModel()
                {
                    Id                    = warPick.id,
                    ClanWarId             = warPick.clanWarId,
                    ClanMemberWarPosition = warPick.clanMemberWarPosition,
                    ClanUserId            = warPick.clanUserId,
                    PickVS                = warPick.pickVS,
                    Note                  = warPick.note,
                    UpdatedOn             = warPick.updatedOn,
                    AddedOn               = warPick.addedOn,
                    _clanUserName         = warPick.clanUserId > 0 ? ClanUserManager.SelectByClanUserId(warPick.clanUserId).name : string.Empty,
                    _basesCount           = count
                });
            }

            return(clanWarPickList);
        }
Ejemplo n.º 3
0
        public ActionResult RegisterClan(RegisterClanViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Clan newClan = new Clan();

                    newClan.name               = model.ClanName;
                    newClan.description        = model.Description;
                    newClan.shieldLogoLocation = model.Shield;

                    ClanManager.Insert(newClan);
                    ClanUser clanUser = HttpContext.GetCurrentLoginInformation();

                    if (clanUser != null)
                    {
                        clanUser.clanId     = newClan.id;
                        clanUser.userRoleId = (int)ClanRole.Leader;
                        ClanUserManager.Update(clanUser);
                    }
                    else
                    {
                        return(View(new RegisterClanViewModel()));
                    }
                }
            }
            catch
            {
                return(View(new RegisterClanViewModel()));
            }

            return(RedirectToAction("Index", "ClanInfo"));
        }
Ejemplo n.º 4
0
        //
        // GET: Delete
        // Removes a clan member
        public ActionResult Remove(int memberId)
        {
            ClanUser removeUser = ClanUserManager.SelectByClanUserId(memberId);

            removeUser.clanId = null;
            ClanUserManager.Update(removeUser);

            return(RedirectToAction("EditMode"));
        }
        public ActionResult Create(int memberId)
        {
            ClanUser blUser = ClanUserManager.SelectByClanUserId(memberId);

            UpsertBlacklistUserViewModel model = new UpsertBlacklistUserViewModel();

            model.ClanUserId = memberId;

            return(View(model));
        }
Ejemplo n.º 6
0
        public ActionResult Edit(ClanWarUpsertViewModel clanWar)
        {
            ActionResult result = View();

            try
            {
                ClanUser clanUser  = HttpContext.GetCurrentLoginInformation();
                int      clanWarId = ClanWarManager.Upsert(clanWar, clanUser.id);

                if (clanWarId > 0)
                {
                    //Insert member picks
                    //vv List<WarRanking> rankings = new List<WarRanking>();
                    List <ClanWarPickViewModel> picks       = new List <ClanWarPickViewModel>();
                    List <ClanUser>             clanMembers = ClanUserManager.SelectAllByClanId(clanWar.ClanId);
                    short i = 1;

                    foreach (ClanUser member in clanMembers)
                    {
                        WarRanking ranking = new WarRanking()
                        {
                            clanUserId = member.id,
                            clanWarId  = clanWarId
                        };

                        //vv rankings.Add(ranking);

                        ClanWarPickViewModel pick = new ClanWarPickViewModel()
                        {
                            ClanUserId            = member.id,
                            ClanMemberWarPosition = i,
                            ClanWarId             = clanWarId,
                            PickVS = i
                        };

                        picks.Add(pick);
                        i++;
                    }

                    //vv RankingsManager.Upsert(rankings);
                    ClanWarPicksManager.Upsert(picks);
                }
                //TODO //vv an Else here should display a message stating that the war was not inserted (and no exception apparently)

                result = RedirectToAction("Index");
            }
            catch
            {
                result = View(clanWar);
            }

            return(result);
        }
Ejemplo n.º 7
0
        public ActionResult AddAttack(int id, int warId)
        {
            ClanMemberStatsViewModel addSingle = new ClanMemberStatsViewModel()
            {
                ClanWarId = warId
            };

            List <ClanUser> clanUsers = ClanUserManager.SelectAllByClanId(id);

            ViewBag.AvailableAttacks = RankingsManager.SelectAttacksAvailableForWar(warId).ToDictionary(key => key.clanUserId, value => clanUsers.Where(p => p.id == value.clanUserId).Select(p => p.name).Single());

            return(PartialView("_ClanMemberStatsViewModel", addSingle));
        }
Ejemplo n.º 8
0
        public string GetName(string aspnetId)
        {
            ClanUser user = ClanUserManager.SelectByAspNetUserId(aspnetId);

            if (user != null)
            {
                return(user.name);
            }
            else
            {
                return("No Name");
            }
        }
		public static ClanUser GetCurrentLoginInformation(this HttpContextBase context)
		{
			ClanUser clanUser = new ClanUser();

			if (context.Session[_sessionMemberInfo] != null)
			{
				clanUser = context.Session[_sessionMemberInfo] as ClanUser;
			}
			else
			{
				clanUser = ClanUserManager.SelectByAspNetUserId(context.User.Identity.GetUserId());
				context.Session.Add(_sessionMemberInfo, clanUser);
			}

			return clanUser;
		}
Ejemplo n.º 10
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.Email, Email = model.Email
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //TODO //vv I think here is where we add the system Role, and all new should be 'normal' user, we need to find a place to change this role in the near future
                    //ref: http://stackoverflow.com/questions/19689183/add-user-to-role-asp-net-identity
                    var currentUser = UserManager.FindByName(user.UserName);

                    CheckAspRoles();

                    var userRoleResult = UserManager.AddToRole(currentUser.Id, "Normal");

                    await SignInAsync(user, isPersistent : false);

                    ClanUser newClanUser = new ClanUser();

                    newClanUser.name         = model.VillageName;
                    newClanUser.userRoleId   = (short)ClanRole.Member;
                    newClanUser.aspnetUserId = currentUser.Id;

                    ClanUserManager.Insert(newClanUser);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 11
0
        //
        // GET: Promote
        // Promotes a clan member
        public ActionResult Promote(int memberId)
        {
            ClanUser promoteUser = ClanUserManager.SelectByClanUserId(memberId);

            if (promoteUser.userRoleId == (short)ClanRole.Member)
            {
                promoteUser.userRoleId = (short)ClanRole.Elder;
            }
            else if (promoteUser.userRoleId == (short)ClanRole.Elder)
            {
                promoteUser.userRoleId = (short)ClanRole.CoLeader;
            }

            ClanUserManager.Update(promoteUser);

            return(RedirectToAction("EditMode"));
        }
Ejemplo n.º 12
0
        public ActionResult Create(CreateGroupViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ClanGroup newGroup = new ClanGroup();

                    int leaderId = 0;
                    int.TryParse(model.GroupLeaderId, out leaderId);

                    newGroup.name          = model.GroupName;
                    newGroup.groupLeaderId = leaderId;
                    newGroup.clanId        = model.ClanId;

                    ClanGroupManager.Insert(newGroup);

                    ClanUser groupLeader = ClanUserManager.SelectByClanUserId(leaderId);
                    groupLeader.clanGroupId = newGroup.id;

                    ClanUserManager.Update(groupLeader);

                    if (model.GroupMemberIds != null && model.GroupMemberIds.Count > 0)
                    {
                        foreach (var memberId in model.GroupMemberIds)
                        {
                            int id = 0;
                            int.TryParse(memberId, out id);

                            ClanUser member = ClanUserManager.SelectByClanUserId(id);
                            member.clanGroupId = newGroup.id;

                            ClanUserManager.Update(member);
                        }
                    }
                }
            }
            catch
            {
                int?clanId = ClanManager.GetClanId(User.Identity.GetUserId());

                return(View(new CreateGroupViewModel((int)clanId)));
            }

            return(RedirectToAction("EditMode"));
        }
Ejemplo n.º 13
0
        //
        // GET: Accept
        // Accepts a clan member
        public ActionResult AcceptMember(int reqId, int clanId)
        {
            Request req = RequestManager.SelectById(reqId);

            req.accepted  = true;
            req.processed = true;

            RequestManager.Update(req);

            ClanUser user = ClanUserManager.SelectByAspNetUserId(req.aspnetUserId);

            user.clanId     = clanId;
            user.userRoleId = (int)ClanRole.Member;

            ClanUserManager.Update(user);

            return(RedirectToAction("EditMode"));
        }
Ejemplo n.º 14
0
        public ActionResult Create(CreateMemberViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ClanUser newMember = new ClanUser();

                    newMember.name       = model.Name;
                    newMember.userRoleId = (short)ClanRole.Member;
                    newMember.clanId     = ClanManager.GetClanId(User.Identity.GetUserId());

                    ClanUserManager.Insert(newMember);
                }
            }
            catch
            {
                return(View(new CreateMemberViewModel()));
            }

            return(RedirectToAction("EditMode"));
        }
Ejemplo n.º 15
0
        public ActionResult Move(MoveMemberViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int newGroupId = 0;
                    int.TryParse(model.NewGroupId, out newGroupId);

                    ClanUser moveMember = ClanUserManager.SelectByClanUserId(model.MoveMemberId);
                    moveMember.clanGroupId = newGroupId;

                    ClanUserManager.Update(moveMember);
                }
            }
            catch
            {
                return(View());
            }

            return(RedirectToAction("EditMode"));
        }
        public RankingsUpsertViewModel(int warId, int clanId, bool isOverall)
        {
            _clanMemberStats = new List <ClanMemberStatsViewModel>();
            List <WarRanking> warRankings = new List <WarRanking>();

            if (isOverall)
            {
                warRankings = RankingsManager.SelectRankingsByClanId(clanId);

                if (warRankings.Any() && warRankings.Count > 0)
                {
                    var rankingTotals = warRankings.GroupBy(g => g.clanUserId).Select(p => new ClanMemberStatsViewModel
                    {
                        ClanUserId         = p.Key,
                        ClanId             = clanId,
                        TotalAttacks       = (short)p.Count(),
                        AttacksWon         = (short)p.Count(r => r.attackWin),
                        TotalHeroicDefense = (short)p.Sum(r => Convert.ToInt16(r.heroicDefense)),
                        TotalHeroicAttack  = (short)p.Sum(r => Convert.ToInt16(r.heroicAttack)),
                        AttacksDefended    = (short)p.Sum(r => r.attacksDefended),
                        AttacksOn          = (short)p.Sum(r => r.attacksOn),
                        Stars = (short)p.Sum(r => r.stars),
                        Xp    = (short)p.Sum(r => r.xp)
                    });

                    _clanMemberStats = rankingTotals.ToList();

                    foreach (ClanMemberStatsViewModel memberStats in _clanMemberStats)
                    {
                        short wars = 0;

                        wars = (short)warRankings.Where(p => p.clanUserId == memberStats.ClanUserId).Select(p => p.clanWarId).Distinct().Count();

                        memberStats.WarsCount = wars;
                    }

                    int attacksCount = warRankings.Count();

                    _clanWarStats = _clanMemberStats.GroupBy(g => g.ClanId).Select(p => new ClanMemberStatsViewModel
                    {
                        ClanId             = p.Key,
                        ClanWarId          = 0,
                        WarsCount          = (short)p.Count(),
                        TotalAttacks       = (short)attacksCount,
                        AttacksWon         = (short)p.Sum(r => r.AttacksWon),
                        TotalHeroicDefense = (short)p.Sum(r => Convert.ToInt16(r.TotalHeroicDefense)),
                        TotalHeroicAttack  = (short)p.Sum(r => Convert.ToInt16(r.TotalHeroicAttack)),
                        AttacksDefended    = (short)p.Sum(r => r.AttacksDefended),
                        AttacksOn          = (short)p.Sum(r => r.AttacksOn),
                        Stars = (short)p.Sum(r => r.Stars),
                        Xp    = (short)p.Sum(r => r.Xp)
                    }).Single();
                }
            }
            else
            {
                warRankings = RankingsManager.SelectRankingsByClanWarId(warId);

                foreach (WarRanking ranking in warRankings)
                {
                    _clanMemberStats.Add(ClanMemberStatsViewModel.ConvertToClanMemberStats(ranking));
                }

                if (warRankings.Any() && warRankings.Count > 0)
                {
                    _clanWarStats = _clanMemberStats.GroupBy(g => g.ClanWarId).Select(p => new ClanMemberStatsViewModel
                    {
                        ClanId             = clanId,
                        ClanWarId          = p.Key,
                        WarsCount          = 1,
                        AttacksWon         = (short)p.Sum(r => r.AttacksWon),
                        TotalAttacks       = (short)p.Count(),
                        TotalHeroicDefense = (short)p.Sum(r => Convert.ToInt16(r.TotalHeroicDefense)),
                        TotalHeroicAttack  = (short)p.Sum(r => Convert.ToInt16(r.TotalHeroicAttack)),
                        AttacksDefended    = (short)p.Sum(r => r.AttacksDefended),
                        AttacksOn          = (short)p.Sum(r => r.AttacksOn),
                        Stars = (short)p.Sum(r => r.Stars),
                        Xp    = (short)p.Sum(r => r.Xp)
                    }).Single();
                }

                List <ClanUser>           clanUsers        = ClanUserManager.SelectAllByClanId(clanId);
                List <Models.ClanWarPick> availableAttacks = RankingsManager.SelectAttacksAvailableForWar(warId);
                _availableAttacks = availableAttacks.ToDictionary(key => key.clanUserId, value => clanUsers.Where(p => p.id == value.clanUserId).Select(p => p.name).Single());
            }
        }
Ejemplo n.º 17
0
        public List <ClanUser> GetFreeAgents()
        {
            List <ClanUser> freeAgents = ClanUserManager.SelectFreeAgentsByClanId(this.ClanId);

            return(freeAgents);
        }
Ejemplo n.º 18
0
        public List <ClanUser> GetGroupMembers(int groupId)
        {
            List <ClanUser> groupMembers = ClanUserManager.SelectGroupMembersByGroupId(groupId);

            return(groupMembers);
        }
Ejemplo n.º 19
0
        public ClanUser GetGroupLeader(int groupLeaderId)
        {
            ClanUser leader = ClanUserManager.SelectByClanUserId(groupLeaderId);

            return(leader);
        }