// Adds member to Member Table
        public static void Add(Group group)
        {
            Random rand = new Random();
            group.ID = rand.Next();

            ClanGroups.Add(group);

            Write();
        }
        public static void Update(Group updatedGroup)
        {
            var group = ClanGroups.Where(p => p.ID == updatedGroup.ID).FirstOrDefault();

            if (group != null)
            {
                group.Name = updatedGroup.Name;
                group.GroupLeaderId = updatedGroup.GroupLeaderId;
            }

            Write();
        }
        public ActionResult Create(UpsertGroupViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Group newGroup = new Group();

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

                    newGroup.Name = model.GroupName;
                    newGroup.GroupLeaderId = leaderId;

                    GroupsManager.Add(newGroup);

                    Member groupLeader = MembersManager.SelectByMemberId(leaderId);
                    groupLeader.GroupId = newGroup.ID;

                    MembersManager.Update(groupLeader);

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

                            Member member = MembersManager.SelectByMemberId(id);
                            member.GroupId = newGroup.ID;

                            MembersManager.Update(member);
                        }
                    }
                }
            }
            catch
            {
                return View(new UpsertGroupViewModel());
            }

            return RedirectToAction("EditMode");
        }