예제 #1
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");
        }
예제 #2
0
 /// <summary>
 /// Inserts a new Clan record
 /// </summary>
 public static void Insert(Clan clan)
 {
     using (var dbContext = new HouseOfClansEntities())
     {
         clan.addedOn = DateTime.Now;
         dbContext.Clans.Add(clan);
         dbContext.SaveChanges();
     }
 }
예제 #3
0
        /// <summary>
        /// Gets the clan information based on the clan id
        /// </summary>
        /// <param name="clanId">Clan Id</param>
        public static Clan SelectByClanId(int? clanId)
        {
            Clan clanInfo = new Clan();

            using (var dbContext = new HouseOfClansEntities())
            {
                clanInfo = dbContext.Clans.Where(p => p.id == clanId).Select(clan => clan).FirstOrDefault();
            }

            return clanInfo;
        }
예제 #4
0
        /// <summary>
        /// Updates the current Clan
        /// </summary>
        public static void Update(Clan clan)
        {
            using (var dbContext = new HouseOfClansEntities())
            {
                Clan clanInfo = ClanManager.SelectByClanId(clan.id);
                clanInfo.updatedOn = DateTime.Now;

                dbContext.Clans.Attach(clanInfo);
                dbContext.Entry(clanInfo).CurrentValues.SetValues(clan);
                dbContext.SaveChanges();
            }
        }