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
Binary file added .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion FifthLesson/readme.md

This file was deleted.

1 change: 0 additions & 1 deletion FirstLesson/readme.md

This file was deleted.

1 change: 0 additions & 1 deletion ForthLesson/readme.md

This file was deleted.

23 changes: 23 additions & 0 deletions RentCars/RentCars.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RentCars", "RentCars\RentCars.csproj", "{106C5519-D955-40F3-A4AA-F6229D9E29FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RentCarsTest", "RentCarsTest\RentCarsTest.csproj", "{E3641E35-A492-4547-8D91-FA311E841C38}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{106C5519-D955-40F3-A4AA-F6229D9E29FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{106C5519-D955-40F3-A4AA-F6229D9E29FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{106C5519-D955-40F3-A4AA-F6229D9E29FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{106C5519-D955-40F3-A4AA-F6229D9E29FB}.Release|Any CPU.Build.0 = Release|Any CPU
{E3641E35-A492-4547-8D91-FA311E841C38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3641E35-A492-4547-8D91-FA311E841C38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3641E35-A492-4547-8D91-FA311E841C38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3641E35-A492-4547-8D91-FA311E841C38}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions RentCars/RentCars/AdminFacade.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
namespace RentCars
{
public class AdminFacade
{
string Name { get; }
public AdminFacade(string name)
{
Name = name;
}
public void AddCar(Car car, CarPark carPark)
{
carPark.AddCarToPark(car, carPark);
}
public Rent CreateNewRent(Car rentedcar, Costumer costumerrenting, Interval rentedinterval)
{
var NewRent = new Rent(rentedcar, costumerrenting, rentedinterval);
return NewRent;
}
}
}
64 changes: 64 additions & 0 deletions RentCars/RentCars/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;

namespace RentCars
{
public class Car
{
public string Id { get; }
public int RentCounter { get; set; }
public List<Interval> RentedIntervals { get; set; }

public Car(string id)
{
Id = id;
RentCounter = new int();
RentedIntervals = new List<Interval>();
}
public bool CheckMaintenance()
{
bool Maintenance;
if (RentCounter <= 10)
{
Maintenance = true;
return Maintenance;
}
else
{
Maintenance = false;
return Maintenance;
}
}

public void DoMaintenance(Interval Dayofstart)
{
Dayofstart.MaintenanceInterval();
RentedIntervals.Add(Dayofstart);


}

public bool Disponibility(Interval IntentionalInterval)
{

bool Disponible = true;

for (int i = 0; i < RentedIntervals.Count; i++)
{
if (RentedIntervals[i].TimeIntervalChecker(IntentionalInterval) != true)
{

return Disponible = false;

}

}

return Disponible;


}

}

}
57 changes: 57 additions & 0 deletions RentCars/RentCars/CarPark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;

namespace RentCars
{
public class CarPark
{
public List<string> AvaiableCars {get; set; }
public List<Car> TotalCars { get; set; }

public CarPark(){


AvaiableCars = new List<string>();
TotalCars = new List<Car>();

}
public void AddCarToPark(Car carToAdd, CarPark carPark)
{
carPark.TotalCars.Add(carToAdd);
}

public List<string> CheckDisponibilityOfCarsOnSpecificInterval(Interval Intended ){
bool avaiable;
for (int i = 0; i < TotalCars.Count; i++)
{
avaiable = true;
for (int j = 0; j < TotalCars[i].RentedIntervals.Count; j++)
{

avaiable = TotalCars[i].RentedIntervals[j].TimeIntervalChecker(Intended);

}
if (avaiable == true)
{

AvaiableCars.Add(TotalCars[i].Id);

}
}
return AvaiableCars;


}
public List<string> ShowAvaiableCars(){

for (int i = 0; i < AvaiableCars.Count; i++)
{
Console.WriteLine(AvaiableCars[i]);
}
return AvaiableCars;
}



}
}
27 changes: 27 additions & 0 deletions RentCars/RentCars/Costumer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;

namespace RentCars
{
public class Costumer
{
public string CostumerID { get; }
public List<string> RentHistory { get; set; }
public List<Interval> Rents { get; set; }

public Costumer(string costumerid)
{
CostumerID = costumerid;
RentHistory = new List<string>();
Rents = new List<Interval>();
}

public void ShowCostumerHistory(){
for (int i = 0; i < RentHistory.Count; i++)
{
Console.WriteLine(RentHistory[i]);
}
}

}
}
39 changes: 39 additions & 0 deletions RentCars/RentCars/Interval.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
namespace RentCars
{
public class Interval
{

public DateTimeOffset Date1 { get; set; }
public DateTimeOffset Date2 { get; set; }

public Interval(DateTimeOffset date1, DateTimeOffset date2)
{

Date1 = date1;
Date2 = date2;
}

public bool TimeIntervalChecker(Interval IntervalToCheck )
{
bool Result = false;
if(DateTimeOffset.Compare(Date1, IntervalToCheck.Date1) > 0 && DateTimeOffset.Compare(Date1, IntervalToCheck.Date2) > 0){
Result = true;
}if(DateTimeOffset.Compare(Date2, IntervalToCheck.Date1) < 0 && DateTimeOffset.Compare(Date2, IntervalToCheck.Date1) < 0)
{
Result = true;
}
return Result;
}


public Interval MaintenanceInterval(){
Date2 = Date2.AddDays(7);
var TenDaysInterval = new Interval(Date1, Date2);
return TenDaysInterval;
}



}
}
11 changes: 11 additions & 0 deletions RentCars/RentCars/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
namespace RentCars
{
public class Program
{
public static void Main(string[] args)
{

}
}
}
34 changes: 34 additions & 0 deletions RentCars/RentCars/Rent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
namespace RentCars
{
public class Rent
{
public Car RentedCar { set; get; }
public Costumer CostumerRenting { set; get; }
public Interval RentedInterval { get; set; }

public Rent(Car rentedcar, Costumer costumerrenting, Interval rentedinterval)
{

RentedCar = rentedcar;
CostumerRenting = costumerrenting;
RentedInterval = rentedinterval;

if (RentedCar.Disponibility(RentedInterval) & RentedCar.CheckMaintenance())
{
CostumerRenting.Rents.Add(RentedInterval);
CostumerRenting.RentHistory.Add(RentedCar.Id);
RentedCar.RentCounter++;

}
if (RentedCar.CheckMaintenance() == false)
{
RentedCar.DoMaintenance(RentedInterval);
Console.WriteLine("Cannot rent this car is going to Maintenance");
}else {
Console.WriteLine("Can not rent this car, it is going to Maintenance");

}
}
}
}
21 changes: 21 additions & 0 deletions RentCars/RentCars/RentCars.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="CarParl.cs" />
<Compile Remove="MainClass.cs" />
<Compile Remove="Class.cs" />
<Compile Remove="CarFacade.cs" />
<Compile Remove="CostumerFacade.cs" />
<Compile Remove="Console.cs" />
<Compile Remove="Console.cs" />
<Compile Remove="RepositoryInterface.cs" />
<Compile Remove="CostumerRepository.cs" />
<Compile Remove="RentsRepository.cs" />
<Compile Remove="Endpoint.cs" />
</ItemGroup>
</Project>
24 changes: 24 additions & 0 deletions RentCars/RentCars/UserFacade.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
namespace RentCars
{
public class UserFacade
{
public Costumer Costumer { get; }

public UserFacade(Costumer costumer)
{
Costumer = costumer;
}
public void ShowCostumerHistory(){

Costumer.ShowCostumerHistory();

}
public Rent CreateNewRent(Car rentedcar, Costumer costumerrenting, Interval rentedinterval)
{
var NewRent = new Rent(rentedcar, costumerrenting, rentedinterval);
return NewRent;
}

}
}
52 changes: 52 additions & 0 deletions RentCars/RentCarsTest/CarParkTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using Xunit;
using RentCars;
using System.Collections.Generic;

namespace RentCarsTest
{
public class CarParkTest
{
[Fact]
public void AddCarToPark()
{
// Arrange
var Admin = new AdminFacade("Daniel");
var newCar = new Car("Red");
var newCarPark = new CarPark();
// Act
Admin.AddCar(newCar, newCarPark);
var expected = new List<Car>();
expected.Add(newCar);
//Asert
newCarPark.ShowAvaiableCars();
Assert.True(expected[0] == newCarPark.TotalCars[0]);

}
[Fact]
public void CheckDisponibilityOfCarsOnSpecificIntervalTestNotCoorrectDates(){

//Arrange
DateTimeOffset date1 = new DateTimeOffset(2018, 10, 1, 0, 0, 0, DateTimeOffset.Now.Offset);
DateTimeOffset date2 = new DateTimeOffset(2018, 10, 10, 0, 0, 0, DateTimeOffset.Now.Offset);
var firstInterval = new Interval(date1, date2);
DateTimeOffset date3 = new DateTimeOffset(2018, 11, 11, 0, 0, 0, DateTimeOffset.Now.Offset);
DateTimeOffset date4 = new DateTimeOffset(2018, 11, 20, 0, 0, 0, DateTimeOffset.Now.Offset);
var secondInterval = new Interval(date3, date4);
var Admin = new AdminFacade("Daniel");
var newCar = new Car("Red");
var newCarPark = new CarPark();
newCar.RentedIntervals.Add(firstInterval);
//Act
Admin.AddCar(newCar, newCarPark);
List<string> result = newCarPark.CheckDisponibilityOfCarsOnSpecificInterval(secondInterval);
var expected = new List<string>();
expected.Add(newCar.Id);
//Assert
Assert.True(expected[0] == result[0]);
}



}
}
Loading