Ejemplo n.º 1
0
        public ActionResult Index(int?categoryID, string searchTerm, int?pageNo)
        {
            var recordSize = (int)RecordSizeEnums.Size10;

            ProductsListingViewModel model = new ProductsListingViewModel
            {
                SearchTerm = searchTerm,

                Categories = CategoriesService.Instance.GetCategories()
            };

            List <int> selectedCategoryIDs = null;

            if (categoryID.HasValue && categoryID.Value > 0)
            {
                var selectedCategory = model.Categories.FirstOrDefault(x => x.ID == categoryID);

                if (selectedCategory != null)
                {
                    model.CategoryID = selectedCategory.ID;

                    var searchedCategories = CategoryHelpers.GetAllCategoryChildrens(selectedCategory, model.Categories);

                    selectedCategoryIDs = searchedCategories != null?searchedCategories.Select(x => x.ID).ToList() : null;
                }
            }

            model.Products = ProductsService.Instance.SearchProducts(selectedCategoryIDs, searchTerm, null, null, null, pageNo, recordSize, out int count);

            model.Pager = new Pager(count, pageNo, recordSize);

            return(View(model));
        }
Ejemplo n.º 2
0
        // GET: Vechicle/Create
        public ActionResult Create()
        {
            ViewBag.Type       = TypesHelpers.DropDownList();
            ViewBag.Categories = CategoryHelpers.DropDownList();

            return(View());
        }
Ejemplo n.º 3
0
        async public void Ignore_Category_Relation_Has_Other()
        {
            // Assign
            var result   = true;
            var category = new Category
            {
                Faqs = new List <Faq>
                {
                    new Faq(),
                    new Faq(),
                },
            };

            DbContextFake.SeedDb <IntranetApiContext>(c => c.Add(category));

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                // Act
                result = await CategoryHelpers.HasNoRelatedEntities(context.Categories.SingleOrDefault(), context, category.Faqs.First());
            }

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                // Assert
                Assert.False(result);
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var faq = await _context.Faqs
                      .Include(f => f.FaqTags)
                      .ThenInclude(ft => ft.Tag)
                      .Include(f => f.Category)
                      .ThenInclude(c => c.Faqs)
                      .SingleOrDefaultAsync(f => f.Id == id);

            if (faq.IsNull())
            {
                return(NotFound());
            }

            _context.Remove(faq);

            // If the category has no more related entities then delete the category as well
            if (await CategoryHelpers.HasNoRelatedEntities(faq.Category, _context, ignore: faq))
            {
                _context.Remove(faq.Category);
            }

            // If the tags has no more related entities then delete the category as well
            foreach (var tag in faq.FaqTags.Select(ft => ft.Tag))
            {
                if (await TagHelpers.HasNoRelatedEntities(tag, _context, ignore: faq.FaqTags))
                {
                    _context.Remove(tag);
                }
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public async Task <IEnumerable <CategoryViewModel> > GetCategoriesAsync(CategorySearchParams searchParams)
        {
            var specification = new CategoryFilterSpecification(searchParams);

            return(await _categoryRepository.ListAsync <CategoryViewModel>(specification,
                                                                           CategoryHelpers.GetCategoryMapperConfiguration()));
        }
        public ActionResult Index()
        {
            var viewModel = new HomeViewModel
            {
                DeploymentDomains = DeploymentDomainsHelpers.CreateDeploymentDomainsSelectMenu(DeploymentDomainsHelpers.GetDeploymentDomains()),
                Categories        = CategoryHelpers.CreateCategorySelectMenu(CategoryHelpers.GetCategories(DeploymentDomainsHelpers.GetDeploymentDomains().First().AuthorityId))
            };

            return(View(viewModel));
        }
Ejemplo n.º 7
0
        public ActionResult Index(string cat)
        {
            var articleListingPage = new ArticleListingPageViewModel
            {
                CurrentPage      = CurrentPage,
                Categories       = CategoryHelpers.GetCategorySelectionsByPath(),
                CurrentPageIndex = 1
            };

            SearchArticles(articleListingPage.CurrentPageIndex, CurrentPage.PageSize, cat, articleListingPage);
            return(View(articleListingPage));
        }
Ejemplo n.º 8
0
        // GET: Vechicle/Edit/5
        public ActionResult Edit(int id)
        {
            try
            {
                var vechicle = _vechicleService.GetEditView(id);

                ViewBag.Type       = TypesHelpers.DropDownList(vechicle.Type);
                ViewBag.Categories = CategoryHelpers.DropDownList(vechicle.Categories);

                return(View(vechicle));
            }
            catch
            {
                return(HttpNotFound());
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Add(CategoryView result)
        {
            if (await _categoryService.CheckIfCategoryExist(result.Name))
            {
                ModelState.AddModelError("", "Kategoria o tej nazwie już istnieje");
            }

            if (!ModelState.IsValid)
            {
                return(View(result));
            }

            await _categoryService.Create(CategoryHelpers.ConvertToModel(result));

            return(RedirectToAction("List"));
        }
Ejemplo n.º 10
0
        async public void No_Category_Relations()
        {
            // Assign
            var result = false;

            DbContextFake.SeedDb <IntranetApiContext>(c => c.Add(new Category()));

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                // Act
                result = await CategoryHelpers.HasNoRelatedEntities(context.Categories.SingleOrDefault(), context);
            }

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                // Assert
                Assert.True(result);
            }
        }
Ejemplo n.º 11
0
        async public void Ignore_Category_Relation_Has_No_Other()
        {
            // Assign
            var result = false;

            DbContextFake.SeedDb <IntranetApiContext>(c => c.Add(new Category()));
            DbContextFake.SeedDb <IntranetApiContext>(c => c.Add(new Faq()), ensureDeleted: false);
            DbContextFake.SeedDb <IntranetApiContext>(c => c.Faqs.SingleOrDefault().Category = c.Categories.SingleOrDefault(), ensureDeleted: false);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                // Act
                result = await CategoryHelpers.HasNoRelatedEntities(context.Categories.SingleOrDefault(), context, context.Faqs.SingleOrDefault());
            }

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                // Assert
                Assert.True(result);
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Edit(CategoryView result)
        {
            var category = await _categoryService.Get(result.Id);

            // sprawdzamy dopiero jeżeli tytuł się
            if (category.Name != result.Name)
            {
                if (await _categoryService.CheckIfCategoryExist(result.Name))
                {
                    ModelState.AddModelError("", "Kategoria o tej nazwie już istnieje");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(result));
            }

            await _categoryService.Update(CategoryHelpers.MergeViewWithModel(category, result));

            return(RedirectToAction("List"));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var policy = await _context.Policies
                         .Include(p => p.PolicyTags)
                         .ThenInclude(pt => pt.Tag)
                         .Include(p => p.Category)
                         .ThenInclude(c => c.Policies)
                         .SingleOrDefaultAsync(p => p.Id == id);

            if (policy.IsNull())
            {
                return(NotFound());
            }

            // TODO: Delete blob as well

            _context.Remove(policy);

            // If the category has no more related entities then delete the category as well
            if (await CategoryHelpers.HasNoRelatedEntities(policy.Category, _context, ignore: policy))
            {
                _context.Remove(policy.Category);
            }

            // If the tags has no more related entities then delete the tag as well
            foreach (var tag in policy.PolicyTags.Select(ft => ft.Tag))
            {
                if (await TagHelpers.HasNoRelatedEntities(tag, _context, ignore: policy.PolicyTags))
                {
                    _context.Remove(tag);
                }
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
        public JsonResult GetCategory(int laId, int categoryId)
        {
            var categoryData = CategoryHelpers.GetCategory(laId, categoryId);

            return(Json(categoryData, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 15
0
        public async Task <CategoryViewModel> GetCategoryByNameAsync(string categoryName)
        {
            var category = await _categoryRepository.GetByConditionAsync <CategoryViewModel>(x => x.Name == categoryName,
                                                                                             CategoryHelpers.GetCategoryMapperConfiguration());

            Guard.Against.NullItem(category, nameof(category));

            return(category);
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Edit(int Id)
        {
            var category = await _categoryService.Get(Id);

            return(View(CategoryHelpers.ConvertToView(category)));
        }