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;
 }