Skip to content

Commit

Permalink
Results structure, new tables added and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Enes Aras committed Aug 3, 2021
1 parent e0fb931 commit c3cdb21
Show file tree
Hide file tree
Showing 72 changed files with 458 additions and 45 deletions.
Binary file modified .vs/ReCapProject/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/ReCapProject/v16/.suo
Binary file not shown.
17 changes: 17 additions & 0 deletions Business/Abstract/ICustomerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Core.Utilities.Results;
using Entities.Concrete;
using System;
using System.Collections.Generic;
using System.Text;

namespace Business.Abstract
{
public interface ICustomerService
{
IResult Add(Customer customer);
IResult Delete(Customer customer);
IResult Update(Customer customer);
IDataResult<List<Customer>> GetAll();
IDataResult<Customer> GetById(int id);
}
}
17 changes: 17 additions & 0 deletions Business/Abstract/IRentalService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Core.Utilities.Results;
using Entities.Concrete;
using System;
using System.Collections.Generic;
using System.Text;

namespace Business.Abstract
{
public interface IRentalService
{
IResult Add(Rental rental);
IResult Delete(Rental rental);
IResult Update(Rental rental);
IDataResult<List<Rental>> GetAll();
IDataResult<Rental> GetById(int id);
}
}
17 changes: 17 additions & 0 deletions Business/Abstract/IUserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Core.Utilities.Results;
using Entities.Concrete;
using System;
using System.Collections.Generic;
using System.Text;

namespace Business.Abstract
{
public interface IUserService
{
IResult Add(User user);
IResult Delete(User user);
IResult Update(User user);
IDataResult<List<User>> GetAll();
IDataResult<User> GetById(int id);
}
}
2 changes: 1 addition & 1 deletion Business/Concrete/CarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public IDataResult<List<Car>> GetAll()
public IDataResult<Car> GetById(int id)
{
return new SuccessDataResult<Car>
(_carDal.Get(c => c.Id == id));
(_carDal.Get(c => c.CarId == id));
}

public IDataResult<List<CarDetailDto>> GetCarDetails()
Expand Down
50 changes: 50 additions & 0 deletions Business/Concrete/CustomerManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Business.Abstract;
using Business.Constans;
using Core.Utilities.Results;
using DataAccess.Abstract;
using Entities.Concrete;
using System;
using System.Collections.Generic;
using System.Text;

namespace Business.Concrete
{
public class CustomerManager : ICustomerService
{
ICustomerDal _customerDal;
public CustomerManager(ICustomerDal customerDal)
{
_customerDal = customerDal;
}

public IResult Add(Customer customer)
{
_customerDal.Add(customer);
return new SuccessResult(Messages.UserAdded);
}

public IResult Delete(Customer customer)
{
_customerDal.Delete(customer);
return new SuccessResult(Messages.UserDeleted);
}

public IDataResult<List<Customer>> GetAll()
{
return new SuccessDataResult<List<Customer>>
(_customerDal.GetAll(), Messages.UsersListed);
}

public IDataResult<Customer> GetById(int id)
{
return new SuccessDataResult<Customer>
(_customerDal.Get(c => c.CustomerId == id));
}

public IResult Update(Customer customer)
{
_customerDal.Update(customer);
return new SuccessResult(Messages.UserUpdated);
}
}
}
76 changes: 76 additions & 0 deletions Business/Concrete/RentalManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Business.Abstract;
using Business.Constans;
using Core.Utilities.BusinessRules;
using Core.Utilities.Results;
using DataAccess.Abstract;
using Entities.Concrete;
using System;
using System.Collections.Generic;
using System.Text;

namespace Business.Concrete
{
public class RentalManager : IRentalService
{
IRentalDal _rentalDal;
public RentalManager(IRentalDal rentalDal)
{
_rentalDal = rentalDal;
}
public IResult Add(Rental rental)
{
IResult result = BusinessRule.Run(
IsCarBeenDelivered(rental.CarId));

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

_rentalDal.Add(rental);
return new SuccessResult(Messages.RentalAdded);
}

public IResult Delete(Rental rental)
{
_rentalDal.Delete(rental);
return new SuccessResult(Messages.RentalDeleted);
}

public IDataResult<List<Rental>> GetAll()
{
return new SuccessDataResult<List<Rental>>
(_rentalDal.GetAll());
}

public IDataResult<Rental> GetById(int id)
{
return new SuccessDataResult<Rental>
(_rentalDal.Get(r => r.Id == id));
}

public IResult Update(Rental rental)
{
try
{
_rentalDal.Update(rental);
return new SuccessResult(Messages.RentalUpdated);
}
catch (Exception)
{
return new ErrorResult(Messages.RentalUpdateError);
}
}

// private metotlar
private IResult IsCarBeenDelivered(int id)
{
var result = _rentalDal.Get(r => r.CarId == id && r.ReturnDate == null);
if (result == null)
{
return new SuccessResult();
}
return new ErrorResult("Araba teslim edilmemiş. Kiralama iptal.");
}
}
}
48 changes: 48 additions & 0 deletions Business/Concrete/UserManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Business.Abstract;
using Business.Constans;
using Core.Utilities.Results;
using DataAccess.Abstract;
using Entities.Concrete;
using System;
using System.Collections.Generic;
using System.Text;

namespace Business.Concrete
{
public class UserManager : IUserService
{
IUserDal _userDal;
public UserManager(IUserDal userDal)
{
_userDal = userDal;
}
public IResult Add(User user)
{
_userDal.Add(user);
return new SuccessResult(Messages.UserAdded);
}
public IResult Delete(User user)
{
_userDal.Delete(user);
return new SuccessResult(Messages.UserDeleted);
}

public IDataResult<List<User>> GetAll()
{
return new SuccessDataResult<List<User>>
(_userDal.GetAll(), Messages.UsersListed);
}

public IDataResult<User> GetById(int id)
{
return new SuccessDataResult<User>
(_userDal.Get(u => u.Id == id));
}

public IResult Update(User user)
{
_userDal.Update(user);
return new SuccessResult(Messages.UserUpdated);
}
}
}
13 changes: 13 additions & 0 deletions Business/Constans/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public static class Messages
public static string ColorListed = "Renkler Listelendi";
public static string ColorAddError = "Renk Eklenemedi";

internal static string UserAdded = "Kullanıcı başarıyla sisteme eklendi.";
internal static string UserDeleted = "Kullanıcı başarıyla sistemden silindi.";
internal static string UsersListed = "Kullanıcı başarıyla listelendi.";
internal static string UserUpdated = "Kullanıcı bilgileri başarıyla güncellendi.";

internal static string RentalAdded = "Kiralama işlemi başarıyla gerçekleşti.";
internal static string RentalDeleted = "Kiralama işlemi başarıyla silindi.";
internal static string RentalUpdated = "Kiralama işlemi başarıyla güncellendi.";
internal static string RentalUpdateError = "Kiralama Güncellenemedi.";
internal static string RentalsListed = "Kiralamalar başarıyla listelendi.";
internal static string RentalError = "Bu araç şuan kirada.";

public static string MaintenanceTime = "Sistem Şuan Bakımda.";
public static string Added = "Eklendi";
public static string Deleted = "Silindi";
Expand All @@ -40,5 +52,6 @@ public static class Messages
internal static string CarImageUpdated = "Fotoğraf Güncellendi";
internal static string CarImageNotFound = "Fotoğraf Bulunamadı";
internal static string CarImageDeleted = "Fotoğraf Silindi";
public static string ReturnDateInvalid = "Kiralama başarısız! Araç müsait değil.";
}
}
Binary file modified Business/bin/Debug/netstandard2.0/Business.dll
Binary file not shown.
Binary file modified Business/bin/Debug/netstandard2.0/Business.pdb
Binary file not shown.
Binary file modified Business/bin/Debug/netstandard2.0/Core.dll
Binary file not shown.
Binary file modified Business/bin/Debug/netstandard2.0/Core.pdb
Binary file not shown.
Binary file modified Business/bin/Debug/netstandard2.0/DataAccess.dll
Binary file not shown.
Binary file modified Business/bin/Debug/netstandard2.0/DataAccess.pdb
Binary file not shown.
Binary file modified Business/bin/Debug/netstandard2.0/Entities.dll
Binary file not shown.
Binary file modified Business/bin/Debug/netstandard2.0/Entities.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
656d0b06cad8785ecf985ee2ad32b557b809e9e9
8d537954dfa8152d86087da4e642afbaf065af20
Binary file modified Business/obj/Debug/netstandard2.0/Business.dll
Binary file not shown.
Binary file modified Business/obj/Debug/netstandard2.0/Business.pdb
Binary file not shown.
80 changes: 53 additions & 27 deletions ConsoleUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,60 @@ class Program
{
static void Main(string[] args)
{
CarManager carManager = new CarManager(new EfCarDal());

//Car car1 = new Car();
//car1.Id = 2;
//car1.BrandId = 2;
//car1.CarName = "Kia";
//car1.ColorId = 2;
//car1.ModelYear = 2016;
//car1.DailyPrice = 155000;
//car1.Description = "Kia Rio 1.3 motor";
//carManager.Add(car1);
//CarsAddTest(carManager);
//CarsInfoListed(carManager);
//UserAddTest(userManager);
//CustomerAddTest();
//RentalRentTest();
}

private static void RentalRentTest()
{
RentalManager rentalManager = new RentalManager(new EfRentalDal());

Rental rental1 = new Rental();
rental1.CarId = 1;
rental1.CustomerId = 1;
rental1.RentDate = new DateTime(2021, 08, 13);
rental1.ReturnDate = new DateTime(2021, 09, 13);


var result = rentalManager.Delete(rental1);
Console.WriteLine(result.Message);
}

private static void CustomerAddTest()
{
CustomerManager customerManager = new CustomerManager(new EfCustomerDal());
Customer customer1 = new Customer();
customer1.CustomerId = 1;
customer1.UserId = 1;
customer1.CompanyName = "Starlink";
customerManager.Add(customer1);
}

private static void UserAddTest(UserManager userManager)
{
User user1 = new User();
user1.FirstName = "Yusuf Enes";
user1.LastName = "Aras";
user1.Password = "12345";
user1.Email = "enesaras551@gmail.com";
userManager.Add(user1);
}

private static void CarsAddTest(CarManager carManager)
{
Car car1 = new Car();
car1.CarName = "Kia Rio";
car1.ModelYear = 2016;
car1.DailyPrice = 155000;
car1.Description = "Kia Rio 1.3 motor";
carManager.Add(car1);
}

private static void CarsInfoListed(CarManager carManager)
{
var result = carManager.GetCarDetails();
if (result.Success == true)
{
Expand All @@ -38,22 +80,6 @@ static void Main(string[] args)
{
Console.WriteLine(result.Message);
}



/*
* BrandManager brandManager = new BrandManager(new EfBrandDal());
foreach (var brand in brandManager.GetAll())
{
Console.WriteLine($"Araba Markası: {brand.BrandName}\n");
}
ColorManager colorManager = new ColorManager(new EfColorDal());
foreach (var color in colorManager.GetAll())
{
Console.WriteLine($"Araba Rengi: {color.ColorName}\n");
}
*/
}
}
}
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/Business.dll
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/Business.pdb
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/ConsoleUI.dll
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/ConsoleUI.pdb
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/Core.dll
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/Core.pdb
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/DataAccess.dll
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/DataAccess.pdb
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/Entities.dll
Binary file not shown.
Binary file modified ConsoleUI/bin/Debug/netcoreapp3.1/Entities.pdb
Binary file not shown.
Binary file not shown.
Binary file modified ConsoleUI/obj/Debug/netcoreapp3.1/ConsoleUI.dll
Binary file not shown.
Binary file modified ConsoleUI/obj/Debug/netcoreapp3.1/ConsoleUI.pdb
Binary file not shown.
1 change: 1 addition & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<Compile Include="Entities\IDto.cs" />
<Compile Include="Entities\IEntity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\BusinessRules\BusinessRule.cs" />
<Compile Include="Utilities\Results\DataResult.cs" />
<Compile Include="Utilities\Results\ErrorDataResult.cs" />
<Compile Include="Utilities\Results\ErrorResult.cs" />
Expand Down
6 changes: 3 additions & 3 deletions Core/DataAccess/IEntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Core.DataAccess
{
List<T> GetAll(Expression<Func<T,bool>> filter = null);
T Get(Expression<Func<T, bool>> filter);
void Add(T car);
void Update(T car);
void Delete(T car);
void Add(T entity);
void Update(T entity);
void Delete(T entity);
}
}
Loading

0 comments on commit c3cdb21

Please sign in to comment.