CompanyService.cs
2.02 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using HHECS.Dal.Repository;
using HHECS.Infrastructure.Json;
using HHECS.Model.Entities;
using System;
using System.Linq;
using System.Linq.Expressions;
namespace HHECS.Application.Service
{
public class CompanyService : BaseService
{
public string Load(Company entity, PageReq pageRequest)
{
return Execute(() =>
{
using var companyRepository = new CompanyRepository();
var query = companyRepository.Where(GetExpression(entity));
var result = query.OrderByDescending(a => a.Created).Page(pageRequest.page, pageRequest.limit).ToList();
Response.Result = result;
Response.Count = query.Count();
return Response.ToJson();
});
}
private Expression<Func<Company, bool>> GetExpression(Company entity)
{
Expression<Func<Company, bool>> filter = t => true;
if (!string.IsNullOrWhiteSpace(entity.Name))
{
filter = filter.And(x => x.Name.Contains(entity.Name));
}
return filter;
}
public string Ins(Company entity, User user)
{
return Execute(() =>
{
entity.CreatedBy = user.UserCode;
entity.Created = DateTime.Now;
new CompanyRepository().Insert(entity);
return Response.ToJson();
});
}
public string Upd(Company entity, User user)
{
return Execute(() =>
{
entity.UpdatedBy = user.UserCode;
entity.Updated = DateTime.Now;
new CompanyRepository().InsertOrUpdate(entity);
return Response.ToJson();
});
}
public string DelByIds(int[] ids)
{
return Execute(() =>
{
new CompanyRepository().Delete(t => ids.Contains(t.Id));
return Response.ToJson();
});
}
}
}