Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Business/Abstract/IAuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
using Entities.DTOs;
using System;
using System.Text;
using System.Threading.Tasks;

namespace Business.Abstract
{

public interface IAuthService
{
IDataResult<User> Register(UserForRegisterDto userForRegisterDto, string password);
IDataResult<User> Login(UserForLoginDto userForLoginDto);
IResult UserExists(string email);
IDataResult<AccessToken> CreateAccessToken(User user);
Task<IDataResult<User>> RegisterAsync(UserForRegisterDto userForRegisterDto, string password);
Task<IDataResult<User>> LoginAsync(UserForLoginDto userForLoginDto);
Task<IResult> UserExistsAsync(string email);
Task<IDataResult<AccessToken>> CreateAccessTokenAsync(User user);
}
}
5 changes: 3 additions & 2 deletions Business/Abstract/ICategoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Business.Abstract
{
public interface ICategoryService
{
IDataResult<List<Category>> GetAll();
IDataResult<Category> GetById(int categoryId);
Task<IDataResult<List<Category>>> GetAllAsync();
Task<IDataResult<Category>> GetByIdAsync(int categoryId);
}
}
19 changes: 10 additions & 9 deletions Business/Abstract/IProductService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Business.Abstract
{
public interface IProductService
{
IDataResult<List<Product>> GetAll();
IDataResult<List<Product>> GetAllByCategoryId(int id);
IDataResult<List<Product>> GetByUnitPrice(decimal min, decimal max);
IDataResult<List<ProductDetailDto>> GetProductDetails();
IDataResult<Product> GetById(int productId);
IResult Add(Product product);
IResult Update(Product product);

IResult AddTransactionalTest(Product product);
Task<IDataResult<List<Product>>> GetAllAsync();
Task<IDataResult<List<Product>>> GetAllByCategoryIdAsync(int id);
Task<IDataResult<List<Product>>> GetByUnitPriceAsync(decimal min, decimal max);
Task<IDataResult<List<ProductDetailDto>>> GetProductDetailsAsync();
Task<IDataResult<Product>> GetByIdAsync(int productId);
Task<IResult> AddAsync(Product product);
Task<IResult> UpdateAsync(Product product);
Task<IResult> AddTransactionalTestAsync(Product product);

//RESTFUL --> HTTP -->
}
Expand Down
7 changes: 4 additions & 3 deletions Business/Abstract/IUserService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Core.Entities.Concrete;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Business.Abstract
{
public interface IUserService
{
List<OperationClaim> GetClaims(User user);
void Add(User user);
User GetByMail(string email);
Task<List<OperationClaim>> GetClaimsAsync(User user);
Task AddAsync(User user);
Task<User> GetByMailAsync(string email);
}
}
17 changes: 9 additions & 8 deletions Business/Concrete/AuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Core.Utilities.Security.Hashing;
using Core.Utilities.Security.JWT;
using Entities.DTOs;
using System.Threading.Tasks;

namespace Business.Concrete
{
Expand All @@ -18,7 +19,7 @@ public AuthManager(IUserService userService, ITokenHelper tokenHelper)
_tokenHelper = tokenHelper;
}

public IDataResult<User> Register(UserForRegisterDto userForRegisterDto, string password)
public async Task<IDataResult<User>> RegisterAsync(UserForRegisterDto userForRegisterDto, string password)
{
byte[] passwordHash, passwordSalt;
HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);
Expand All @@ -31,13 +32,13 @@ public IDataResult<User> Register(UserForRegisterDto userForRegisterDto, string
PasswordSalt = passwordSalt,
Status = true
};
_userService.Add(user);
await _userService.AddAsync(user);
return new SuccessDataResult<User>(user, "Kayıt oldu");
}

public IDataResult<User> Login(UserForLoginDto userForLoginDto)
public async Task<IDataResult<User>> LoginAsync(UserForLoginDto userForLoginDto)
{
var userToCheck = _userService.GetByMail(userForLoginDto.Email);
var userToCheck = await _userService.GetByMailAsync(userForLoginDto.Email);
if (userToCheck == null)
{
return new ErrorDataResult<User>("Kullanıcı bulunamadı");
Expand All @@ -51,18 +52,18 @@ public IDataResult<User> Login(UserForLoginDto userForLoginDto)
return new SuccessDataResult<User>(userToCheck, "Başarılı giriş");
}

public IResult UserExists(string email)
public async Task<IResult> UserExistsAsync(string email)
{
if (_userService.GetByMail(email) != null)
if (await _userService.GetByMailAsync(email) != null)
{
return new ErrorResult("Kullanıcı mevcut");
}
return new SuccessResult();
}

public IDataResult<AccessToken> CreateAccessToken(User user)
public async Task<IDataResult<AccessToken>> CreateAccessTokenAsync(User user)
{
var claims = _userService.GetClaims(user);
var claims =await _userService.GetClaimsAsync(user);
var accessToken = _tokenHelper.CreateToken(user, claims);
return new SuccessDataResult<AccessToken>(accessToken, "Token oluşturuldu");
}
Expand Down
9 changes: 5 additions & 4 deletions Business/Concrete/CategoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Business.Concrete
{
Expand All @@ -17,16 +18,16 @@ public CategoryManager(ICategoryDal categoryDal)
_categoryDal = categoryDal;
}

public IDataResult<List<Category>> GetAll()
public async Task<IDataResult<List<Category>>> GetAllAsync()
{
//İş kodları
return new SuccessDataResult<List<Category>>(_categoryDal.GetAll());
return new SuccessDataResult<List<Category>>(await _categoryDal.GetAllAsync());
}

//Select * from Categories where CategoryId = 3
public IDataResult<Category> GetById(int categoryId)
public async Task<IDataResult<Category>> GetByIdAsync(int categoryId)
{
return new SuccessDataResult<Category>(_categoryDal.Get(c=>c.CategoryId == categoryId));
return new SuccessDataResult<Category>(await _categoryDal.GetAsync(c=>c.CategoryId == categoryId));
}
}
}
57 changes: 29 additions & 28 deletions Business/Concrete/ProductManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Concrete
{
Expand All @@ -37,99 +38,99 @@ public ProductManager(IProductDal productDal,ICategoryService categoryService)
[SecuredOperation("product.add,admin")]
[ValidationAspect(typeof(ProductValidator))]
[CacheRemoveAspect("IProductService.Get")]
public IResult Add(Product product)
public async Task<IResult> AddAsync(Product product)
{

//Aynı isimde ürün eklenemez
//Eğer mevcut kategori sayısı 15'i geçtiyse sisteme yeni ürün eklenemez. ve
IResult result = BusinessRules.Run(CheckIfProductNameExists(product.ProductName),
CheckIfProductCountOfCategoryCorrect(product.CategoryId), CheckIfCategoryLimitExceded());
IResult result = BusinessRules.Run(await CheckIfProductNameExistsAsync(product.ProductName),
await CheckIfProductCountOfCategoryCorrectAsync(product.CategoryId),await CheckIfCategoryLimitExcededAsync());

if (result != null)
{
return result;
}

_productDal.Add(product);
await _productDal.AddAsync(product);

return new SuccessResult(Messages.ProductAdded);

}


[CacheAspect] //key,value
public IDataResult<List<Product>> GetAll()
public async Task<IDataResult<List<Product>>> GetAllAsync()
{
if (DateTime.Now.Hour == 1)
{
return new ErrorDataResult<List<Product>>(Messages.MaintenanceTime);
}

return new SuccessDataResult<List<Product>>(_productDal.GetAll(), Messages.ProductsListed);
return new SuccessDataResult<List<Product>>(await _productDal.GetAllAsync(), Messages.ProductsListed);
}

public IDataResult<List<Product>> GetAllByCategoryId(int id)
public async Task<IDataResult<List<Product>>> GetAllByCategoryIdAsync(int id)
{
return new SuccessDataResult<List<Product>>(_productDal.GetAll(p => p.CategoryId == id));
return new SuccessDataResult<List<Product>>(await _productDal.GetAllAsync(p => p.CategoryId == id));
}

[CacheAspect]
//[PerformanceAspect(5)]
public IDataResult<Product> GetById(int productId)
public async Task<IDataResult<Product>> GetByIdAsync(int productId)
{
return new SuccessDataResult<Product>(_productDal.Get(p => p.ProductId == productId));
return new SuccessDataResult<Product>(await _productDal.GetAsync(p => p.ProductId == productId));
}

public IDataResult<List<Product>> GetByUnitPrice(decimal min, decimal max)
public async Task<IDataResult<List<Product>>> GetByUnitPriceAsync(decimal min, decimal max)
{
return new SuccessDataResult<List<Product>>(_productDal.GetAll(p => p.UnitPrice >= min && p.UnitPrice <= max));
return new SuccessDataResult<List<Product>>(await _productDal.GetAllAsync(p => p.UnitPrice >= min && p.UnitPrice <= max));
}

public IDataResult<List<ProductDetailDto>> GetProductDetails()
public async Task<IDataResult<List<ProductDetailDto>>> GetProductDetailsAsync()
{
if (DateTime.Now.Hour == 23)
{
return new ErrorDataResult<List<ProductDetailDto>>(Messages.MaintenanceTime);
}
return new SuccessDataResult<List<ProductDetailDto>>(_productDal.GetProductDetails());
return new SuccessDataResult<List<ProductDetailDto>>(await _productDal.GetProductDetailsAsync());
}

[ValidationAspect(typeof(ProductValidator))]
[CacheRemoveAspect("IProductService.Get")]
public IResult Update(Product product)
public async Task<IResult> UpdateAsync(Product product)
{
var result = _productDal.GetAll(p => p.CategoryId == product.CategoryId).Count;
if (result >= 10)
var result =await _productDal.GetAllAsync(p => p.CategoryId == product.CategoryId);
if (result.Count >= 10)
{
return new ErrorResult(Messages.ProductCountOfCategoryError);
}
throw new NotImplementedException();
}

private IResult CheckIfProductCountOfCategoryCorrect(int categoryId)
private async Task<IResult> CheckIfProductCountOfCategoryCorrectAsync(int categoryId)
{
//Select count(*) from products where categoryId=1
var result = _productDal.GetAll(p => p.CategoryId == categoryId).Count;
if (result >= 15)
var result = await _productDal.GetAllAsync(p => p.CategoryId == categoryId);
if (result.Count >= 15)
{
return new ErrorResult(Messages.ProductCountOfCategoryError);
}
return new SuccessResult();
}

private IResult CheckIfProductNameExists(string productName)
private async Task<Result> CheckIfProductNameExistsAsync(string productName)
{
var result = _productDal.GetAll(p => p.ProductName == productName).Any();
if (result)
var result = await _productDal.GetAllAsync(p => p.ProductName == productName);
if (result.Any())
{
return new ErrorResult(Messages.ProductNameAlreadyExists);
}
return new SuccessResult();
}

private IResult CheckIfCategoryLimitExceded()
private async Task<IResult> CheckIfCategoryLimitExcededAsync()
{
var result = _categoryService.GetAll();
var result =await _categoryService.GetAllAsync();
if (result.Data.Count>15)
{
return new ErrorResult(Messages.CategoryLimitExceded);
Expand All @@ -139,16 +140,16 @@ private IResult CheckIfCategoryLimitExceded()
}

//[TransactionScopeAspect]
public IResult AddTransactionalTest(Product product)
public async Task<IResult> AddTransactionalTestAsync(Product product)
{

Add(product);
await AddAsync(product);
if (product.UnitPrice < 10)
{
throw new Exception("");
}

Add(product);
await AddAsync(product);

return null;
}
Expand Down
13 changes: 7 additions & 6 deletions Business/Concrete/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Business.Concrete
{
Expand All @@ -16,19 +17,19 @@ public UserManager(IUserDal userDal)
_userDal = userDal;
}

public List<OperationClaim> GetClaims(User user)
public async Task<List<OperationClaim>> GetClaimsAsync(User user)
{
return _userDal.GetClaims(user);
return await _userDal.GetClaimsAsync(user);
}

public void Add(User user)
public async Task AddAsync(User user)
{
_userDal.Add(user);
await _userDal.AddAsync(user);
}

public User GetByMail(string email)
public async Task<User> GetByMailAsync(string email)
{
return _userDal.Get(u => u.Email == email);
return await _userDal.GetAsync(u => u.Email == email);
}
}
}
2 changes: 1 addition & 1 deletion Core/Aspects/Autofac/Caching/CacheAspect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CacheAspect(int duration = 60)
_cacheManager = ServiceTool.ServiceProvider.GetService<ICacheManager>();
}

public override void Intercept(IInvocation invocation)
public override void InterceptAsynchronous<TResult>(IInvocation invocation)
{
var methodName = string.Format($"{invocation.Method.ReflectedType.FullName}.{invocation.Method.Name}");
var arguments = invocation.Arguments.ToList();
Expand Down
1 change: 1 addition & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="Autofac" Version="6.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.0.0" />
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
<PackageReference Include="FluentValidation" Version="9.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
Expand Down
Loading