public ActionResult Create(RuleViewModel achievementrule)
        {
            if (achievementrule != null && ModelState.IsValid)
            {
                AchievementRule newRule = new AchievementRule()
                {
                    AchievementRuleId = achievementrule.AchievementRuleId,
                    Title = achievementrule.Title,
                    TicketsCount = achievementrule.TicketsCount,
                    TimespanDays = achievementrule.TimespanDays,
                    Priority = achievementrule.Priority
                };
                var existingAch = db.Achievements.GetById((int)achievementrule.Achievement);
                newRule.Achievement = existingAch;

                db.Rules.Add(newRule);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(achievementrule);
        }
 private RuleViewModel ConvertToViewModel(AchievementRule achievementrule)
 {
     RuleViewModel model = new RuleViewModel()
     {
         AchievementRuleId = achievementrule.AchievementRuleId,
         Title = achievementrule.Title,
         TicketsCount = achievementrule.TicketsCount,
         TimespanDays = achievementrule.TimespanDays,
         Priority = achievementrule.Priority
     };
     model.Achievement = achievementrule.Achievement.AchievementId;
     return model;
 }
        public ActionResult Edit(RuleViewModel achievementrule)
        {
            AchievementRule existingRule = db.Rules.GetById((int)achievementrule.AchievementRuleId);

            if (existingRule != null && ModelState.IsValid)
            {
                existingRule.Title = achievementrule.Title;
                existingRule.TicketsCount = achievementrule.TicketsCount;
                existingRule.TimespanDays = achievementrule.TimespanDays;
                existingRule.Priority = achievementrule.Priority;

                var existingAch = db.Achievements.GetById((int)achievementrule.Achievement);
                existingRule.Achievement = existingAch;
                //db.Rules.Update(existingRule);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(existingRule);
        }