Exemplo n.º 1
0
 /// <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();
     }
 }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
        /// <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();
            }
        }
Exemplo n.º 4
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");
        }