/// <summary>
 /// Inserts a new Rule
 /// </summary>
 public static void Insert(Rule rule)
 {
     using (var dbContext = new HouseOfClansEntities())
     {
         rule.addedOn = DateTime.Now;
         dbContext.Rules.Add(rule);
         dbContext.SaveChanges();
     }
 }
        /// <summary>
        /// Gets a rule based on the rule id
        /// </summary>
        /// <param name="clanId">Clan Id</param>
        public static Rule SelectByRuleId(int ruleId)
        {
            Rule rule = new Rule();

            using (var dbContext = new HouseOfClansEntities())
            {
                rule = dbContext.Rules.Where(p => p.id == ruleId).FirstOrDefault();
            }

            return rule;
        }
        /// <summary>
        /// Updates a Rule
        /// </summary>
        public static void Update(Rule rule)
        {
            using (var dbContext = new HouseOfClansEntities())
            {
                Rule ruleInfo = RuleManager.SelectByRuleId(rule.id);
                ruleInfo.updatedOn = DateTime.Now;

                dbContext.Rules.Attach(ruleInfo);
                dbContext.Entry(ruleInfo).CurrentValues.SetValues(rule);
                dbContext.SaveChanges();
            }
        }
        public ActionResult AddRule(UpsertRuleViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Rule newRule = new Rule();

                    newRule.clanId = (int)ClanManager.GetClanId(User.Identity.GetUserId());
                    newRule.description = model.Description;

                    RuleManager.Insert(newRule);
                }
            }
            catch
            {
                return View();
            }

            return RedirectToAction("Index");
        }