| #endregion | #endregion | ||||
| #region Model to DTO | #region Model to DTO | ||||
| CreateMap<Category, TreeCategoryItem>(); | |||||
| #endregion | #endregion | ||||
| } | } | ||||
| } | } |
| return dto; | return dto; | ||||
| } | } | ||||
| public async Task<List<TreeCategoryItem>> GetAllCategories() | |||||
| { | |||||
| var res = await _context.Categories.Include(k => k.ParentCategory).ToListAsync(); | |||||
| return _mapper.Map<List<TreeCategoryItem>>(res); | |||||
| } | |||||
| } | } | ||||
| } | } |
| Task<CategoriesParentChild> GetRootCategories(int userId,int categoryId); | Task<CategoriesParentChild> GetRootCategories(int userId,int categoryId); | ||||
| Task<Category> GetCategoryEntityById(int? id); | Task<Category> GetCategoryEntityById(int? id); | ||||
| Task<List<IsGrantedCategory>> GetCategories(int userId); | Task<List<IsGrantedCategory>> GetCategories(int userId); | ||||
| Task<List<TreeCategoryItem>> GetAllCategories(); | |||||
| } | } | ||||
| } | } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Diligent.WebAPI.Contracts.DTOs.Categories | |||||
| { | |||||
| public class TreeCategoryItem | |||||
| { | |||||
| public int Id { get; set; } | |||||
| public string Name { get; set; } | |||||
| public TreeCategoryItem? ParentCategory { get; set; } = null; | |||||
| } | |||||
| } |
| [HttpGet("granted-categories")] | [HttpGet("granted-categories")] | ||||
| public async Task<IActionResult> GetCategories(int userId) => | public async Task<IActionResult> GetCategories(int userId) => | ||||
| Ok(await _categoryService.GetCategories(userId)); | Ok(await _categoryService.GetCategories(userId)); | ||||
| [HttpGet("all-categories")] | |||||
| public async Task<IActionResult> GetAllCategories() => | |||||
| Ok(await _categoryService.GetAllCategories()); | |||||
| } | } | ||||
| } | } |