コード例 #1
0
        public IActionResult ChangePage(AddedCategoriesViewModel model, int id)
        {
            this.StartUp();
            var returnModel = this.addedCategoriesService.ChangeActivePage(model, id);

            return(this.View(returnModel));
        }
コード例 #2
0
        public IActionResult EditCategory(AddedCategoriesViewModel model, string id)
        {
            this.StartUp();
            var returnModel = this.addedCategoriesService.GetCategoryData(id);

            this.TempData["editCategoryId"] = id;
            return(this.View("EditCategory", returnModel));
        }
コード例 #3
0
        public IActionResult DeleteCategory(AddedCategoriesViewModel model, string id)
        {
            this.StartUp();
            var returnModel = this.addedCategoriesService.DeleteCategory(this.userId, model, id);

            this.ViewData["message"] = "Успешно премахнат жанр!";
            return(this.View("Index", returnModel));
        }
コード例 #4
0
        public AddedCategoriesViewModel DeleteCategory(string userId, AddedCategoriesViewModel model, string categoryId)
        {
            var category = this.context.Categories.FirstOrDefault(c => c.Id == categoryId);

            category.DeletedOn = DateTime.UtcNow;
            this.context.SaveChanges();

            return(this.PreparedPage());
        }
コード例 #5
0
        public AddedCategoriesViewModel GetAllAddedCategories(AddedCategoriesViewModel model)
        {
            var genreName        = model.SearchCategory.Name;
            var sortMethodId     = model.SortMethodId;
            var countBooksOfPage = model.CountCategoriesOfPage;
            var currentPage      = model.CurrentPage;

            var categories = this.context.Categories
                             .Where(c => c.DeletedOn == null)
                             .OrderBy(c => c.Name)
                             .Select(c => new CategoryViewModel()
            {
                Id         = c.Id,
                Name       = c.Name,
                ParentId   = c.ParentCategoryId,
                ParentName = c.ParentCategory.Name,
            });

            categories = this.SelectGenres(genreName, categories);
            categories = this.SortGenres(sortMethodId, categories);

            int maxCountPage = categories.Count() / countBooksOfPage;

            if (categories.Count() % countBooksOfPage != 0)
            {
                maxCountPage++;
            }


            var viewCategories = categories.Skip((currentPage - 1) * countBooksOfPage)
                                 .Take(countBooksOfPage)
                                 .ToList();
            var returnModel = new AddedCategoriesViewModel()
            {
                Categories                = viewCategories,
                CountCategoriesOfPage     = model.CountCategoriesOfPage,
                CountCategoriesOfPageList = model.CountCategoriesOfPageList,
                SortMethodId              = model.SortMethodId,
                SearchCategory            = model.SearchCategory,
            };

            return(returnModel);
        }
コード例 #6
0
 public AddedCategoriesViewModel ChangeActivePage(AddedCategoriesViewModel model, int id)
 {
     model.CurrentPage = id;
     return(this.GetAllAddedCategories(model));
 }
コード例 #7
0
        public AddedCategoriesViewModel PreparedPage()
        {
            var model = new AddedCategoriesViewModel();

            return(this.GetAllAddedCategories(model));
        }