Beispiel #1
0
        public virtual IActionResult CategoryAddPopup(DiscountModel.AddCategoryToDiscountModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            var discount = _discountService.GetDiscountById(model.DiscountId);

            if (discount == null)
            {
                throw new Exception("No discount found with the specified id");
            }

            if (model.SelectedCategoryIds != null)
            {
                foreach (var id in model.SelectedCategoryIds)
                {
                    var category = _categoryService.GetCategoryById(id);
                    if (category != null)
                    {
                        if (category.AppliedDiscounts.Count(d => d.Id == discount.Id) == 0)
                        {
                            category.AppliedDiscounts.Add(discount);
                        }

                        _categoryService.UpdateCategory(category);
                    }
                }
            }

            ViewBag.RefreshPage = true;
            return(View(model));
        }
Beispiel #2
0
        public ActionResult CategoryAddPopup(int discountId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            var model = new DiscountModel.AddCategoryToDiscountModel();

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> CategoryAddPopup(DiscountModel.AddCategoryToDiscountModel model)
        {
            var discount = await _discountService.GetDiscountById(model.DiscountId);

            if (discount == null)
            {
                throw new Exception("No discount found with the specified id");
            }

            if (model.SelectedCategoryIds != null)
            {
                await _discountViewModelService.InsertCategoryToDiscountModel(model);
            }
            ViewBag.RefreshPage = true;
            return(View(model));
        }
        public virtual void InsertCategoryToDiscountModel(DiscountModel.AddCategoryToDiscountModel model)
        {
            foreach (string id in model.SelectedCategoryIds)
            {
                var category = _categoryService.GetCategoryById(id);
                if (category != null)
                {
                    if (category.AppliedDiscounts.Count(d => d == model.DiscountId) == 0)
                    {
                        category.AppliedDiscounts.Add(model.DiscountId);
                    }

                    _categoryService.UpdateCategory(category);
                }
            }
        }
        public IActionResult CategoryAddPopupList(DataSourceRequest command, DiscountModel.AddCategoryToDiscountModel model, [FromServices] ICategoryService categoryService)
        {
            var categories = categoryService.GetAllCategories(model.SearchCategoryName,
                                                              pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true);
            var gridModel = new DataSourceResult
            {
                Data = categories.Select(x =>
                {
                    var categoryModel        = x.ToModel();
                    categoryModel.Breadcrumb = x.GetFormattedBreadCrumb(categoryService);
                    return(categoryModel);
                }),
                Total = categories.TotalCount
            };

            return(Json(gridModel));
        }
Beispiel #6
0
        public ActionResult CategoryAddPopupList(DataSourceRequest command, DiscountModel.AddCategoryToDiscountModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            var categories = _categoryService.GetAllCategories(model.SearchCategoryName,
                                                               0, command.Page - 1, command.PageSize, true);
            var gridModel = new DataSourceResult
            {
                Data = categories.Select(x =>
                {
                    var categoryModel        = x.ToModel();
                    categoryModel.Breadcrumb = x.GetFormattedBreadCrumb(_categoryService);
                    return(categoryModel);
                }),
                Total = categories.TotalCount
            };

            return(Json(gridModel));
        }
Beispiel #7
0
        public async Task <IActionResult> CategoryAddPopupList(DataSourceRequest command, DiscountModel.AddCategoryToDiscountModel model, [FromServices] ICategoryService categoryService)
        {
            var categories = await categoryService.GetAllCategories(model.SearchCategoryName,
                                                                    pageIndex : command.Page - 1, pageSize : command.PageSize, showHidden : true);

            var items = new List <CategoryModel>();

            foreach (var item in categories)
            {
                var categoryModel = item.ToModel();
                categoryModel.Breadcrumb = await categoryService.GetFormattedBreadCrumb(item);

                items.Add(categoryModel);
            }
            var gridModel = new DataSourceResult
            {
                Data  = items,
                Total = categories.TotalCount
            };

            return(Json(gridModel));
        }
Beispiel #8
0
        public IActionResult CategoryAddPopup(string discountId)
        {
            var model = new DiscountModel.AddCategoryToDiscountModel();

            return(View(model));
        }