-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMenuService.cs
48 lines (42 loc) · 1.19 KB
/
MenuService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Data.Repository;
using Microsoft.EntityFrameworkCore;
using Model.Models;
using RazorTable.Dto;
using RazorTable.Generator;
using ServicePattern.Interface;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
namespace ServicePattern.Service
{
public class MenuService : Service<Menu>, IMenuService
{
private readonly IRepository<Menu> _repository;
public MenuService(IRepository<Menu> repository) : base(repository)
{
_repository = repository;
}
public override void Add(Menu menu)
{
_repository.Add(menu);
}
public async Task<IEnumerable<Menu>> GetAllMenus()
{
return await _repository.Query().ToListAsync();
}
public async Task<IEnumerable<Menu>> GetAllMenusWithOptions(int page, int size, List<SearchObj> searchParameters, List<SortObj> sortParameters)
{
var skip = page == 1 ? 0 : (page - 1) * size;
var searchQuery = SearchHelper.GenerateFromSearchObj(searchParameters, true);
var sorting = SortHelper.GenerateFromSortObj(sortParameters);
return await _repository
.Query()
.Where(searchQuery)
.OrderBy(sorting)
.Skip(skip)
.Take(size)
.ToListAsync();
}
}
}