コード例 #1
0
        public ActionResult ManageHighlights(ManageHighlightsViewModel model)
        {
            // TODO: implement editing
            if (model.SelectedAchievementIDs == null && model.SelectedQuestsIDs == null)
                ModelState.AddModelError(String.Empty, "At least one achievement or quest must be selected to be featured!");

            if (ModelState.IsValid)
            {
                UnitOfWork work = new UnitOfWork();
                work.SystemRepository.AdminEditHighlights(model);
                return RedirectToAction("Index");
            }

            ManageHighlightsViewModel refreshModel = ManageHighlightsViewModel.Populate();
            model.AllAchievementsList = refreshModel.AllAchievementsList;
            model.AllQuestsList = refreshModel.AllQuestsList;

            return View(model);
        }
コード例 #2
0
        public void AdminEditHighlights(ManageHighlightsViewModel model)
        {
            // TODO: Optimize?
            // Remove old featured items
            IEnumerable<quest_template> currentFeaturedQuests = _dbContext.quest_template.Where(m => m.featured);
            foreach (quest_template quest in currentFeaturedQuests)
                quest.featured = false;

            IEnumerable<achievement_template> currentFeaturedAchievements = _dbContext.achievement_template.Where(m => m.featured);
            foreach (achievement_template achievement in currentFeaturedAchievements)
                achievement.featured = false;

            // Set new featured items
            if (model.SelectedQuestsIDs != null)
            {
                IEnumerable<quest_template> newFeaturedQuests = _dbContext.quest_template.Where(m => model.SelectedQuestsIDs.Contains(m.id));
                foreach (quest_template quest in newFeaturedQuests)
                    quest.featured = true;
            }

            if (model.SelectedAchievementIDs != null)
            {
                IEnumerable<achievement_template> newFeaturedAchievements = _dbContext.achievement_template.Where(m => model.SelectedAchievementIDs.Contains(m.id));
                foreach (achievement_template achievement in newFeaturedAchievements)
                    achievement.featured = true;
            }

            Save();
        }