コード例 #1
0
        public IActionResult Index()
        {
            var categories = _categoryService.GetAll().
                             Select(category => new CategoryListingModel
            {
                Name        = category.Name,
                Description = category.Description,
                Id          = category.Id,
                ImageUrl    = category.ImageUrl
            });

            var model = new CategoryIndexModel
            {
                CategoryList = categories
            };

            return(View(model));
        }
コード例 #2
0
        // GET: Categories
        public ActionResult Index()
        {
            var cim = new CategoryIndexModel
            {
                CategorieTabelList = null,
                CategorySelectList = new List <CategorySelectListModel>
                {
                    new CategorySelectListModel
                    {
                        CategoriesSelectList = db.Category.Where(c => c.ParentID == null).ToList(),
                        SelectedCategoryId   = 0
                    }
                }
            };

            //db.Category.Include(c => c.Category2).ToList();
            return(View(cim));
        }
コード例 #3
0
        public async Task <IActionResult> Index(int page = 1, int perPage = CategoriesPerPageDefaultValue)
        {
            var categories = await this.categoryService.GetAllAsQueryable <CategoryListingViewModel>();

            var pagesCount = (int)Math.Ceiling(categories.Count() / (decimal)perPage);

            if (page > pagesCount)
            {
                page = 1;
            }

            var model = new CategoryIndexModel()
            {
                PagesCount   = pagesCount,
                CurrentPage  = page,
                CategoryList = PaginationHelper
                               .CreateForPage(categories.OrderBy(f => f.NumberOfPosts), perPage, page),
            };

            return(this.View(model));
        }
コード例 #4
0
        public ActionResult Index(CategoryIndexModel model)
        {
            PopulateIndexModel(model);

            return View(model);
        }
コード例 #5
0
        public ActionResult Delete(Guid id)
        {
            var entity = CacheHelper.GetCategories().FirstOrDefault(i => i.Id == id);

            if (entity == null)
            {
                var indexModel = new CategoryIndexModel();
                PopulateIndexModel(indexModel);
                return JsonObject(true, BackendMessage.DeleteSuccessfull, new
                {
                    html = PartialViewToString("BaseView/Nhom/_list", indexModel)
                });
            }

            var res = ServiceHelper.Category.ExecuteDispose(s => s.DeleteCategory(id, PhysicalDataImagesFolderPath));

            if (res.Success)
            {
                var indexModel = new CategoryIndexModel();
                PopulateIndexModel(indexModel);
                return JsonObject(true, BackendMessage.DeleteSuccessfull, new
                {
                    html = PartialViewToString("BaseView/Nhom/_list", indexModel)
                });
            }

            var msg = res.Messages.FirstOrDefault();

            return JsonObject(false, string.IsNullOrWhiteSpace(msg) ? BackendMessage.ErrorOccure : msg.GetServiceMessageRes());
        }
コード例 #6
0
        protected void PopulateIndexModel(CategoryIndexModel model)
        {
            model.CategoryType = CategoryType;

            model.InitSortInfo();

            if (string.IsNullOrWhiteSpace(model.SortBy))
            {
                model.SortBy = CategoryType == CategoryType.Product ? "Code" : "Name";
            }

            var filter = new FindRequest
            {
                TextSearch = model.TextSearch,
                CategoryType = CategoryType,
                SortOption = new SortOption(new[] { new SortItem(model.SortBy, model.SortDirection.Value) })
            };

            var response = ServiceHelper.Category.ExecuteDispose(s => s.FindCategories(filter));

            var listTree = SiteUtils.BuildCategoryTreeFromList(response.Results);

            model.Results = listTree.MapList<CategoryModel>();

            model.Pagination.TotalRecords = response.TotalRecords;
        }
コード例 #7
0
        public ActionResult SaveImage(Guid categoryId, bool visible)
        {
            var imagePath = string.Empty;

            #region save image

            if (Request.Files["fileImage"] != null && !string.IsNullOrWhiteSpace(Request.Files["fileImage"].FileName))
            {
                var file = Request.Files["fileImage"];

                var extension = Path.GetExtension(file.FileName).ToStr();

                if (!SiteUtils.IsImageFile(file.FileName))
                {
                    return JsonObject(false, BackendMessage.FileTypeIsInvalid);
                }

                if (!SiteUtils.ImageSizeIsValid(file.ContentLength))
                {
                    return JsonObject(false, BackendMessage.FileMaxSize5MB);
                }

                imagePath = Guid.NewGuid() + extension;

                var filePath = PhysicalDataFilePath(imagePath);
                file.SaveAs(filePath);
            }

            #endregion

            var image = new CategoryImage
            {
                ImagePath = imagePath,
                CategoryId = categoryId,
                CreatedDate = DateTime.UtcNow,
                Visible = visible
            };

            image.InitId();

            var response = ServiceHelper.Category.ExecuteDispose(s => s.SaveImage(image));

            if (response.Success)
            {
                var cate = CacheHelper.GetCategories().FirstOrDefault(i => i.Id == categoryId);

                if (cate == null)
                {
                    return JsonObject(false, BackendMessage.CannotLoadData);
                }

                var indexModel = new CategoryIndexModel();

                PopulateIndexModel(indexModel);
                return JsonObject(true, BackendMessage.SaveDataSuccess, new
                {
                    categoryList = PartialViewToString("BaseView/Nhom/_list", indexModel),
                    imageList = PartialViewToString("BaseView/Nhom/ImageList/_imageList", cate.Map<Category, CategoryModel>())
                });
            }

            return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes());
        }
コード例 #8
0
        public ActionResult Save(CategoryModel model)
        {
            if (model.IsNew && !CanAdd)
            {
                return GetAddDeniedResult();
            }

            if (!model.IsNew && !CanUpdate)
            {
                return GetUpdateDeniedResult();
            }

            if (model.CategoryType != CategoryType.Product && model.CategoryType != CategoryType.UOM)
            {
                ModelState.Remove("Code");
            }

            if (!ModelState.IsValid)
            {
                return JsonObject(false, GetModelStateErrors());
            }

            var entity = model.Map<CategoryModel, Category>();

            if (entity.IsNew)
            {
                entity.InitId();
            }

            var request = new SaveRequest
            {
                Entity = entity
            };

            var res = ServiceHelper.Category.ExecuteDispose(s => s.SaveCategory(request));

            if (res.Success)
            {
                var indexModel = new CategoryIndexModel();
                PopulateIndexModel(indexModel);
                return JsonObject(true, BackendMessage.SaveDataSuccess, new
                {
                    html = PartialViewToString("BaseView/Nhom/_list", indexModel)
                });
            }

            var msg = res.Messages.FirstOrDefault();

            return JsonObject(false, string.IsNullOrWhiteSpace(msg) ? BackendMessage.ErrorOccure : msg.GetServiceMessageRes());
        }
コード例 #9
0
        public ActionResult GetList(CategoryIndexModel model)
        {
            PopulateIndexModel(model);

            return JsonObject(true, string.Empty, new
            {
                html = PartialViewToString("BaseView/Nhom/_list", model)
            });
        }
コード例 #10
0
        public ActionResult DeleteImage(Guid id, Guid categoryId)
        {
            var response = ServiceHelper.Category.ExecuteDispose(s => s.DeleteImage(id, PhysicalDataImagesFolderPath));

            if (response.Success)
            {
                var cate = CacheHelper.GetCategories().FirstOrDefault(i => i.Id == categoryId);

                if (cate == null)
                {
                    return JsonObject(false, BackendMessage.CannotLoadData);
                }

                var indexModel = new CategoryIndexModel();

                PopulateIndexModel(indexModel);
                return JsonObject(true, BackendMessage.DeleteSuccessfull, new
                {
                    categoryList = PartialViewToString("BaseView/Nhom/_list", indexModel),
                    imageList = PartialViewToString("BaseView/Nhom/ImageList/_imageList", cate.Map<Category, CategoryModel>())
                });
            }

            return JsonObject(false, response.Messages.FirstOrDefault().GetServiceMessageRes());
        }
コード例 #11
0
 private async Task PopulateCategoryPageAsync(CategoryIndexModel model)
 {
     model.Paging.PageClickFunction = "comdy.category.search({0})";
     model.PopulateCreatedUser(await _userService.GetReferencesAsync());
 }