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
20 changes: 20 additions & 0 deletions Business/Abstract/IAuthService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Core.Entities.Concrete;
using Core.Utilities.Results;
using Core.Utilities.Security.JWT;
using Entities.DTOs;
using System;
using System.Collections.Generic;
using System.Linq;
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);
}
}
22 changes: 22 additions & 0 deletions Business/Abstract/ICarImageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Core.Utilities.Results;
using Entities.Concrete;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Abstract
{
public interface ICarImageService
{

IDataResult<List<CarImage>> GetImagesByCarId(int id);
IDataResult<List<CarImage>> GetAll();
IDataResult<CarImage> GetById(int id);
IResult Add(IFormFile file, CarImage carImage);
IResult Update(IFormFile file, CarImage carImage);
IResult Delete(CarImage carImage);
}
}
16 changes: 12 additions & 4 deletions Business/Abstract/ICarService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Core.Utilities.Results;
using Entities.Concrete;
using Entities.DTOs;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -11,14 +12,21 @@ namespace Business.Abstract;

public interface ICarService
{

IDataResult<List<Car>> GetAll();
IDataResult<List<Car>> GetCarsByBrandId(int id);
IDataResult<List<Car>> GetCarsByColorId(int id);
IDataResult<Car> GetCarsById(int id);
public IDataResult<List<Car>> GetCarsByColorId(int id);
public IDataResult<List<Car>> GetCarsByBrandId(int id);
IDataResult<CarImageByDetailDto> GetCarImageByDetailDto(int id);
IDataResult<List<CarDetailDto>> GetDetail();
IDataResult<List<CarByBrandIdDto>> GetCarsByBrandIdDetail(int id);
IDataResult<List<CarByColorIdDto>> GetCarsByColorIdDetail(int id);

IDataResult<List<CarDetailDto>> GetCarByBrandAndColor(int brandId, int colorId);

IResult Add(Car car);
IResult Add(Car car);
IResult Update(Car car);
IResult Delete(Car car);
IDataResult<List<CarDetailDto>> GetDetail();


}
21 changes: 21 additions & 0 deletions Business/Abstract/ICreditCardService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Core.Utilities.Results;
using Entities.Concrete;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Abstract
{
public interface ICreditCardService
{
IDataResult<List<CreditCart>> GetAll();
IDataResult<CreditCart> GetById(string KrediKartiNo);

IResult Add(CreditCart creditCart);
IResult Update(CreditCart creditCart);
IResult Delete(CreditCart creditCart);
IResult Payment(string KrediKartiNo, string KartIsim, string SonKullanmaTarihi, string CVV);
}
}
3 changes: 3 additions & 0 deletions Business/Abstract/IRentalService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Core.Utilities.Results;
using Entities.Concrete;
using Entities.DTOs;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -17,4 +18,6 @@ public interface IRentalService
IDataResult<List<Rentals>> GetAll();

IDataResult<Rentals> GetById(int id);
IDataResult<List<Rentals>> GetRentalsByCarId(int id);
IDataResult<List<RentalDetailDto>> GetDetail();
}
17 changes: 11 additions & 6 deletions Business/Abstract/IUserService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Core.Utilities.Results;
using Core.Entities.Concrete;
using Core.Utilities.Results;
using Entities.Concrete;
using Entities.DTOs;
using System;
Expand All @@ -11,10 +12,14 @@ namespace Business.Abstract;

public interface IUserService
{
IResult Add(Users users);
IResult Delete(Users users);
IResult Update(Users users);
IDataResult<List<Users>> GetAll();
IDataResult<Users> GetById(int id);
IResult Add(User users);
IResult Delete(User users);
IResult Update(User users);
IDataResult<List<User>> GetAll();
IDataResult<User> GetById(int id);
IDataResult<List<CompanyAndUserDetailDto>> GetDetail();

List<OperationClaim> GetClaims(User user);
User GetByMail(string email);

}
41 changes: 41 additions & 0 deletions Business/BusinessAspects/Autofac/SecuredOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Business.Constants;
using Castle.DynamicProxy;
using Core.Extensions;
using Core.Utilities.Interceptors;
using Core.Utilities.IoC;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.BusinessAspects.Autofac
{
public class SecuredOperation : MethodInterception
{
private string[] _roles;
private IHttpContextAccessor _httpContextAccessor;

public SecuredOperation(string roles)
{
_roles = roles.Split(',');
_httpContextAccessor = ServiceTool.ServiceProvider.GetService<IHttpContextAccessor>();

}

protected override void OnBefore(IInvocation invocation)
{
var roleClaims = _httpContextAccessor.HttpContext.User.ClaimRoles();
foreach (var role in _roles)
{
if (roleClaims.Contains(role))
{
return;
}
}
throw new Exception(Messages.AuthorizationDenied);
}
}
}
76 changes: 76 additions & 0 deletions Business/Concrete/AuthManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Business.Abstract;
using Business.Constants;
using Core.Entities.Concrete;
using Core.Utilities.Results;
using Core.Utilities.Security.Hashing;
using Core.Utilities.Security.JWT;
using Entities.DTOs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Concrete
{
public class AuthManager : IAuthService
{
private IUserService _userService;
private ITokenHelper _tokenHelper;

public AuthManager(IUserService userService, ITokenHelper tokenHelper)
{
_userService = userService;
_tokenHelper = tokenHelper;
}

public IDataResult<User> Register(UserForRegisterDto userForRegisterDto, string password)
{
byte[] passwordHash, passwordSalt;
HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt);
var user = new User
{
Email = userForRegisterDto.Email,
FirstName = userForRegisterDto.FirstName,
LastName = userForRegisterDto.LastName,
PasswordHash = passwordHash,
PasswordSalt = passwordSalt,
Status = true
};
_userService.Add(user);
return new SuccessDataResult<User>(user, Messages.UserRegistered);
}

public IDataResult<User> Login(UserForLoginDto userForLoginDto)
{
var userToCheck = _userService.GetByMail(userForLoginDto.Email);
if (userToCheck == null)
{
return new ErrorDataResult<User>(Messages.UserNotFound);
}

if (!HashingHelper.VerifyPasswordHash(userForLoginDto.Password, userToCheck.PasswordHash, userToCheck.PasswordSalt))
{
return new ErrorDataResult<User>(Messages.PasswordError);
}

return new SuccessDataResult<User>(userToCheck, Messages.SuccessfulLogin);
}

public IResult UserExists(string email)
{
if (_userService.GetByMail(email) != null)
{
return new ErrorResult(Messages.UserAlreadyExists);
}
return new SuccessResult();
}

public IDataResult<AccessToken> CreateAccessToken(User user)
{
var claims = _userService.GetClaims(user);
var accessToken = _tokenHelper.CreateToken(user, claims);
return new SuccessDataResult<AccessToken>(accessToken, Messages.AccessTokenCreated);
}
}
}
120 changes: 120 additions & 0 deletions Business/Concrete/CarImageManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using Business.Abstract;
using Business.Constants;
using Core.Utilities.Business;
using Core.Utilities.Helpers.FileHelper;
using Core.Utilities.Results;
using DataAccess.Abstract;
using Entities.Concrete;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.Concrete
{
public class CarImageManager:ICarImageService
{
ICarImageDal _carImageDal;
IFileHelperService _fileHelperService;


public CarImageManager(ICarImageDal carImageDal, IFileHelperService fileHelperService)
{
_carImageDal = carImageDal;
_fileHelperService = fileHelperService;

}


//IFormFile it means for HTTP protocol for file to request.
public IResult Add(IFormFile file, CarImage carImage)
{
IResult result = BusinessRules.Run(CheckForCarImageLimit(carImage.CarId));
if (result != null)
{
return result;
}
carImage.ImagePath = _fileHelperService.Upload(file, PathConstants.CarImagesPath);
carImage.ImageDate = DateTime.Now;

_carImageDal.Add(carImage);
return new SuccessResult(Messages.ImageAdded);

}

public IResult Delete(CarImage carImage)
{
_fileHelperService.Delete(PathConstants.CarImagesPath + carImage.ImagePath);
_carImageDal.Delete(carImage);

return new SuccessResult(Messages.CarImageDeleted);

}

public IDataResult<CarImage> GetById(int id)
{
return new SuccessDataResult<CarImage>(_carImageDal.Get(i => i.Id == id), Messages.ImagesListedById);

}

public IResult Update(IFormFile file, CarImage carImage)
{
carImage.ImagePath = _fileHelperService.Update(file, PathConstants.CarImagesPath + carImage.ImagePath,
PathConstants.CarImagesPath);
carImage.ImageDate = DateTime.Now;
_carImageDal.Update(carImage);
return new SuccessResult(Messages.ImageUpdated);
}
public IDataResult<List<CarImage>> GetAll()
{
return new SuccessDataResult<List<CarImage>>(_carImageDal.GetAll(), Messages.ImagesListed);
}

public IDataResult<List<CarImage>> GetImagesByCarId(int id)
{
//IResult result = BusinessRules.Run(CheckImageExists(id));
var result=_carImageDal.GetAll(i=> i.CarId == id);
if (result.Count == 0)
{
return new ErrorDataResult<List<CarImage>>(GetDefaultImage(id).Data);
}

return new SuccessDataResult<List<CarImage>>(_carImageDal.GetAll(c => c.CarId == id), Messages.ImagesListedByCarId);
}

private IResult CheckForCarImageLimit(int carId)
{
var result = _carImageDal.GetAll(i => i.CarId == carId).Count;
if (result > 5)
{
return new ErrorResult(Messages.CarImageLimitReached);
}
return new SuccessResult();

}

private IResult CheckImageExists(int carId)
{
var result = _carImageDal.GetAll(i => i.CarId == carId).Count;

if (result > 0)
{
return new ErrorResult(Messages.CarImageAlreadyHave);
}
return new SuccessResult();

}
private IDataResult<List<CarImage>> GetDefaultImage(int carId)
{

List<CarImage> carImages = new List<CarImage>();

carImages.Add(new CarImage { CarId = carId, ImageDate = DateTime.Now, ImagePath = "DefaultImage.jpg" });

return new SuccessDataResult<List<CarImage>>(carImages);
}

}
}
Loading