Example #1
0
        public IActionResult Index(string q, bool isDesc, string col, int pageNr = 1)
        {
            var viewModel = new SubCategoryIndexViewModel();

            var subCategorySearchResult = _subCategoryRepository.GetSearchResult(q).ToList();
            var sortedSubCategories     = GetSortedSubCategoryList(subCategorySearchResult, isDesc, col, ref viewModel);

            viewModel.SubCategories            = GetSubCategoriesByPageNr(pageNr, sortedSubCategories);
            viewModel.TotalSubCategoryAmount   = subCategorySearchResult.Count;
            viewModel.SubCategoryAmountPerPage = _subCategoriesPerPage;
            viewModel.TotalNumberOfPages       = (int)Math.Ceiling(viewModel.TotalSubCategoryAmount / viewModel.SubCategoryAmountPerPage);
            viewModel.SelectedPageNumber       = pageNr;
            viewModel.q = q;

            return(View(viewModel));
        }
        public IActionResult Index(int Id)
        {
            IEnumerable <SubCategory> list = _subCcategoryDataService.Query(s => s.CategoryId == Id);
            //Get Category name
            Category cat = _categoryDataService.GetSingle(p => p.CategoryId == Id);
            //put CategoryName into session

            //Create vm
            SubCategoryIndexViewModel vm = new SubCategoryIndexViewModel
            {
                Total         = list.Count(),
                SubCategories = list,
                CategoryName  = cat.Name,
                CategoryId    = Id
            };

            return(View(vm));
        }
        public IActionResult AddEditCategoryTranslations(SubCategoryIndexViewModel modelIn)
        {
            if (this.ModelState.IsValid)
            {
                if (modelIn.Id == 0)
                {
                    try
                    {
                        var subCategoryTranslation = new SubCategoryLang
                        {
                            Name          = modelIn.Name,
                            LangText      = modelIn.LangText,
                            SubCategoryId = modelIn.SubCategoryId,
                            Lang          = modelIn.Lang,
                        };
                        this.categoryService.SaveSubCategotyLangAsync(subCategoryTranslation);
                        return(this.RedirectToAction("Index", "Category", new { toastr = "New local category name has been created successfully." }));
                    }
                    catch
                    {
                        return(this.RedirectToAction("Index", "Category", new { toastr = "ERROR: No category translation has been created. Try again." }));
                    }
                }
                else
                {
                    try
                    {
                        var subCategoryTranslation = this.categoryService.GetSubCategoryTranslation((int)modelIn.Id);
                        subCategoryTranslation.LangText = modelIn.LangText;
                        this.categoryService.UpdateSubCategoryTranslation(subCategoryTranslation);
                        return(this.RedirectToAction("Index", "Category", new { toastr = "The categroy translation has been updated successfully" }));
                    }
                    catch
                    {
                        return(this.RedirectToAction("Index", "Category", new { toastr = "ERROR: Category translation hasn't been updated. Try again." }));
                    }
                }
            }

            this.ViewBag.Message = modelIn.Id != 0 ? "Edit Translation" : "New Translation";
            return(this.View("AddEditCategoryTranslation", modelIn));
        }
        public IActionResult AddEditCategoryTranslation(SubCategoryIndexViewModel modelIn)
        {
            if (this.ModelState.IsValid)
            {
                if (modelIn.Id != 0)
                {
                    this.ViewBag.Title = "Edit Translation";
                }
                else
                {
                    this.ViewBag.Title = "New Translation";
                }

                if (modelIn.LangText == "No translation available")
                {
                    modelIn.LangText = string.Empty;
                }

                return(this.View(modelIn));
            }

            return(this.RedirectToAction("Index"));
        }
Example #5
0
        private IEnumerable <SubProductCategory> GetSortedSubCategoryList(IEnumerable <SubProductCategory> subCategorySearchResult, bool isDesc, string col, ref SubCategoryIndexViewModel viewModel)
        {
            viewModel.IsDescCategory = false;
            viewModel.IsDescTitle    = false;
            viewModel.IsDescId       = false;
            viewModel.SelectedColumn = col;
            viewModel.IsDesc         = isDesc;

            if (isDesc && col == "title")
            {
                subCategorySearchResult = subCategorySearchResult.OrderByDescending(subCat => subCat.Title);
            }
            else if (!isDesc && col == "title")
            {
                subCategorySearchResult = subCategorySearchResult.OrderBy(subCat => subCat.Title);
                viewModel.IsDescTitle   = true;
            }
            else if (isDesc && col == "id")
            {
                subCategorySearchResult = subCategorySearchResult.OrderByDescending(subCat => subCat.Id);
            }
            else if (!isDesc && col == "id")
            {
                subCategorySearchResult = subCategorySearchResult.OrderBy(subCat => subCat.Id);
                viewModel.IsDescId      = true;
            }

            else if (isDesc && col == "category")
            {
                subCategorySearchResult = subCategorySearchResult.OrderByDescending(subCat => subCat.Category.Title);
            }
            else if (!isDesc && col == "category")
            {
                subCategorySearchResult  = subCategorySearchResult.OrderBy(subCat => subCat.Category.Title);
                viewModel.IsDescCategory = true;
            }

            return(subCategorySearchResult);
        }