public ActionResult ManageResources() { //set up the model/service and fetch data var model = new ResourceListViewModel(); model.ResourceCategories = ExigoDAL.GetResourceCategories(new GetResourceCategoriesRequest()).OrderBy(c => c.CategoryOrder); model.CountryAvailability = GlobalSettings.Markets.AvailableMarkets; model.Languages = ExigoDAL.GetUniqueLanguages().ToList(); model.ResourceTypes = ExigoDAL.GetResourceTypes(new GetResourceTypeRequest()).OrderBy(rt => rt.SortOrder).ToList(); model.CategoryTranslation = ExigoDAL.GetCategoryTranslations(new GetTranslatedCategoryRequest()); model.Tags = ExigoDAL.GetTagsForResources(new GetTagsForResourcesRequest()); //Create ListItems for the Market/Language DropDown List <SelectListItem> items = new List <SelectListItem>(); foreach (var market in model.CountryAvailability) { SelectListItem item = new SelectListItem() { Value = market.Countries.FirstOrDefault(), Text = CommonResources.Countries(market.Countries.FirstOrDefault()), Selected = Identity.Current.Country == market.Countries.FirstOrDefault() }; items.Add(item); } model.CountryList = items; return(View(model)); }
public ActionResult ResourceItems(Guid?editItemID) { Guid ID = Guid.NewGuid(); var model = new ResourceListViewModel(); model.CountryAvailability = GlobalSettings.Markets.AvailableMarkets; model.Languages = ExigoDAL.GetUniqueLanguages().ToList(); model.ResourceTypes = ExigoDAL.GetResourceTypes(new GetResourceTypeRequest()); model.Statuses = ExigoDAL.GetResourceStatuses(); model.ResourceCategories = ExigoDAL.GetResourceCategories(new GetResourceCategoriesRequest()); model.Tags = ExigoDAL.GetTagsForResources(new GetTagsForResourcesRequest()); model.IsEdit = false; model.CurrentTags = new List <string>(); if (editItemID != null && editItemID != Guid.Empty) { ID = editItemID ?? ID; model.Resource = ExigoDAL.GetResourceItems(new GetResourcesRequest() { ItemID = ID }).FirstOrDefault(); var TagIDs = ExigoDAL.GetResourceItemTags(new GetResourceItemTagsRequest() { ItemID = ID }).Select(t => t.TagID); model.CurrentTags = model.Tags.Where(t => TagIDs.Contains(t.TagID)).Select(t => t.Name).Distinct().ToList(); model.Resource.ResourceCategoryItems = ExigoDAL.GetResourceCategoryItems(new GetResourceCategoryItemsRequest() { ItemID = ID }); model.Resource.ResourceAvailabilities = ExigoDAL.GetResourceAvailabilities(new GetResourceAvailabilitiesRequest() { ItemID = ID }); //SET Default Values for DropDownList on View model.TypeID = model.Resource.TypeID; model.StatusID = model.Resource.StatusID; model.Language = model.Resource.Language; model.IsEdit = true; } model.EditItemID = editItemID ?? Guid.Empty; return(View(model)); }
public JsonNetResult GetResourceList(ResourceFilters filter) { try { var model = new ResourceListViewModel(); model.Filter = filter; model.IsResourceManager = filter.isResourceManager; model.ResourceCategories = new JavaScriptSerializer().Deserialize <IEnumerable <ExigoService.ResourceCategory> >(filter.Categories); var filteredcatfilter = filter.CategoryFilter != null ? new JavaScriptSerializer().Deserialize <string>(filter.CategoryFilter) : ""; var categoryFilter = (filteredcatfilter != null && filteredcatfilter != "") ? Guid.Parse(filteredcatfilter) : Guid.Empty; model.ResourceList = ExigoDAL.GetResourceItems(new GetResourcesRequest()); model.CategoryItemList = ExigoDAL.GetResourceCategoryItems(new GetResourceCategoryItemsRequest()).OrderBy(t => t.ItemOrder); model.Types = ExigoDAL.GetResourceTypes(new GetResourceTypeRequest() { TypeDescriptions = filter.MediaFilter }); //Get a List of CategoryIDs from the Rescource Category List var catIds = model.ResourceCategories.Select(c => c.CategoryID).ToList(); //Get all resources assigned to a CURRENT Category ID var assigned = model.CategoryItemList.Where(c => catIds.Contains(c.CategoryID)).ToList(); //Assign all remaining items so they may be displayed in the Unassigned Category model.UnassignedResources = model.CategoryItemList.Except(assigned).ToList(); //Get a list of Unassigned Resources before filtering by market var unassignedresourceIDs = model.UnassignedResources.Select(ur => ur.ItemID).ToList(); model.UnassignedRsourceList = model.ResourceList.Where(rl => unassignedresourceIDs.Contains(rl.ItemID)).ToList(); if (filter.MarketFilter != null && filter.MarketFilter != string.Empty) { if (filter.LanguageFilter != null && filter.LanguageFilter != string.Empty) { var language = Convert.ToInt32(filter.LanguageFilter); var cc = filter.MarketFilter; model.GetAvailableResources = ExigoDAL.GetResourceAvailabilities(new GetResourceAvailabilitiesRequest() { CountryCode = cc, LanguageID = language }); model.AvailableResources = model.GetAvailableResources.Select(ar => ar.ItemID).ToList(); } else { var cc = filter.MarketFilter; model.GetAvailableResources = ExigoDAL.GetResourceAvailabilities(new GetResourceAvailabilitiesRequest() { CountryCode = cc }); model.AvailableResources = model.GetAvailableResources.Select(ar => ar.ItemID).ToList(); } } model.ResourceList = model.ResourceList.Where(x => model.AvailableResources.Contains(x.ItemID)); bool filtered = false; if (filter.MediaFilter != null && filter.MediaFilter.Count() > 0) { var typeIDs = model.Types.Select(v => v.TypeID); filtered = true; model.ResourceList = model.ResourceList.Where(x => typeIDs.Contains(x.TypeID)).ToList(); } if (categoryFilter != null && categoryFilter != Guid.Empty) { model.SelectedCategoryID = model.ResourceCategories.Where(c => c.CategoryID == categoryFilter).FirstOrDefault().CategoryID; } if (filter.KeyWord != null && filter.KeyWord.Any()) { var keyword = filter.KeyWord; var tag = ExigoDAL.GetTagsForResources(new GetTagsForResourcesRequest() { Names = keyword }).FirstOrDefault(); if (tag != null) { var resourceitemtagIDs = ExigoDAL.GetResourceItemTags(new GetResourceItemTagsRequest() { TagID = tag.TagID }).AsEnumerable().Select(rt => rt.ItemID); //var tagitems = model.ResourceList.Where(rl => resourceitemtagIDs.Contains(rl.ItemID)); //var matchingitems = model.ResourceList.Where(rl => keyword.Contains(rl.Title) || rl.ItemDescription.ToLower().Contains(keyword)); //var keywordSearchResult = tagitems.Union(matchingitems).ToList().Select(r => r.ItemID); //model.ResourceList = model.ResourceList.Where(rl => keywordSearchResult.Contains(rl.ItemID)); model.ResourceList = model.ResourceList.Where(rl => resourceitemtagIDs.Contains(rl.ItemID)); } } var html = this.RenderPartialViewToString("partials/_resourcelist", model); return(new JsonNetResult(new { success = true, html = html, isFiltered = filtered })); } catch (Exception ex) { return(new JsonNetResult(new { success = false, message = ex.Message })); } }
public JsonNetResult SortCategoryByDate(Guid categoryID, string sortType, ResourceFilters filter) { try { var model = new CategoryResourceItemsViewModel(); var availableResources = new List <Guid>(); model.CategoryItem = ExigoDAL.GetResourceCategoryItems(new GetResourceCategoryItemsRequest() { CategoryID = categoryID }).FirstOrDefault(); model.IsResourceManager = filter.isResourceManager; model.ResourceList = ExigoDAL.GetResourceItemsByCategory(categoryID); model.Types = ExigoDAL.GetResourceTypes(new GetResourceTypeRequest() { TypeDescriptions = filter.MediaFilter }); if (filter.MarketFilter != null && filter.MarketFilter != string.Empty) { if (filter.LanguageFilter != null && filter.LanguageFilter != string.Empty) { var language = Convert.ToInt32(filter.LanguageFilter); var cc = filter.MarketFilter; var getAvailableResources = ExigoDAL.GetResourceAvailabilities(new GetResourceAvailabilitiesRequest() { CountryCode = cc, LanguageID = language }); availableResources = getAvailableResources.Select(ar => ar.ItemID).ToList(); } else { var cc = filter.MarketFilter; var getAvailableResources = ExigoDAL.GetResourceAvailabilities(new GetResourceAvailabilitiesRequest() { CountryCode = cc }); availableResources = getAvailableResources.Select(ar => ar.ItemID).ToList(); } } model.ResourceList = model.ResourceList.Where(x => availableResources.Contains(x.ItemID)); if (!model.IsResourceManager) { model.ResourceList = model.ResourceList.Where(c => c.StatusID == ExigoDAL.ResourceStatuses.Active && (c.PostDate <= DateTime.Now.ToCST() || c.PostDate == null)).ToList(); } switch (sortType) { case "asc": model.ResourceList = model.ResourceList.OrderBy(c => c.CreatedDate); break; case "desc": model.ResourceList = model.ResourceList.OrderByDescending(c => c.CreatedDate); break; default: model.ResourceList = model.ResourceList.OrderBy(c => c.ItemOrder); break; } if (filter.MediaFilter != null && filter.MediaFilter.Count() > 0) { var typeIDs = model.Types.Select(v => v.TypeID); model.ResourceList = model.ResourceList.Where(x => typeIDs.Contains(x.TypeID)).ToList(); } if (filter.KeyWord != null && filter.KeyWord.Any()) { var keyword = filter.KeyWord; var tag = ExigoDAL.GetTagsForResources(new GetTagsForResourcesRequest() { Names = keyword }).FirstOrDefault(); if (tag != null) { var resourceitemtagIDs = ExigoDAL.GetResourceItemTags(new GetResourceItemTagsRequest() { TagID = tag.TagID }).AsEnumerable().Select(rt => rt.ItemID); model.ResourceList = model.ResourceList.Where(rl => resourceitemtagIDs.Contains(rl.ItemID)); } } var html = this.RenderPartialViewToString("Partials/_CategoryResourceItems", model); return(new JsonNetResult(new { success = true, html = html })); } catch (Exception ex) { return(new JsonNetResult(new { success = false, message = ex.Message })); } }