| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using Karsha_Site.Application.Interfaces.Contexts;
- using Karsha_Site.Common.Dto;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.EntityFrameworkCore.Storage;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace Karsha_Site.Application.Services.Common.Queries.GetMenuItem
- {
- public interface IGetMenuItemService
- {
- ResultDto<List<MenuItemDto>> Execute();
- }
-
- public class GetMenuItemService : IGetMenuItemService
- {
- private readonly IDataBaseContext _context;
- public GetMenuItemService(IDataBaseContext context)
- {
- _context = context;
- }
-
- public ResultDto<List<MenuItemDto>> Execute()
- {
- var category = _context.Categories
- .Include(p => p.SubCategories)
- //.Where(p=> p.ParentCategoryID == null)
- .ToList()
- .Select(p => new MenuItemDto
- {
- CatId = p.ID,
- Name = p.Title,
- Child = p.SubCategories.ToList().Select(child => new MenuItemDto
- {
- CatId = child.ID,
- Name = child.Title,
- }).ToList(),
- }).ToList();
-
- return new ResultDto<List<MenuItemDto>>()
- {
- Data = category,
- IsSuccess = true,
- };
- }
- }
-
- public class MenuItemDto
- {
- public long CatId { get; set; }
- public string Name { get; set; }
- public List<MenuItemDto> Child { get; set; }
- }
- }
|