예제 #1
0
        public async Task<ActionResult> Index(ObjectivesIndexViewModel model)
        {
            model.Objectives = objectiveService.GetObjectives().Where(o => o.IsActive).OrderBy(o => o.Title).ToList();

            await PopulatePostObjectives(model);
            model.FormName = "Index";
            model.FormID = "";

            ModelState.Clear();

            return View(model);
        }
예제 #2
0
        public async Task<ActionResult> Boosted()
        {
            ObjectivesIndexViewModel model = new ObjectivesIndexViewModel();

            model.Objectives = objectiveService.GetObjectives().Where(o => o.IsActive && o.BoostedObjective != null).ToList();

            await PopulateGetObjectives(model);

            model.FormName = "Boosted";
            model.FormID = "";

            return View("Index", model);
        }
예제 #3
0
        public async Task PopulatePostObjectives(ObjectivesIndexViewModel model)
        {
            model.LoggedInUser = await objectiveService.GetCurrentUser();

            if (User.Identity.IsAuthenticated && User.IsInRole("Admin"))
            {
                model.FullNavList = CreateObjectivesAdminNavList();
            }
            else
            {
                model.FullNavList = CreateObjectivesNavList();
            }

            if (model.Objectives != null)
            {
                if (model.FilterLibrary && User.Identity.IsAuthenticated)
                {
                    model.PreviousFilterLibrary = !model.PreviousFilterLibrary;

                    if (model.PreviousFilterLibrary && HttpContext.User.Identity.IsAuthenticated)
                    {
                        AppUser user = await objectiveService.GetCurrentUser();

                        if (user.OwnedGames != null)
                        {
                            model.Objectives = model.Objectives.Where(o => o.Product == null || user.OwnsProduct(o.Product)).ToList();
                        }
                    }
                }

                model.FilterLibrary = false;
            }
            
            foreach (SelectedTagMapping mapping in model.SelectedTagMappings)
            {
                if (model.TagToChange == mapping.StoreTag.TagID)
                {
                    mapping.IsSelected = !mapping.IsSelected;
                }

                mapping.StoreTag = objectiveService.GetTagByID(mapping.StoreTag.TagID);

                if (mapping.IsSelected && model.Objectives != null)
                {
                    model.Objectives = model.Objectives.Where(o => o.Product.HasTag(mapping.StoreTag)).ToList();
                }
            }

            model.TagToChange = 0;
        }
예제 #4
0
        public async Task PopulateGetObjectives(ObjectivesIndexViewModel model)
        {
            if (User.Identity.IsAuthenticated)
            {
                model.LoggedInUser = await objectiveService.GetCurrentUser();
            }

            if (User.Identity.IsAuthenticated && User.IsInRole("Admin"))
            {
                model.FullNavList = CreateObjectivesAdminNavList();
            }
            else
            {
                model.FullNavList = CreateObjectivesNavList();
            }

            if (model.Objectives != null)
            {
                List<SelectedTagMapping> tagMappings = new List<SelectedTagMapping>();

                foreach (Tag tag in objectiveService.GetTags())
                {
                    if (model.Objectives.Any(o => o.Product.HasTag(tag)))
                    {
                        tagMappings.Add(new SelectedTagMapping(tag, false));
                    }
                }

                model.SelectedTagMappings = tagMappings.OrderBy(t => t.StoreTag.TagName).ToList();
            }
        }