From f7a54d04bbe9c65ffb988807b0e8c24943b44dcd Mon Sep 17 00:00:00 2001 From: semihshn Date: Sun, 28 Mar 2021 21:56:43 +0300 Subject: [PATCH] =?UTF-8?q?28/03/2021=20=E2=9C=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReCapProject/Business/Abstract/ICarService.cs | 2 + .../Business/Abstract/ICreditCardService.cs | 3 + .../Business/Abstract/ICustomerService.cs | 3 + .../Autofac/SecuredOperation.cs | 4 +- ReCapProject/Business/Concrete/AuthManager.cs | 3 +- ReCapProject/Business/Concrete/CarManager.cs | 7 +- .../Business/Concrete/CreditCardManager.cs | 5 ++ .../Business/Concrete/CustomerManager.cs | 57 ++++++++++++- .../Business/Concrete/RentalManager.cs | 45 +++++++++- ReCapProject/Business/Concrete/UserManager.cs | 2 +- ReCapProject/Business/Constants/Messages.cs | 6 ++ .../FluentValidation/CarValidator.cs | 2 + ReCapProject/ConsoleUI/Program.cs | 84 +++++++++---------- ReCapProject/Core/Entities/Concrete/User.cs | 2 +- ReCapProject/Core/Extensions/ErrorDetails.cs | 5 ++ .../Core/Extensions/ExceptionMiddleware.cs | 21 ++++- .../DataAccess/Abstract/ICustomerDal.cs | 2 + .../Concrete/EntityFramework/EfCustomerDal.cs | 29 ++++++- ReCapProject/Entities/Concrete/Car.cs | 2 + ReCapProject/Entities/Concrete/Customer.cs | 3 +- .../Entities/DTOs/CustomerAndUserUpdateDto.cs | 19 +++++ .../Entities/DTOs/UserForRegisterDto.cs | 2 + .../WebAPI/Controllers/CarsController.cs | 6 +- .../Controllers/CreditCardsController.cs | 22 +++++ .../WebAPI/Controllers/CustomersController.cs | 21 +++++ 25 files changed, 294 insertions(+), 63 deletions(-) create mode 100644 ReCapProject/Entities/DTOs/CustomerAndUserUpdateDto.cs diff --git a/ReCapProject/Business/Abstract/ICarService.cs b/ReCapProject/Business/Abstract/ICarService.cs index 5a5048b..059d814 100644 --- a/ReCapProject/Business/Abstract/ICarService.cs +++ b/ReCapProject/Business/Abstract/ICarService.cs @@ -15,7 +15,9 @@ public interface ICarService IResult Delete(Car car); IDataResult> GetAll(); IDataResult GetById(int id); + IDataResult> GetCarDetails(Expression> filter = null); + IDataResult GetCarDetail(Expression> filter); IDataResult> GetCarsBySelect(int brandId, int colorId); } diff --git a/ReCapProject/Business/Abstract/ICreditCardService.cs b/ReCapProject/Business/Abstract/ICreditCardService.cs index 9a4d061..2166f80 100644 --- a/ReCapProject/Business/Abstract/ICreditCardService.cs +++ b/ReCapProject/Business/Abstract/ICreditCardService.cs @@ -10,6 +10,9 @@ namespace Business.Abstract public interface ICreditCardService { IDataResult> GetCreditCards(Expression> filter = null); + IDataResult GetCreditCard(Expression> filter = null); IResult Pay(CreditCard creditCard); + + } } diff --git a/ReCapProject/Business/Abstract/ICustomerService.cs b/ReCapProject/Business/Abstract/ICustomerService.cs index 6dd7a9d..cd49a35 100644 --- a/ReCapProject/Business/Abstract/ICustomerService.cs +++ b/ReCapProject/Business/Abstract/ICustomerService.cs @@ -1,6 +1,7 @@ using Core.Utilities.Results.Abstract; using DataAccess.Abstract; using Entities.Concrete; +using Entities.DTOs; using System; using System.Collections.Generic; using System.Text; @@ -16,5 +17,7 @@ public interface ICustomerService IResult Add(Customer customer); IResult Update(Customer customer); IResult Delete(Customer customer); + IResult UpdateCustomerAndUser(CustomerAndUserUpdateDto customerUpdateDto); + IDataResultGetCustomerAndUserDetails(int userId); } } diff --git a/ReCapProject/Business/BusinessAspect/Autofac/SecuredOperation.cs b/ReCapProject/Business/BusinessAspect/Autofac/SecuredOperation.cs index 16e9e66..396e327 100644 --- a/ReCapProject/Business/BusinessAspect/Autofac/SecuredOperation.cs +++ b/ReCapProject/Business/BusinessAspect/Autofac/SecuredOperation.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection; using Core.Extensions; using Business.Constants; +using System.Security; namespace Business.BusinessAspect.Autofac { @@ -32,8 +33,7 @@ protected override void OnBefore(IInvocation invocation)//Authorization işlemi return; } } - return; - throw new Exception(Messages.AuthorizationDenied); + throw new SecurityException(Messages.AuthorizationDenied); } } } diff --git a/ReCapProject/Business/Concrete/AuthManager.cs b/ReCapProject/Business/Concrete/AuthManager.cs index 8c6a3bb..99ee005 100644 --- a/ReCapProject/Business/Concrete/AuthManager.cs +++ b/ReCapProject/Business/Concrete/AuthManager.cs @@ -31,7 +31,8 @@ public IDataResult Register(UserForRegisterDto userForRegisterDto, string LastName = userForRegisterDto.LastName, PasswordHash = passwordHash, PasswordSalt = passwordSalt, - Status = true + Status = true, + Age=userForRegisterDto.Age }; _userService.Add(user);//Kullanıcı veri tabanına kaydediliyor return new SuccessDataResult(user, Messages.UserRegistered); diff --git a/ReCapProject/Business/Concrete/CarManager.cs b/ReCapProject/Business/Concrete/CarManager.cs index 54c4b3c..5254f09 100644 --- a/ReCapProject/Business/Concrete/CarManager.cs +++ b/ReCapProject/Business/Concrete/CarManager.cs @@ -88,5 +88,10 @@ public IDataResult> GetCarsBySelect(int brandId, int colorId) { return new SuccessDataResult>(_carDal.GetCarDetails(c => c.ColorId == colorId & c.BrandId == brandId)); } - } + + public IDataResult GetCarDetail(Expression> filter) + { + return new SuccessDataResult(_carDal.GetCarDetails(filter).FirstOrDefault()); + } + } } diff --git a/ReCapProject/Business/Concrete/CreditCardManager.cs b/ReCapProject/Business/Concrete/CreditCardManager.cs index 3de702a..757fbd0 100644 --- a/ReCapProject/Business/Concrete/CreditCardManager.cs +++ b/ReCapProject/Business/Concrete/CreditCardManager.cs @@ -22,6 +22,11 @@ public CreditCardManager(ICreditCardDal creditCardDal) _creditCardDal = creditCardDal; } + public IDataResult GetCreditCard(Expression> filter = null) + { + return new SuccessDataResult(_creditCardDal.Get(filter)); + } + public IDataResult> GetCreditCards(Expression> filter = null) { return new SuccessDataResult>(_creditCardDal.GetAll(filter)); diff --git a/ReCapProject/Business/Concrete/CustomerManager.cs b/ReCapProject/Business/Concrete/CustomerManager.cs index cbc079a..7a0a2d6 100644 --- a/ReCapProject/Business/Concrete/CustomerManager.cs +++ b/ReCapProject/Business/Concrete/CustomerManager.cs @@ -2,10 +2,12 @@ using Business.Constants; using Business.ValidationRules.FluentValidation; using Core.Aspects.Autofac.Validation; +using Core.Utilities.Hashing; using Core.Utilities.Results.Abstract; using Core.Utilities.Results.Concrete; using DataAccess.Abstract; using Entities.Concrete; +using Entities.DTOs; using System; using System.Collections.Generic; using System.Text; @@ -15,10 +17,12 @@ namespace Business.Concrete public class CustomerManager : ICustomerService { ICustomerDal _customerDal; + IUserService _userService; - public CustomerManager(ICustomerDal customerDal) + public CustomerManager(ICustomerDal customerDal,IUserService userService) { _customerDal = customerDal; + _userService = userService; } [ValidationAspect(typeof(CustomerValidator))] @@ -54,5 +58,56 @@ public IResult Update(Customer customer) _customerDal.Update(customer); return new SuccessResult(Messages.CustomerUpdated); } + + public IDataResult GetCustomerAndUserDetails(int userId) + { + return new SuccessDataResult(_customerDal.GetCustomerAndUserDetails(userId)); + } + + public IResult UpdateCustomerAndUser(CustomerAndUserUpdateDto customerUpdateDto) + { + var userResult = _userService.GetById(customerUpdateDto.Id); + if (!userResult.Success) + return new ErrorResult(userResult.Message); + + if (!HashingHelper.VerifyPasswordHash(customerUpdateDto.ActivePassword, userResult.Data.PasswordHash, userResult.Data.PasswordSalt)) + return new ErrorResult(Messages.PasswordError); + + var customerResult = _customerDal.Get(p => p.UserId == customerUpdateDto.Id); + if (customerResult == null) + return new ErrorResult(Messages.CustomerNotFound); + + customerResult.CompanyName = customerUpdateDto.CompanyName; + + userResult.Data.FirstName = customerUpdateDto.FirstName; + userResult.Data.LastName = customerUpdateDto.LastName; + userResult.Data.Email = customerUpdateDto.Email; + + if (customerUpdateDto.NewPassword.Length > 5) + { + HashingHelper.CreatePasswordHash(customerUpdateDto.NewPassword, out byte[] passwordHash, out byte[] passwordSalt); + userResult.Data.PasswordHash = passwordHash; + userResult.Data.PasswordSalt = passwordSalt; + } + + try + { + _customerDal.Update(customerResult); + } + catch (Exception) + { + return new ErrorResult(Messages.CustomerNotUpdated); + } + try + { + _userService.Update(userResult.Data); + } + catch (Exception) + { + return new ErrorResult(Messages.UserNotUpdated); + } + + return new SuccessResult(Messages.CustomerUpdated); + } } } diff --git a/ReCapProject/Business/Concrete/RentalManager.cs b/ReCapProject/Business/Concrete/RentalManager.cs index 64f7919..8e01060 100644 --- a/ReCapProject/Business/Concrete/RentalManager.cs +++ b/ReCapProject/Business/Concrete/RentalManager.cs @@ -18,16 +18,21 @@ namespace Business.Concrete public class RentalManager : IRentalService { IRentalDal _rentalDal; + ICarService _carService; + ICustomerService _customerService; - public RentalManager(IRentalDal rentalDal) + + public RentalManager(IRentalDal rentalDal,ICarService carService,ICustomerService customerService) { _rentalDal = rentalDal; + _carService = carService; + _customerService = customerService; } - [ValidationAspect(typeof(RentalValidator))] + //[ValidationAspect(typeof(RentalValidator))] public IResult Add(Rental rental) { - IResult result = BusinessRules.Run(CheckCarExistInRentalList(rental), ChecCarExistRentalHistory(rental)); + IResult result = BusinessRules.Run(CheckCarExistInRentalList(rental), ChecCarExistRentalHistory(rental), ChecIfCarOfFindeksPoint(rental), ChecIfCustomerOfFindeksPoint(rental), ChecIfFindeksPoint(rental)); if (result != null) { @@ -94,5 +99,39 @@ private IResult ChecCarExistRentalHistory(Rental rental) return new SuccessResult(); } + + private IResult ChecIfCarOfFindeksPoint(Rental rental) + { + + var car = _carService.GetById(rental.CarId); + if (car.Data.FindeksPoint==null) + { + return new ErrorResult(Messages.ErrorCarFindeksPoint); + } + return new SuccessResult(); + } + + private IResult ChecIfCustomerOfFindeksPoint(Rental rental) + { + + var customer = _customerService.GetById(rental.CustomerId); + if (customer.Data.FindeksPoint == null) + { + return new ErrorResult(Messages.ErrorCustomerFindeksPoint); + } + return new SuccessResult(); + } + + private IResult ChecIfFindeksPoint(Rental rental) + { + + var customer = _customerService.GetById(rental.CustomerId); + var car = _carService.GetById(rental.CarId); + if (customer.Data.FindeksPoint> GetClaims(User user) { return new SuccessDataResult>(_userDal.GetClaims(user)); } - } + } } diff --git a/ReCapProject/Business/Constants/Messages.cs b/ReCapProject/Business/Constants/Messages.cs index fd4a742..64a7f9d 100644 --- a/ReCapProject/Business/Constants/Messages.cs +++ b/ReCapProject/Business/Constants/Messages.cs @@ -67,5 +67,11 @@ public static class Messages public static string ReturnedRental="Kiralama bilgisi döndürüldü"; public static string FailedRentalAddOrUpdate="Bu kiralık araç daha önce eklenmiş"; public static string AlreadyRented="Bu araç belirlediğiniz tarihlerde dolu , ileriki bir tarih seçiniz"; + public static string ErrorCarFindeksPoint= "Kiralanmak istenen aracın findeks puanı yok , başka bir araç seçin"; + public static string ErrorCustomerFindeksPoint = "Findeks puanınız olmadığından bu aracı size kiralayamayız"; + public static string InsufficientFindeksScore="Findeks puanınız bu aracı kiralamak için yetersiz"; + public static string CustomerNotFound = "Böyle bir müşteri bulunamadı"; + public static string CustomerNotUpdated = "Müşteri bilgilerini güncellerken bir hatayla karşılaştık"; + public static string UserNotUpdated = "Kullanıcı bilgilerini güncellerken bir hatayla karşılaştık"; } } diff --git a/ReCapProject/Business/ValidationRules/FluentValidation/CarValidator.cs b/ReCapProject/Business/ValidationRules/FluentValidation/CarValidator.cs index 07b8925..d7f4aab 100644 --- a/ReCapProject/Business/ValidationRules/FluentValidation/CarValidator.cs +++ b/ReCapProject/Business/ValidationRules/FluentValidation/CarValidator.cs @@ -13,6 +13,8 @@ public CarValidator() RuleFor(c => c.BrandId).NotEmpty(); RuleFor(c => c.ColorId).NotEmpty(); RuleFor(c => c.DailyPrice).GreaterThan(0); + + RuleFor(c => c.FindeksPoint).ExclusiveBetween(0, 1900); } } } diff --git a/ReCapProject/ConsoleUI/Program.cs b/ReCapProject/ConsoleUI/Program.cs index fb129c5..31dbd48 100644 --- a/ReCapProject/ConsoleUI/Program.cs +++ b/ReCapProject/ConsoleUI/Program.cs @@ -71,7 +71,7 @@ static void Main(string[] args) private static void TestGetRentalDetailsDto() { - RentalManager rentalManager = new RentalManager(new EfRentalDal()); + //RentalManager rentalManager = new RentalManager(new EfRentalDal()); //var result = rentalManager.GetRentalDetailsDto(); @@ -83,36 +83,36 @@ private static void TestGetRentalDetailsDto() private static void TestDeleteRental(int id) { - RentalManager rentalManager = new RentalManager(new EfRentalDal()); + //RentalManager rentalManager = new RentalManager(new EfRentalDal()); - rentalManager.Delete(new Rental() { Id = id }); + //rentalManager.Delete(new Rental() { Id = id }); } - private static RentalManager TestGetAllRentals() - { - RentalManager rentalManager = new RentalManager(new EfRentalDal()); + // private static RentalManager TestGetAllRentals() + // { + // RentalManager rentalManager = new RentalManager(new EfRentalDal()); - var result = rentalManager.GetAll(); + // var result = rentalManager.GetAll(); - foreach (var rentals in result.Data) - { - Console.WriteLine("{0}/{1}/{2}//{3}//{4}", rentals.Id, rentals.CarId, rentals.CustomerId, rentals.RentDate, rentals.ReturnDate); - } + // foreach (var rentals in result.Data) + // { + // Console.WriteLine("{0}/{1}/{2}//{3}//{4}", rentals.Id, rentals.CarId, rentals.CustomerId, rentals.RentDate, rentals.ReturnDate); + // } - return rentalManager; - } + // return rentalManager; + //} - private static RentalManager TestAddNewRentalCar(int carId, int customerId) - { - RentalManager rentalManager = new RentalManager(new EfRentalDal()); + // private static RentalManager TestAddNewRentalCar(int carId, int customerId) + // { + // RentalManager rentalManager = new RentalManager(new EfRentalDal()); - rentalManager.Add(new Rental() - { - CarId = carId, - CustomerId = customerId - }); - return rentalManager; - } + //rentalManager.Add(new Rental() + //{ + // CarId = carId, + // CustomerId = customerId + //}); + // return rentalManager; + // } private static CreditCardManager TestAddNewCreditCard(string cardNumber,string cvc,string expiration, int customerId) { @@ -128,30 +128,30 @@ private static CreditCardManager TestAddNewCreditCard(string cardNumber,string c return creditCardManager; } - private static void TestGetAllCustomer() - { - CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); + //private static void TestGetAllCustomer() + // { + // CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); - var result = customerManager.GetAll(); + // var result = customerManager.GetAll(); - foreach (var customer in result.Data) - { - Console.WriteLine("{0}/{1}/{2}", customer.Id, customer.UserId, customer.CompanyName); + // foreach (var customer in result.Data) + // { + // Console.WriteLine("{0}/{1}/{2}", customer.Id, customer.UserId, customer.CompanyName); - } - } + // } + // } - private static CustomerManager TestAddNewCustomer(int id, string companyName) - { - CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); + //private static CustomerManager TestAddNewCustomer(int id, string companyName) + //{ + // CustomerManager customerManager = new CustomerManager(new EfCustomerDal()); - customerManager.Add(new Customer() - { - UserId = id, - CompanyName = companyName, - }); - return customerManager; - } + // customerManager.Add(new Customer() + // { + // UserId = id, + // CompanyName = companyName, + // }); + // return customerManager; + //} private static void TestUserGetAll() { diff --git a/ReCapProject/Core/Entities/Concrete/User.cs b/ReCapProject/Core/Entities/Concrete/User.cs index 9c81ba0..a0c3c47 100644 --- a/ReCapProject/Core/Entities/Concrete/User.cs +++ b/ReCapProject/Core/Entities/Concrete/User.cs @@ -13,5 +13,5 @@ public class User : IEntity public byte[] PasswordHash { get; set; } public bool Status { get; set; } public DateTime? Age { get; set; } - } + } } diff --git a/ReCapProject/Core/Extensions/ErrorDetails.cs b/ReCapProject/Core/Extensions/ErrorDetails.cs index adf409d..d34a7fe 100644 --- a/ReCapProject/Core/Extensions/ErrorDetails.cs +++ b/ReCapProject/Core/Extensions/ErrorDetails.cs @@ -20,4 +20,9 @@ public class ValidationErrorDetails : ErrorDetails { public IEnumerable ValidationErrors { get; set; } } + + public class SecurityErrorDetail : ErrorDetails + { + + } } diff --git a/ReCapProject/Core/Extensions/ExceptionMiddleware.cs b/ReCapProject/Core/Extensions/ExceptionMiddleware.cs index 5476450..c07e24b 100644 --- a/ReCapProject/Core/Extensions/ExceptionMiddleware.cs +++ b/ReCapProject/Core/Extensions/ExceptionMiddleware.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Net; +using System.Security; using System.Text; using System.Threading.Tasks; using FluentValidation; @@ -36,11 +37,23 @@ private Task HandleExceptionAsync(HttpContext httpContext, Exception e) httpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; string message = "Internal Server Error"; - IEnumerable errors; - if (e.GetType() == typeof(ValidationException))//Eğer bir hata alınırsa buraya geliyor ve aldığın hata ValidationException ise bir mesaj oluşturuyor + + + if (e.GetType() == typeof(SecurityException))//Eğer bir SecurityException hatası alınırsa buraya geliyor ve aldığın hata SecurityException ise bir mesaj oluşturuyor + { + message = e.Message; + httpContext.Response.StatusCode = 403; + + return httpContext.Response.WriteAsync(new SecurityErrorDetail //Validasyon hatası dönerse bu çalışacak + { + StatusCode = 403, + Message = message + }.ToString()); + } + else if (e.GetType() == typeof(ValidationException))//Eğer bir ValidationException hatası alınırsa buraya geliyor ve aldığın hata ValidationException ise bir mesaj oluşturuyor { message = e.Message; - errors = ((ValidationException)e).Errors; + IEnumerable errors = ((ValidationException)e).Errors; httpContext.Response.StatusCode = 400; return httpContext.Response.WriteAsync(new ValidationErrorDetails//Validasyon hatası dönerse bu çalışacak @@ -54,7 +67,7 @@ private Task HandleExceptionAsync(HttpContext httpContext, Exception e) return httpContext.Response.WriteAsync(new ErrorDetails//Eğer sistem hata verirse back-end'in frontend'e ne döndereceğini belirtiyor , sınırlandırıyoruz burada { StatusCode = httpContext.Response.StatusCode, - Message = message + Message = e.Message }.ToString()); } } diff --git a/ReCapProject/DataAccess/Abstract/ICustomerDal.cs b/ReCapProject/DataAccess/Abstract/ICustomerDal.cs index 0d6fa90..92b4802 100644 --- a/ReCapProject/DataAccess/Abstract/ICustomerDal.cs +++ b/ReCapProject/DataAccess/Abstract/ICustomerDal.cs @@ -1,5 +1,6 @@ using Core.DataAccess; using Entities.Concrete; +using Entities.DTOs; using System; using System.Collections.Generic; using System.Text; @@ -8,5 +9,6 @@ namespace DataAccess.Abstract { public interface ICustomerDal : IEntityRepository { + CustomerAndUserUpdateDto GetCustomerAndUserDetails(int userId); } } diff --git a/ReCapProject/DataAccess/Concrete/EntityFramework/EfCustomerDal.cs b/ReCapProject/DataAccess/Concrete/EntityFramework/EfCustomerDal.cs index f02ec32..09f6ae3 100644 --- a/ReCapProject/DataAccess/Concrete/EntityFramework/EfCustomerDal.cs +++ b/ReCapProject/DataAccess/Concrete/EntityFramework/EfCustomerDal.cs @@ -1,13 +1,36 @@ using Core.DataAccess.EntityFramework; using DataAccess.Abstract; using Entities.Concrete; +using Entities.DTOs; using System; using System.Collections.Generic; using System.Text; +using System.Linq; namespace DataAccess.Concrete.EntityFramework { - public class EfCustomerDal : EfEntityRepositoryBase , ICustomerDal - { - } + public class EfCustomerDal : EfEntityRepositoryBase, ICustomerDal + { + public CustomerAndUserUpdateDto GetCustomerAndUserDetails(int userId) + { + using (ReCapContext context = new ReCapContext()) + { + var result = from user in context.Users + join customer in context.Customers + on user.Id equals customer.UserId + where user.Id==userId + select new CustomerAndUserUpdateDto + { + Id = user.Id, + CustomerId=customer.Id, + CompanyName = customer.CompanyName, + FirstName = user.FirstName, + LastName = user.LastName, + Email = user.Email + }; + + return result.FirstOrDefault(); + } + } + } } diff --git a/ReCapProject/Entities/Concrete/Car.cs b/ReCapProject/Entities/Concrete/Car.cs index 04e8ca6..2dcee53 100644 --- a/ReCapProject/Entities/Concrete/Car.cs +++ b/ReCapProject/Entities/Concrete/Car.cs @@ -21,5 +21,7 @@ public class Car : IEntity public int DailyPrice { get; set; } public string Description { get; set; } + + public int? FindeksPoint { get; set; } } } diff --git a/ReCapProject/Entities/Concrete/Customer.cs b/ReCapProject/Entities/Concrete/Customer.cs index 00e2274..2465589 100644 --- a/ReCapProject/Entities/Concrete/Customer.cs +++ b/ReCapProject/Entities/Concrete/Customer.cs @@ -10,5 +10,6 @@ public class Customer : IEntity public int Id { get; set; } public int UserId { get; set; } public string CompanyName { get; set; } - } + public int? FindeksPoint { get; set; } + } } diff --git a/ReCapProject/Entities/DTOs/CustomerAndUserUpdateDto.cs b/ReCapProject/Entities/DTOs/CustomerAndUserUpdateDto.cs new file mode 100644 index 0000000..04b75a3 --- /dev/null +++ b/ReCapProject/Entities/DTOs/CustomerAndUserUpdateDto.cs @@ -0,0 +1,19 @@ +using Core.Entities; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Entities.DTOs +{ + public class CustomerAndUserUpdateDto : IDto + { + public int Id { get; set; } + public int CustomerId { get; set; } + public string CompanyName { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string Email { get; set; } + public string ActivePassword { get; set; } + public string NewPassword { get; set; } + } +} diff --git a/ReCapProject/Entities/DTOs/UserForRegisterDto.cs b/ReCapProject/Entities/DTOs/UserForRegisterDto.cs index 25d6363..af90d2e 100644 --- a/ReCapProject/Entities/DTOs/UserForRegisterDto.cs +++ b/ReCapProject/Entities/DTOs/UserForRegisterDto.cs @@ -11,5 +11,7 @@ public class UserForRegisterDto : IDto public string Password { get; set; } public string FirstName { get; set; } public string LastName { get; set; } + public DateTime Age { get; set; } + } } diff --git a/ReCapProject/WebAPI/Controllers/CarsController.cs b/ReCapProject/WebAPI/Controllers/CarsController.cs index 62505b0..950a87b 100644 --- a/ReCapProject/WebAPI/Controllers/CarsController.cs +++ b/ReCapProject/WebAPI/Controllers/CarsController.cs @@ -111,11 +111,11 @@ public IActionResult GetCarByBrand(int id) return BadRequest(result); } - [HttpGet("getcarbycar")] - public IActionResult GetCarByCar(int id) + [HttpGet("getcarbycarId")] + public IActionResult GetCarByCarId(int id) { - var result = _carService.GetCarDetails(I => I.Id == id); + var result = _carService.GetCarDetail(I => I.Id == id); if (result.Success) { return Ok(result); diff --git a/ReCapProject/WebAPI/Controllers/CreditCardsController.cs b/ReCapProject/WebAPI/Controllers/CreditCardsController.cs index c665ef2..a1bec26 100644 --- a/ReCapProject/WebAPI/Controllers/CreditCardsController.cs +++ b/ReCapProject/WebAPI/Controllers/CreditCardsController.cs @@ -41,5 +41,27 @@ public IActionResult GetAll() } return BadRequest(result); } + + [HttpGet("getallbycustomerid")] + public IActionResult GetAllByCustomerId(int customerId) + { + var result = _creditCardService.GetCreditCards(c=>c.CustomerId==customerId); + if (result.Success) + { + return Ok(result); + } + return BadRequest(result); + } + + [HttpGet("getbycustomerid")] + public IActionResult GetByCustomerId(int customerId) + { + var result = _creditCardService.GetCreditCard(c=>c.CustomerId==customerId); + if (result.Success) + { + return Ok(result); + } + return BadRequest(result); + } } } diff --git a/ReCapProject/WebAPI/Controllers/CustomersController.cs b/ReCapProject/WebAPI/Controllers/CustomersController.cs index f6b50c1..3abeed8 100644 --- a/ReCapProject/WebAPI/Controllers/CustomersController.cs +++ b/ReCapProject/WebAPI/Controllers/CustomersController.cs @@ -1,5 +1,6 @@ using Business.Abstract; using Entities.Concrete; +using Entities.DTOs; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; @@ -75,6 +76,16 @@ public IActionResult Update(Customer customer) return BadRequest(result); } + [HttpPost("updateofuserandcustomer")] + public IActionResult UpdateWithUser(CustomerAndUserUpdateDto customerUpdateDto) + { + var result = _customerService.UpdateCustomerAndUser(customerUpdateDto); + if (result.Success) + return Ok(result); + + return BadRequest(result); + } + [HttpPost("delete")] public IActionResult Delete(Customer customer) { @@ -85,5 +96,15 @@ public IActionResult Delete(Customer customer) } return BadRequest(result); } + + [HttpGet("getcustomeranduserdetailsbyuserid")] + public IActionResult GetDetailCustomers(int userId) + { + var result = _customerService.GetCustomerAndUserDetails(userId); + if (result.Success) + return Ok(result); + + return BadRequest(result); + } } }