Пример #1
0
        // since we run this seeder when the app starts
        // we should avoid adding duplicates, so check first
        // then add

        private void AddNewCategory(CategoryParent parentCategory)
        {
            var existingType = _context.CategoriesParents.FirstOrDefault(p => p.SubCategory.Name == parentCategory.SubCategory.Name && p.ParentCategory.Name == parentCategory.ParentCategory.Name);

            if (existingType == null)
            {
                _context.CategoriesParents.Add(parentCategory);
            }
        }
Пример #2
0
        public ActionResult DeleteParentCategory(CategoryParent cp)
        {
            var found = db.CategoryParents.Find(cp.Id);

            db.CategoryParents.Remove(db.CategoryParents.Find(cp.Id));


            db.SaveChanges();
            TempData["msg"] = "دسته اصلی با موفقیت حذف شد";
            return(RedirectToAction("AdminCategoryManagement", "Admin", new { idd = -1 }));
        }
Пример #3
0
        public ActionResult UpdateParentCategory(CategoryParent p)
        {
            var found = db.CategoryParents.Find(p.Id);

            if (found.Id != null)
            {
                found.Name = p.Name;
            }
            db.SaveChanges();
            TempData["msg"] = "اطلاعات با موفقیت آپدیت شد";
            return(RedirectToAction("AdminCategoryManagement", "Admin", new { id = -1 }));
        }
Пример #4
0
        public void SeedData()
        {
            var categ1 = new Category {
                Name = "categ1"
            };
            var categ2 = new Category {
                Name = "categ2"
            };
            var sub1_categ1 = new Category {
                Name = "sub1categ1"
            };
            var sub2_categ1 = new Category {
                Name = "sub2categ1"
            };
            var sub1_categ2 = new Category {
                Name = "sub1categ2"
            };
            var sub2_categ2 = new Category {
                Name = "sub2categ2"
            };
            var subcommon = new Category {
                Name = "subcommon"
            };
            var cat1 = new CategoryParent {
                SubCategory = sub1_categ1, ParentCategory = categ1
            };
            var cat2 = new CategoryParent {
                SubCategory = sub2_categ1, ParentCategory = categ1
            };
            var cat3 = new CategoryParent {
                SubCategory = sub1_categ2, ParentCategory = categ2
            };
            var cat4 = new CategoryParent {
                SubCategory = sub2_categ2, ParentCategory = categ2
            };
            var cat5 = new CategoryParent {
                SubCategory = subcommon, ParentCategory = categ1
            };
            var cat6 = new CategoryParent {
                SubCategory = subcommon, ParentCategory = categ2
            };

            AddNewCategory(cat1);
            AddNewCategory(cat2);
            AddNewCategory(cat3);
            AddNewCategory(cat4);
            AddNewCategory(cat5);
            AddNewCategory(cat6);

            _context.SaveChanges();
        }
        public List <CategoryParent> GetAllCategoryParent()
        {
            var model = new List <CategoryParent>();

            var paren = new CategoryParent();

            foreach (var item in GetCategory())
            {
                paren = GetCategoryParentById(item.Id);
                model.Add(paren);
            }

            return(model);
        }
Пример #6
0
        public bool Load(string culture)
        {
            bool ret = false;

            CategoryParent cat = new CategoryParent();

            cat.Language.CultureId = culture;

            Repository.Sql.Categories.Load(culture, cat);

            this.Items.Add(cat);
            this.items.LastLoad = DateTime.UtcNow;

            ret = true;

            return(ret);
        }
        public ActionResult List(string category, string subcategory, int?page, int?sort)
        {
            if (!DomainModel.Security.InputController.IsValid(category) ||
                !DomainModel.Security.InputController.IsValid(subcategory))
            {
                return(RedirectToAction(
                           WebUi.ViewModels.NavigationKeys.SecurityBadInputAction,
                           WebUi.ViewModels.NavigationKeys.SecurityController));
            }

            if (page == null)
            {
                page = 1;
            }
            if (sort == null)
            {
                sort = 1;
            }

            CategoryParent parent =
                DomainModel.Repository.Memory.Categories.Instance.Items
                [Models.AppCulture.CurrentCulture.CultureId];

            int?     categoryId = null;
            int?     parentId   = null;
            string   listTitle  = string.Empty;
            Category cat        = null;

            if (!string.IsNullOrWhiteSpace(category))
            {
                cat = parent[category];

                if (cat != null)
                {
                    parentId  = cat.CategoryId;
                    listTitle = cat.CategoryName;
                }
            }

            if (!string.IsNullOrWhiteSpace(subcategory) && cat != null)
            {
                cat = cat.SubCategories[subcategory];

                if (cat != null)
                {
                    categoryId = cat.CategoryId;

                    if (!string.IsNullOrWhiteSpace(listTitle))
                    {
                        listTitle += " - ";
                    }
                    listTitle += cat.CategoryName;
                }
            }

            WebUi.ViewModels.PagingInfo pagingInf = new ViewModels.PagingInfo();
            int startRow = (page.Value - 1) * pagingInf.ItemsPerPage + 1;

            GeneralDatabaseList list;

            if (string.IsNullOrEmpty(category) &&
                string.IsNullOrEmpty(subcategory))
            {
                list = DomainModel.Repository.Sql.Products.GetAll(
                    WebUi.Models.AppCulture.CurrentCulture.CultureId,
                    startRow,
                    startRow + pagingInf.ItemsPerPage - 1,
                    sort.Value);

                string sortName = UiResources.UiTexts.unsorted;

                if (DomainModel.Repository.Memory.ProductList.Instance.SortOptions.Keys.Contains(sort.Value))
                {
                    sortName = WebUi.Models.DynamicResources.GetText(
                        DomainModel.Repository.Memory.ProductList.Instance.SortOptions[sort.Value]);
                }

                string controller = ControllerContext.RouteData.Values["controller"].ToString();
                string section    = WebUi.Models.DynamicResources.GetText(controller.ToLower());

                listTitle = string.Format(
                    "{0} {1} ({2})",
                    UiResources.UiTexts.softwares,
                    section,
                    sortName);
            }
            else
            {
                list = DomainModel.Repository.Sql.Products.GetByCategory(
                    WebUi.Models.AppCulture.CurrentCulture.CultureId,
                    categoryId,
                    parentId,
                    startRow,
                    startRow + pagingInf.ItemsPerPage - 1,
                    sort.Value);
            }
            pagingInf.CurrentSortOption = sort.Value;
            pagingInf.CurrentPage       = page.Value;
            pagingInf.TotalItems        = list.TotalCount;
            pagingInf.listTitle         = listTitle;

            ViewData[ViewModels.ViewDataKeys.ListPagingDetails] = pagingInf;

            return(View("List", list.List));
        }
        public ActionResult List(string category, string subcategory, int?page, int?sort)
        {
            if (!DomainModel.Security.InputController.IsValid(category) ||
                !DomainModel.Security.InputController.IsValid(subcategory))
            {
                return(RedirectToAction(
                           WebUi.ViewModels.NavigationKeys.SecurityBadInputAction,
                           WebUi.ViewModels.NavigationKeys.SecurityController));
            }

            if (page == null)
            {
                page = 1;
            }
            if (sort == null)
            {
                sort = 1;
            }

            CategoryParent parent =
                DomainModel.Repository.Memory.Categories.Instance.Items
                [Models.AppCulture.CurrentCulture.CultureId];

            int?     categoryId = null;
            int?     parentId   = null;
            string   listTitle  = string.Empty;
            Category cat        = null;

            if (!string.IsNullOrWhiteSpace(category))
            {
                cat = parent[category];

                if (cat != null)
                {
                    parentId  = cat.CategoryId;
                    listTitle = cat.CategoryName;
                }
            }

            if (!string.IsNullOrWhiteSpace(subcategory) && cat != null)
            {
                cat = cat.SubCategories[subcategory];

                if (cat != null)
                {
                    categoryId = cat.CategoryId;

                    if (!string.IsNullOrWhiteSpace(listTitle))
                    {
                        listTitle += " - ";
                    }
                    listTitle += cat.CategoryName;
                }
            }

            WebUi.ViewModels.PagingInfo pagingInf = new ViewModels.PagingInfo();
            int startRow = (page.Value - 1) * pagingInf.ItemsPerPage + 1;

            GeneralDatabaseList list =
                DomainModel.Repository.Sql.Products.GetByCategory(
                    WebUi.Models.AppCulture.CurrentCulture.CultureId,
                    categoryId,
                    parentId,
                    startRow,
                    startRow + pagingInf.ItemsPerPage - 1,
                    sort.Value);

            pagingInf.CurrentSortOption = sort.Value;
            pagingInf.CurrentPage       = page.Value;
            pagingInf.TotalItems        = list.TotalCount;
            pagingInf.listTitle         = listTitle;

            ViewData[ViewModels.ViewDataKeys.ListPagingDetails] = pagingInf;

            return(View(list.List));
        }