Exemple #1
0
        public ActionResult ManageResources()
        {
            //set up the model/service and fetch data
            var model = new ResourceListViewModel();

            model.ResourceCategories  = Exigo.GetResourceCategories(new GetResourceCategoriesRequest()).OrderBy(c => c.CategoryOrder);
            model.CountryAvailability = GlobalSettings.Markets.AvailableMarkets;
            model.Languages           = Exigo.GetLanguages().ToList();
            model.ResourceTypes       = Exigo.GetResourceTypes(new GetResourceTypeRequest()).OrderBy(rt => rt.SortOrder).ToList();
            model.CategoryTranslation = Exigo.GetCategoryTranslations(new GetTranslatedCategoryRequest());
            model.Tags = Exigo.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  = market.Description
                };
                items.Add(item);
            }
            model.CountryList = items;

            return(View(model));
        }
Exemple #2
0
        public JsonNetResult EditCategory(List <TranslatedCategory> items, Guid categoryID, Guid?parentID)
        {
            try
            {
                foreach (var item in items.Where(i => !i.Language.IsNullOrEmpty()))
                {
                    if (item.Language == "English")
                    {
                        //Update the Resource
                        var resourceCategory = Exigo.GetResourceCategories(new GetResourceCategoriesRequest()
                        {
                            CategoryID = categoryID
                        }).FirstOrDefault();
                        resourceCategory.CategoryDescription = item.TranslatedCategoryDescription;
                        resourceCategory.ParentID            = parentID ?? Guid.Empty;
                        Exigo.ModifyResourceCategory(resourceCategory);
                    }
                    //Update the Translations
                    var translatedCategory = Exigo.GetCategoryTranslations(new GetTranslatedCategoryRequest()
                    {
                        Language = item.Language, CategoryID = categoryID
                    }).FirstOrDefault();
                    if (translatedCategory != null)
                    {
                        translatedCategory.TranslatedCategoryDescription = item.TranslatedCategoryDescription;
                        Exigo.ModifyResourceTranslationDescription(translatedCategory);
                    }
                    else
                    {
                        ResourceTranslatedCategoryItem TCategory = new ResourceTranslatedCategoryItem()
                        {
                            TranslatedCategoryID          = Guid.NewGuid(),
                            CategoryID                    = categoryID,
                            Language                      = item.Language,
                            TranslatedCategoryDescription = item.TranslatedCategoryDescription
                        };
                        Exigo.AddCategoryTranslation(TCategory);
                    }
                }

                return(new JsonNetResult(new
                {
                    success = true
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }
Exemple #3
0
        public ActionResult ManageResourceCategories()
        {
            //set up the model/service and fetch data
            var model = new ResourceCategoryListViewModel();

            string ResourceCategoryText;


            model.ResourceCategories = Exigo.GetResourceCategories(new GetResourceCategoriesRequest()
            {
                ParentID = Guid.Empty
            }).OrderBy(c => c.CategoryOrder);

            List <SelectListItem> categorySelectItems = new List <SelectListItem>();

            foreach (var category in model.ResourceCategories.ToList())
            {
                category.HasChildren = Exigo.GetResourceCategories(new GetResourceCategoriesRequest()
                {
                    ParentID = category.CategoryID
                }).Any();
                //var childCount = context.ResourceCategories.Where(c => c.ParentID == category.CategoryID).Count();
                //category.HasChildren = (childCount > 0);
                ResourceCategoryText = Exigo.GetCategoryTranslations(new GetTranslatedCategoryRequest()
                {
                    Language = Identity.Current.Language.LanguageDescription, CategoryID = category.CategoryID
                }).FirstOrDefault().TranslatedCategoryDescription;

                if (ResourceCategoryText.IsNullOrEmpty())//#71613 Ivan S. 2015-11-06 Validated when the translation is not available in the resource files
                {
                    ResourceCategoryText = category.CategoryDescription;
                }
                categorySelectItems.Add(new SelectListItem
                {
                    Text  = ResourceCategoryText,
                    Value = category.CategoryID.ToString()
                });
            }
            model.ResourceCategorySelectListItems = categorySelectItems;

            return(View(model));
        }
Exemple #4
0
        public JsonNetResult GetModal(Guid categoryID, Guid parentCategoryID)
        {
            var model = new ResourceCategoryViewModel();

            try
            {
                //context.ResourceCategories.Where(c => c.ParentID == null && c.CategoryID != categoryID)
                List <SelectListItem>   ListItems = new List <SelectListItem>();
                List <ResourceCategory> categories;
                using (var context = Exigo.Sql())
                {
                    categories = context.Query <ResourceCategory>(@"
                        SELECT 
                            CategoryID,
                            CategoryDescription
                        FROM
                            ExigoWebContext.ResourceCategories
                        WHERE
                            ParentID = @parentid
                        AND
                            CategoryID <> @categoryid

                        ", new { parentid = Guid.Empty, categoryid = categoryID }).ToList();
                    foreach (var cat in categories)
                    {
                        SelectListItem item = new SelectListItem()
                        {
                            Value = cat.CategoryID.ToString(),
                            Text  = cat.CategoryDescription
                        };
                        ListItems.Add(item);
                    }
                }
                model.ParentCategories = ListItems;


                model.allLanguages = Exigo.GetLanguages().ToList();

                if (categoryID != Guid.Empty)
                {
                    model.Categories = Exigo.GetCategoryTranslations(new GetTranslatedCategoryRequest()
                    {
                        CategoryID = categoryID
                    }).ToList();
                }
                var parentCat = Exigo.GetResourceCategories(new GetResourceCategoriesRequest()
                {
                    CategoryID = categoryID
                }).FirstOrDefault();
                model.SelectedParentCategoryID = parentCat == null ? Guid.Empty : parentCat.ParentID;
                model.hasSubCategories         = categoryID == Guid.Empty ? false : Exigo.GetResourceCategories(new GetResourceCategoriesRequest {
                    ParentID = categoryID
                }).Count() > 0;
                var html = this.RenderPartialViewToString("partials/_categorypartial", model);

                return(new JsonNetResult(new
                {
                    success = true,
                    html = html
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }
Exemple #5
0
        public JsonNetResult DeleteCategory(Guid categoryID)
        {
            try
            {
                //Create new List Guids
                List <Guid> categoryList = new List <Guid>();

                //Get Children Categories
                categoryList = Exigo.GetResourceCategories(new GetResourceCategoriesRequest()
                {
                    ParentID = categoryID
                }).Select(cat => cat.CategoryID).ToList();

                //Add Parent Category to List
                categoryList.Add(categoryID);

                //reset the resource items
                var resources = Exigo.GetResourceCategoryItems(new GetResourceCategoryItemsRequest()
                {
                    CategoryIDs = categoryList
                }).Select(v => v.ItemID);

                if (resources.Any())
                {
                    using (var context = Exigo.Sql())
                    {
                        context.Execute(@"
                            UPDATE 
                                ExigoWebContext.ResourceCategoryItems
                            SET
                                CategoryID = cast(cast(0 as binary) as uniqueidentifier)
                            WHERE
                                CategoryID IN @categorylist
                            AND
                                ItemID IN @resources
                         
                        ", new { categorylist = categoryList, resources = resources });
                    }
                }



                var allCategoryItems = Exigo.GetResourceCategoryItems(new GetResourceCategoryItemsRequest());

                var listWithNoCategory = allCategoryItems.Where(c => c.CategoryID == Guid.Empty);
                var deleteItemList     = new List <ResourceCategoryItem>();

                foreach (var item in listWithNoCategory)
                {
                    if (allCategoryItems.Where(c => c.ItemID == item.ItemID && c.CategoryID != Guid.Empty).Any())
                    {
                        deleteItemList.Add(item);
                    }
                }

                var deleteIDs = deleteItemList.Select(c => c.ItemID);

                if (deleteItemList.Any())
                {
                    using (var context = Exigo.Sql())
                    {
                        context.Execute(@"
                            DELETE FROM 
                            ExigoWebContext.ResourceCategoryItems
                        WHERE
                            CategoryID = cast(cast(0 as binary) as uniqueidentifier)
                        AND
                            ItemID IN @itemids
                        
                         
                        ", new { itemids = deleteIDs });
                    }
                }

                //delete the Category and Children
                var category = Exigo.GetResourceCategories(new GetResourceCategoriesRequest()
                {
                    CategoryID = categoryID
                }).FirstOrDefault();
                var categoryOrder = category.CategoryOrder ?? 0;
                using (var context = Exigo.Sql())
                {
                    context.Execute(@"
                        DELETE FROM 
                            ExigoWebContext.ResourceCategories
                        WHERE
                            CategoryID = @categoryid
                        OR  
                            ParentID = @categoryid
                         
                    ", new { categoryid = category.CategoryID });
                }

                //delete the translations
                var translatedCategoryIDs = Exigo.GetCategoryTranslations(new GetTranslatedCategoryRequest()
                {
                    CategoryID = categoryID
                }).Select(t => t.TranslatedCategoryID);
                using (var context = Exigo.Sql())
                {
                    context.Execute(@"
                        DELETE FROM 
                            ExigoWebContext.ResourceTranslatedCategoryItems
                        WHERE
                            TranslatedCategoryID IN @translatedids
                         
                    ", new { translatedids = translatedCategoryIDs });
                }

                //2015-09-08
                //Ivan S.
                //66
                //Decreases the order for the following categories
                var categoryOrders = Exigo.GetResourceCategories(new GetResourceCategoriesRequest()
                {
                    CategoryOrder = categoryOrder
                }).Select(rc => rc.CategoryID);
                using (var context = Exigo.Sql())
                {
                    context.Execute(@"
                        UPDATE 
                            ExigoWebContext.ResourceCategories
                        SET
                            CategoryOrder = CategoryOrder - 1
                        WHERE
                            CategoryID IN @categoryorders
                         
                    ", new { categoryorders = categoryOrders });
                }

                return(new JsonNetResult(new
                {
                    success = true,
                }));
            }
            catch (Exception ex)
            {
                return(new JsonNetResult(new
                {
                    success = true,
                    message = ex.Message
                }));
            }
        }