-
Notifications
You must be signed in to change notification settings - Fork 0
/
One Interface Multiple Definition using func.cs
172 lines (130 loc) · 5.59 KB
/
One Interface Multiple Definition using func.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using GlobalServe.Core.StandardModels;
using GlobalServe.Core.ViewModels;
using GlobalServe.Data.Context;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace GlobalServe.Core.Services.Interfaces
{
public abstract class BasketAbstract
{
protected readonly ApplicationUserService _userService;
protected GlobalServeDbContext _dbContext;
protected StandardApiResponse standardApiResponse;
protected readonly ConfigurationService _configurationService;
public BasketAbstract()
{
}
public BasketAbstract(GlobalServeDbContext dbContext, ConfigurationService configurationService, ApplicationUserService userService)
{
_userService = userService;
_configurationService = configurationService;
_dbContext = dbContext;
standardApiResponse = new StandardApiResponse();
}
public abstract bool AuthenticateItems(BasketItemRequestModel item);
}
public class CatalogItem : BasketAbstract
{
public CatalogItem(){}
public CatalogItem(GlobalServeDbContext dbContext, ConfigurationService configurationService, ApplicationUserService userService) :base(dbContext, configurationService, userService)
{
}
public override bool AuthenticateItems(BasketItemRequestModel item)
{
var authenticatePartItem = _dbContext.TblCatalogParts
.Where(x => x.CatalogPartId == item.CatalogPartId
&& x.CustomerId == _userService.CustomerId
&& x.IsActive == true)
.SingleOrDefault();
if (authenticatePartItem != null)
return true;
else
return false;
}
}
public class StandardItem : BasketAbstract
{
public StandardItem()
{
}
public StandardItem(GlobalServeDbContext dbContext, ConfigurationService configurationService, ApplicationUserService userService) : base(dbContext, configurationService, userService)
{
}
public override bool AuthenticateItems(BasketItemRequestModel item)
{
var authenticateStandardItem = _dbContext.TblCatalogStandards
.Where(x => x.CatalogStandardId == item.CatalogStandardId
&& x.CustomerId == _userService.CustomerId
&& x.IsActive == true)
.SingleOrDefault();
if (authenticateStandardItem != null)
return true;
else
return false;
}
}
public enum ItemType
{
QuoteId,
CatalogId,
StandardId
}
public class BasketAbstractService
{
private readonly Func<BasketItemRequestModel, BasketAbstract> basketAbstract;
//private readonly BasketAbstract basketAbstract;
public BasketAbstractService(Func<BasketItemRequestModel, BasketAbstract> basketAbstract)
{
this.basketAbstract = basketAbstract;
}
public void chk(BasketItemRequestModel item)
{
try
{
//var chk = basketAbstract.AuthenticateItems(item);
string name = basketAbstract.GetType().Name;
string assembly = basketAbstract.GetType().Assembly.ToString();
string fname = basketAbstract.GetType().FullName;
string returntype = basketAbstract.Method.ReturnType.ToString();
string type = basketAbstract.Method.ReflectedType.Name;
string targettype = basketAbstract.Target.GetType().Name;
var chk = basketAbstract(item).AuthenticateItems(item);
string name1 = basketAbstract.GetType().Name;
string assembly1 = basketAbstract.GetType().Assembly.ToString();
string fname1 = basketAbstract.GetType().FullName;
string returntype1 = basketAbstract.Method.ReturnType.ToString();
string type1 = basketAbstract.Method.ReflectedType.Name;
string targettype1 = basketAbstract.Target.GetType().Name;
}
catch (Exception ex)
{
}
}
}
}
services.AddScoped<BasketAbstractService>();
services.AddScoped<CatalogItem>();
//services.AddScoped<BasketAbstract,CatalogItem>();
//services.AddScoped<BasketAbstract, StandardItem>();
services.AddScoped<Func<BasketItemRequestModel, BasketAbstract>>(serviceProvider => key =>
{
if (key.CatalogPartId != 0)
{
return serviceProvider.GetService<CatalogItem>();
}
else
{
return serviceProvider.GetService<CatalogItem>();
}
});
[HttpPost("/chk")]
public IActionResult ckh(BasketItemRequestModel model)
{
service.chk(model);
return Ok();
}