/// <summary>
 /// Inserts a new ClanGroup
 /// </summary>
 public static void Insert(ClanGroup clanGroup)
 {
     using (var dbContext = new HouseOfClansEntities())
     {
         clanGroup.addedOn = DateTime.Now;
         dbContext.ClanGroups.Add(clanGroup);
         dbContext.SaveChanges();
     }
 }
        /// <summary>
        /// Gets a ClanGroup based on the ClanGroup id
        /// </summary>
        /// <param name="clanId">Clan Id</param>
        public static ClanGroup SelectByClanGroupId(int clanGroupId)
        {
            ClanGroup clanGroup = new ClanGroup();

            using (var dbContext = new HouseOfClansEntities())
            {
                clanGroup = dbContext.ClanGroups.Where(p => p.id == clanGroupId).FirstOrDefault();
            }

            return(clanGroup);
        }
        /// <summary>
        /// Updates a ClanGroup
        /// </summary>
        public static void Update(ClanGroup clanGroup)
        {
            using (var dbContext = new HouseOfClansEntities())
            {
                ClanGroup clanGroupInfo = ClanGroupManager.SelectByClanGroupId(clanGroup.id);
                clanGroupInfo.updatedOn = DateTime.Now;

                dbContext.ClanGroups.Attach(clanGroupInfo);
                dbContext.Entry(clanGroupInfo).CurrentValues.SetValues(clanGroup);
                dbContext.SaveChanges();
            }
        }
        /// <summary>
        /// Deletes a ClanGroup
        /// </summary>
        public static bool Delete(int clanGroupId)
        {
            bool      isDeleted       = false;
            ClanGroup deleteClanGroup = ClanGroupManager.SelectByClanGroupId(clanGroupId);

            using (var dbContext = new HouseOfClansEntities())
            {
                dbContext.ClanGroups.Attach(deleteClanGroup);
                dbContext.ClanGroups.Remove(deleteClanGroup);
                isDeleted = dbContext.SaveChanges() > 0;
            }

            return(isDeleted);
        }
        /// <summary>
        /// Gets the all group members(except Leader) based on the group id
        /// </summary>
        /// <param name="clanId">Clan Id</param>
        public static List <ClanUser> SelectGroupMembersByGroupId(int groupId)
        {
            List <ClanUser> groupMembers = new List <ClanUser>();

            using (var dbContext = new HouseOfClansEntities())
            {
                groupMembers = dbContext.ClanUsers.Where(p => p.clanGroupId == groupId).ToList();
            }

            ClanGroup group = ClanGroupManager.SelectByClanGroupId(groupId);

            groupMembers.RemoveAll(member => member.id == group.groupLeaderId);

            return(groupMembers);
        }
示例#6
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"));
        }