Skip to content

Commit e124d57

Browse files
author
kadir.avci
committed
Created ServiceLayer, Added more functionalities
1 parent fb2ba1c commit e124d57

File tree

64 files changed

+2720
-1757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2720
-1757
lines changed

Diff for: .vs/VueJsTutorial/DesignTimeBuild/.dtbcache

0 Bytes
Binary file not shown.

Diff for: Common/Helpers/EnumHelper.cs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Common.Helpers
8+
{
9+
public class EnumHelper
10+
{
11+
12+
public static int GetValueOfEnum(string name, string value)
13+
{
14+
name = replaceTurkishCharacters(name);
15+
var val = 0;
16+
17+
try
18+
{
19+
val = Convert.ToInt32(Enum.Parse(Type.GetType(name), value));
20+
}
21+
catch (Exception ex)
22+
{
23+
var msg = ex.Message;
24+
}
25+
26+
return val;
27+
}
28+
29+
public static string replaceTurkishCharacters(string text)
30+
{
31+
var message = text;
32+
var oldValue = new char[] { 'ö', 'Ö', 'ü', 'Ü', 'ç', 'Ç', 'İ', 'ı', 'Ğ', 'ğ', 'Ş', 'ş' };
33+
var newValue = new char[] { 'o', 'O', 'u', 'U', 'c', 'C', 'I', 'i', 'G', 'g', 'S', 's' };
34+
35+
for (int i = 0; i < oldValue.Length; i++)
36+
{
37+
message = message.Replace(oldValue[i], newValue[i]);
38+
message = message.Replace(" ", "");
39+
}
40+
41+
string a = message.Substring(0, 1);
42+
43+
message = a.ToUpper() + message.Substring(1, message.Length - 1).ToLower();
44+
45+
return message.Trim();
46+
}
47+
}
48+
}

Diff for: Common/obj/Common.csproj.nuget.g.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
88
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Kavci\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder</NuGetPackageFolders>
99
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
10-
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.3.0</NuGetToolVersion>
10+
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.3.1</NuGetToolVersion>
1111
</PropertyGroup>
1212
<PropertyGroup>
1313
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Common.deps.json
22
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Common.dll
33
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Common.pdb
4+
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Hosting.Abstractions.dll
45
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Html.Abstractions.dll
6+
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Mvc.Core.dll
57
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Mvc.ViewFeatures.dll
68
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Razor.dll
9+
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Hosting.Abstractions.xml
710
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Html.Abstractions.xml
11+
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Mvc.Core.xml
812
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Mvc.ViewFeatures.xml
913
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Razor.xml
1014
D:\Development\Tutorials\VueJsTutorial\Common\obj\Debug\netcoreapp2.2\Common.csprojAssemblyReference.cache
@@ -13,7 +17,3 @@ D:\Development\Tutorials\VueJsTutorial\Common\obj\Debug\netcoreapp2.2\Common.Ass
1317
D:\Development\Tutorials\VueJsTutorial\Common\obj\Debug\netcoreapp2.2\Common.csproj.CopyComplete
1418
D:\Development\Tutorials\VueJsTutorial\Common\obj\Debug\netcoreapp2.2\Common.dll
1519
D:\Development\Tutorials\VueJsTutorial\Common\obj\Debug\netcoreapp2.2\Common.pdb
16-
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Hosting.Abstractions.dll
17-
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Hosting.Abstractions.xml
18-
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Mvc.Core.dll
19-
D:\Development\Tutorials\VueJsTutorial\Common\bin\Debug\netcoreapp2.2\Microsoft.AspNetCore.Mvc.Core.xml

Diff for: Data/.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# EF1000: Possible SQL injection vulnerability.
4+
dotnet_diagnostic.EF1000.severity = warning

Diff for: Data/Data.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
<ItemGroup>
2929
<ProjectReference Include="..\Model\Model.csproj" />
30+
<ProjectReference Include="..\RazorTable\RazorTable.csproj" />
3031
</ItemGroup>
3132

3233
</Project>

Diff for: Data/Interfaces/IMenuService.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Data.Repository;
2+
using Model.Models;
3+
using RazorTable.Dto;
4+
using System.Collections.Generic;
5+
using System.Threading.Tasks;
6+
7+
namespace Data.Interfaces
8+
{
9+
public interface IMenuService : IRepository<Menu>
10+
{
11+
Task<IEnumerable<Menu>> GetAllMenus();
12+
13+
Task<IEnumerable<Menu>> GetAllMenusWithOptions(int page, List<SearchObj> searchParameters, List<SortObj> sortParameters);
14+
}
15+
}

Diff for: Data/Repository/IRepository.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IRepository<T> where T : class
1212
{
1313
void Add(T entity);
1414

15-
void AddRange(IEnumerable<T> list);
15+
void AddRange(IQueryable<T> list);
1616

1717
void Update(T entity);
1818

@@ -22,7 +22,7 @@ public interface IRepository<T> where T : class
2222

2323
void Delete(int id);
2424

25-
void DeleteRange(IEnumerable<T> list);
25+
void DeleteRange(IQueryable<T> list);
2626

2727
void Attach(T Entity);
2828

@@ -52,10 +52,6 @@ public interface IRepository<T> where T : class
5252

5353
IQueryable<T> QueryNoTracking(Expression<Func<T, bool>> expression);
5454

55-
IQueryable<T> Include(Expression<Func<T, object>> expression);
56-
57-
IQueryable<T> Include(params Expression<Func<T, object>>[] includes);
58-
5955
IList<T> SqlQuery(string query);
6056

6157
IList<dynamic> GetQueryResult(string query);

Diff for: Data/Repository/Repository.cs

+10-31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.EntityFrameworkCore;
2+
using Model.Models;
23
using System;
34
using System.Collections.Generic;
45
using System.ComponentModel;
@@ -11,27 +12,27 @@ namespace Data.Repository
1112
{
1213
public class Repository<T> : IRepository<T> where T : class
1314
{
14-
private readonly DbContext _context;
15+
protected AppDbContext DbContext;
16+
protected readonly DbContext _context;
1517
private readonly DbSet<T> _dbSet;
16-
protected Model.Models.AppDbContext DbContext;
1718

18-
public Repository(Model.Models.AppDbContext context)
19+
public Repository(AppDbContext context)
1920
{
2021
if (context == null)
2122
{
22-
context = new Model.Models.AppDbContext();
23+
context = new AppDbContext();
2324
}
2425

2526
_context = context;
2627
_dbSet = _context.Set<T>();
2728
}
2829

29-
public void Add(T entity)
30+
public virtual void Add(T entity)
3031
{
3132
_dbSet.Add(entity);
3233
}
3334

34-
public void AddRange(IEnumerable<T> list)
35+
public void AddRange(IQueryable<T> list)
3536
{
3637
_dbSet.AddRange(list);
3738
}
@@ -85,7 +86,7 @@ public void Delete(T entity)
8586
}
8687
}
8788

88-
public void DeleteRange(IEnumerable<T> list)
89+
public void DeleteRange(IQueryable<T> list)
8990
{
9091
_dbSet.RemoveRange(list);
9192
}
@@ -267,25 +268,6 @@ public IQueryable<T> QueryNoTracking(Expression<Func<T, bool>> expression)
267268
}
268269
}
269270

270-
public IQueryable<T> Include(Expression<Func<T, object>> expression)
271-
{
272-
_context.ChangeTracker.LazyLoadingEnabled = false;
273-
274-
return _dbSet.Include(expression);
275-
}
276-
277-
public IQueryable<T> Include(params Expression<Func<T, object>>[] includes)
278-
{
279-
_context.ChangeTracker.LazyLoadingEnabled = false;
280-
281-
foreach (var include in includes)
282-
{
283-
_dbSet.Include(include);
284-
}
285-
286-
return _dbSet;
287-
}
288-
289271
public virtual void LazyLoading(bool lazyLoadingEnabled, bool proxyCreationEnabled, bool autoDetectChanges)
290272
{
291273
_context.ChangeTracker.LazyLoadingEnabled = lazyLoadingEnabled;
@@ -319,16 +301,13 @@ public DataTable DataTableQuery(string query)
319301
return ConvertToDataTable(list);
320302
}
321303

322-
public int ExecQuery(string query, params object[] parameters)
323-
{
324-
return DbContext.Database.ExecuteSqlCommand("EXEC " + query, parameters);
325-
}
304+
public int ExecQuery(string query, params object[] parameters) => DbContext.Database.ExecuteSqlCommand("EXEC " + query, parameters);
326305

327306
public bool HasFlag(string field)
328307
{
329308
var hasFlag = false;
330309
var genericTypeArguments = _dbSet.GetType().GenericTypeArguments;
331-
310+
332311
if (genericTypeArguments.Any())
333312
{
334313
var fields = ((System.Reflection.TypeInfo)(_dbSet.GetType().GenericTypeArguments.FirstOrDefault())).DeclaredFields;

Diff for: Data/Services/BaseService.cs

-17
This file was deleted.

Diff for: Data/Services/IApprovalSystemService.cs

-30
This file was deleted.

Diff for: Data/Services/IBaseService.cs

-45
This file was deleted.

Diff for: Data/Services/IProductService.cs

-14
This file was deleted.

Diff for: Data/Services/MenuService.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using Data.Interfaces;
4+
using Data.Repository;
5+
using Microsoft.EntityFrameworkCore;
6+
using Model.Models;
7+
using RazorTable.Dto;
8+
9+
namespace Data.Services
10+
{
11+
public class MenuService : Repository<Menu>, IMenuService
12+
{
13+
private readonly Repository<Menu> _repository;
14+
15+
public MenuService(Repository<Menu> repository, AppDbContext context) : base(context)
16+
{
17+
_repository = repository;
18+
}
19+
20+
public override void Add(Menu menu)
21+
{
22+
_repository.Add(menu);
23+
}
24+
25+
public async Task<IEnumerable<Menu>> GetAllMenus()
26+
{
27+
return await _repository.Query().ToListAsync();
28+
}
29+
30+
public async Task<IEnumerable<Menu>> GetAllMenusWithOptions(int page, List<SearchObj> searchParameters, List<SortObj> sortParameters)
31+
{
32+
return await _repository.Query().ToListAsync();
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)