summaryrefslogtreecommitdiff
path: root/slips/src/app/Marina/Task
diff options
context:
space:
mode:
authormokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219>2009-02-21 21:44:27 +0000
committermokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219>2009-02-21 21:44:27 +0000
commit1dfdccb8118aeaa3cd844ac8de2a672c93312166 (patch)
tree4b19e7f816ab1019f180a46b68572af4b66fe4bc /slips/src/app/Marina/Task
parent42d66bcab8262c7b8b2452615df535e694a3ec1c (diff)
git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219
Diffstat (limited to 'slips/src/app/Marina/Task')
-rw-r--r--slips/src/app/Marina/Task/ApplicationStartupTask.cs14
-rw-r--r--slips/src/app/Marina/Task/AuthenticationTask.cs41
-rw-r--r--slips/src/app/Marina/Task/CatalogTasks.cs52
-rw-r--r--slips/src/app/Marina/Task/IApplicationStartupTask.cs5
-rw-r--r--slips/src/app/Marina/Task/IAuthenticationTask.cs7
-rw-r--r--slips/src/app/Marina/Task/ICatalogTasks.cs14
-rw-r--r--slips/src/app/Marina/Task/ILeaseTasks.cs10
-rw-r--r--slips/src/app/Marina/Task/IRegistrationTasks.cs16
-rw-r--r--slips/src/app/Marina/Task/LeaseTasks.cs39
-rw-r--r--slips/src/app/Marina/Task/Mappers/BrokenRulesToDisplayItemMapper.cs13
-rw-r--r--slips/src/app/Marina/Task/Mappers/DockToDisplayDTOMapper.cs16
-rw-r--r--slips/src/app/Marina/Task/Mappers/IBrokenRulesToDisplayItemMapper.cs9
-rw-r--r--slips/src/app/Marina/Task/Mappers/IDockToDisplayDTOMapper.cs7
-rw-r--r--slips/src/app/Marina/Task/Mappers/ILeaseToDtoMapper.cs7
-rw-r--r--slips/src/app/Marina/Task/Mappers/ISlipsToDisplayDTOMapper.cs7
-rw-r--r--slips/src/app/Marina/Task/Mappers/LeaseToDtoMapper.cs12
-rw-r--r--slips/src/app/Marina/Task/Mappers/SlipsToDisplayDTOMapper.cs16
-rw-r--r--slips/src/app/Marina/Task/RegistrationTasks.cs92
18 files changed, 377 insertions, 0 deletions
diff --git a/slips/src/app/Marina/Task/ApplicationStartupTask.cs b/slips/src/app/Marina/Task/ApplicationStartupTask.cs
new file mode 100644
index 0000000..e55eccf
--- /dev/null
+++ b/slips/src/app/Marina/Task/ApplicationStartupTask.cs
@@ -0,0 +1,14 @@
+using Marina.Infrastructure.Container;
+using Marina.Infrastructure.Container.Windsor;
+
+namespace Marina.Task {
+ public class ApplicationStartupTask : IApplicationStartupTask {
+ public static void ApplicationBegin( ) {
+ new ApplicationStartupTask( ).Execute( );
+ }
+
+ public void Execute( ) {
+ Resolve.InitializeWith( new WindsorDependencyContainer( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/AuthenticationTask.cs b/slips/src/app/Marina/Task/AuthenticationTask.cs
new file mode 100644
index 0000000..75424a9
--- /dev/null
+++ b/slips/src/app/Marina/Task/AuthenticationTask.cs
@@ -0,0 +1,41 @@
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Presentation.DTO;
+using Marina.Web.Http;
+
+namespace Marina.Task {
+ public class AuthenticationTask : IAuthenticationTask {
+ public AuthenticationTask( ICustomerRepository customers, IHttpGateway gateway ) {
+ _customers = customers;
+ _gateway = gateway;
+ }
+
+ public DisplayResponseLineDTO AuthenticateUserUsing( LoginCredentialsDTO credentials ) {
+ if ( CheckIfPasswordMatches( credentials, _customers.FindBy( credentials.Username ) ) ) {
+ _gateway.AddAuthenticationCookieFor( credentials.Username, _customers.FindBy( credentials.Username ).ID( ) );
+ return ValidCredentialsMessage( credentials.Username );
+ }
+ else {
+ return InvalidCredentialsMessage( );
+ }
+ }
+
+ private static DisplayResponseLineDTO ValidCredentialsMessage( string username ) {
+ return new DisplayResponseLineDTO( string.Format( "Currently logged in as {0}", username ) );
+ }
+
+ private static DisplayResponseLineDTO InvalidCredentialsMessage() {
+ return new DisplayResponseLineDTO( "Invalid credentials specified" );
+ }
+
+ private static bool CheckIfPasswordMatches( LoginCredentialsDTO credentials, ICustomer customer ) {
+ if ( customer != null && customer.Registration( ) != null ) {
+ return customer.Registration( ).Password( ).Equals( credentials.Password );
+ }
+ return false;
+ }
+
+ private readonly ICustomerRepository _customers;
+ private readonly IHttpGateway _gateway;
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/CatalogTasks.cs b/slips/src/app/Marina/Task/CatalogTasks.cs
new file mode 100644
index 0000000..e3c18a2
--- /dev/null
+++ b/slips/src/app/Marina/Task/CatalogTasks.cs
@@ -0,0 +1,52 @@
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Infrastructure.Container;
+using Marina.Presentation.DTO;
+using Marina.Task.Mappers;
+
+namespace Marina.Task {
+ public class CatalogTasks : ICatalogTasks {
+ public CatalogTasks()
+ : this(
+ Resolve.DependencyFor< ISlipsRepository >( ),
+ Resolve.DependencyFor< ISlipsToDisplayDTOMapper >( ),
+ Resolve.DependencyFor< IDockRepository >( ),
+ Resolve.DependencyFor< IDockToDisplayDTOMapper >( )
+ ) {}
+
+ public CatalogTasks( ISlipsRepository slipRepository, ISlipsToDisplayDTOMapper slipMapper,
+ IDockRepository dockRepository, IDockToDisplayDTOMapper dockMapper ) {
+ _slips = slipRepository;
+ _slipMapper = slipMapper;
+ _docks = dockRepository;
+ _dockMapper = dockMapper;
+ }
+
+ public IEnumerable< SlipDisplayDTO > GetAvailableSlipsForDockBy( long dockId ) {
+ IDock dock = _docks.FindBy( dockId );
+ foreach ( ISlip slip in _slips.AllAvailableSlipsFor( dock ) ) {
+ yield return _slipMapper.MapFrom( slip );
+ }
+ }
+
+ public DockDisplayDTO GetDockInformationBy( long dockId ) {
+ return _dockMapper.MapFrom( _docks.FindBy( dockId ) );
+ }
+
+ public IEnumerable< SlipDisplayDTO > GetAllAvailableSlips() {
+ foreach ( ISlip availableSlip in _slips.AllAvailableSlips( ) ) {
+ yield return _slipMapper.MapFrom( availableSlip );
+ }
+ }
+
+ public SlipDisplayDTO FindSlipBy( long slipId ) {
+ return _slipMapper.MapFrom( _slips.FindBy( slipId ) );
+ }
+
+ private readonly ISlipsRepository _slips;
+ private readonly ISlipsToDisplayDTOMapper _slipMapper;
+ private readonly IDockRepository _docks;
+ private readonly IDockToDisplayDTOMapper _dockMapper;
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/IApplicationStartupTask.cs b/slips/src/app/Marina/Task/IApplicationStartupTask.cs
new file mode 100644
index 0000000..8fcdf6e
--- /dev/null
+++ b/slips/src/app/Marina/Task/IApplicationStartupTask.cs
@@ -0,0 +1,5 @@
+namespace Marina.Task {
+ public interface IApplicationStartupTask {
+ void Execute( );
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/IAuthenticationTask.cs b/slips/src/app/Marina/Task/IAuthenticationTask.cs
new file mode 100644
index 0000000..9072578
--- /dev/null
+++ b/slips/src/app/Marina/Task/IAuthenticationTask.cs
@@ -0,0 +1,7 @@
+using Marina.Presentation.DTO;
+
+namespace Marina.Task {
+ public interface IAuthenticationTask {
+ DisplayResponseLineDTO AuthenticateUserUsing( LoginCredentialsDTO credentials );
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/ICatalogTasks.cs b/slips/src/app/Marina/Task/ICatalogTasks.cs
new file mode 100644
index 0000000..5d438a2
--- /dev/null
+++ b/slips/src/app/Marina/Task/ICatalogTasks.cs
@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task {
+ public interface ICatalogTasks {
+ IEnumerable< SlipDisplayDTO > GetAvailableSlipsForDockBy( long dockId );
+
+ DockDisplayDTO GetDockInformationBy( long dockId );
+
+ IEnumerable< SlipDisplayDTO > GetAllAvailableSlips();
+
+ SlipDisplayDTO FindSlipBy( long slipId );
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/ILeaseTasks.cs b/slips/src/app/Marina/Task/ILeaseTasks.cs
new file mode 100644
index 0000000..f781a29
--- /dev/null
+++ b/slips/src/app/Marina/Task/ILeaseTasks.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task {
+ public interface ILeaseTasks {
+ IEnumerable< DisplayLeaseDTO > FindAllLeasesFor( long customerId );
+
+ DisplayResponseLineDTO RequestLeaseUsing( SubmitLeaseRequestDTO request );
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/IRegistrationTasks.cs b/slips/src/app/Marina/Task/IRegistrationTasks.cs
new file mode 100644
index 0000000..97974b3
--- /dev/null
+++ b/slips/src/app/Marina/Task/IRegistrationTasks.cs
@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task {
+ public interface IRegistrationTasks {
+ IEnumerable< DisplayResponseLineDTO > RegisterNew( RegisterCustomerDTO customer );
+
+ IEnumerable< DisplayResponseLineDTO > AddNewBoatUsing( BoatRegistrationDTO boat );
+
+ CustomerRegistrationDisplayDTO LoadRegistrationFor( long customerId );
+
+ IEnumerable< DisplayResponseLineDTO > UpdateRegistrationFor( UpdateCustomerRegistrationDTO registration );
+
+ IEnumerable< BoatRegistrationDTO > AllBoatsFor( long customerId );
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/LeaseTasks.cs b/slips/src/app/Marina/Task/LeaseTasks.cs
new file mode 100644
index 0000000..1dfb592
--- /dev/null
+++ b/slips/src/app/Marina/Task/LeaseTasks.cs
@@ -0,0 +1,39 @@
+using System.Collections.Generic;
+using Marina.Domain;
+using Marina.Domain.Exceptions;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+using Marina.Task.Mappers;
+
+namespace Marina.Task {
+ public class LeaseTasks : ILeaseTasks {
+ public LeaseTasks( ICustomerRepository customers, ISlipsRepository slips, ILeaseToDtoMapper mapper ) {
+ _customers = customers;
+ _slips = slips;
+ _mapper = mapper;
+ }
+
+ public IEnumerable< DisplayLeaseDTO > FindAllLeasesFor( long customerId ) {
+ return new EnumerableMapper< ISlipLease, DisplayLeaseDTO >( _mapper )
+ .MapFrom( _customers.FindBy( customerId ).Leases( ) );
+ }
+
+ public DisplayResponseLineDTO RequestLeaseUsing( SubmitLeaseRequestDTO request ) {
+ ICustomer customer = _customers.FindBy( request.CustomerId );
+ try {
+ customer.Lease( _slips.FindBy( request.SlipId ), LeaseDurations.FindBy( request.Duration ) );
+ _customers.Save( customer );
+ return new DisplayResponseLineDTO( "Success!" );
+ }
+ catch ( SlipIsAlreadyLeasedException ) {
+ return new DisplayResponseLineDTO( "Slip is already leased!" );
+ }
+ }
+
+ private readonly ICustomerRepository _customers;
+ private readonly ISlipsRepository _slips;
+ private readonly ILeaseToDtoMapper _mapper;
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/Mappers/BrokenRulesToDisplayItemMapper.cs b/slips/src/app/Marina/Task/Mappers/BrokenRulesToDisplayItemMapper.cs
new file mode 100644
index 0000000..5a9aee6
--- /dev/null
+++ b/slips/src/app/Marina/Task/Mappers/BrokenRulesToDisplayItemMapper.cs
@@ -0,0 +1,13 @@
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task.Mappers {
+ public class BrokenRulesToDisplayItemMapper : IBrokenRulesToDisplayItemMapper {
+ public IEnumerable< DisplayResponseLineDTO > MapFrom( IEnumerable< IBrokenRule > input ) {
+ foreach ( IBrokenRule brokenRule in input ) {
+ yield return new DisplayResponseLineDTO( brokenRule.Message( ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/Mappers/DockToDisplayDTOMapper.cs b/slips/src/app/Marina/Task/Mappers/DockToDisplayDTOMapper.cs
new file mode 100644
index 0000000..89ef037
--- /dev/null
+++ b/slips/src/app/Marina/Task/Mappers/DockToDisplayDTOMapper.cs
@@ -0,0 +1,16 @@
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task.Mappers {
+ public class DockToDisplayDTOMapper : IDockToDisplayDTOMapper {
+ public DockDisplayDTO MapFrom( IDock input ) {
+ return
+ new DockDisplayDTO(
+ input.Name( ),
+ input.Location( ).Name( ),
+ input.IsUtilityEnabled( Utilities.Water ).ToString( ),
+ input.IsUtilityEnabled( Utilities.Electrical ).ToString( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/Mappers/IBrokenRulesToDisplayItemMapper.cs b/slips/src/app/Marina/Task/Mappers/IBrokenRulesToDisplayItemMapper.cs
new file mode 100644
index 0000000..1af9300
--- /dev/null
+++ b/slips/src/app/Marina/Task/Mappers/IBrokenRulesToDisplayItemMapper.cs
@@ -0,0 +1,9 @@
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task.Mappers {
+ public interface IBrokenRulesToDisplayItemMapper :
+ IMapper< IEnumerable< IBrokenRule >, IEnumerable< DisplayResponseLineDTO > > {}
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/Mappers/IDockToDisplayDTOMapper.cs b/slips/src/app/Marina/Task/Mappers/IDockToDisplayDTOMapper.cs
new file mode 100644
index 0000000..264a92a
--- /dev/null
+++ b/slips/src/app/Marina/Task/Mappers/IDockToDisplayDTOMapper.cs
@@ -0,0 +1,7 @@
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task.Mappers {
+ public interface IDockToDisplayDTOMapper : IMapper< IDock, DockDisplayDTO > {}
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/Mappers/ILeaseToDtoMapper.cs b/slips/src/app/Marina/Task/Mappers/ILeaseToDtoMapper.cs
new file mode 100644
index 0000000..473ed68
--- /dev/null
+++ b/slips/src/app/Marina/Task/Mappers/ILeaseToDtoMapper.cs
@@ -0,0 +1,7 @@
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task.Mappers {
+ public interface ILeaseToDtoMapper : IMapper< ISlipLease, DisplayLeaseDTO > {}
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/Mappers/ISlipsToDisplayDTOMapper.cs b/slips/src/app/Marina/Task/Mappers/ISlipsToDisplayDTOMapper.cs
new file mode 100644
index 0000000..95f97ba
--- /dev/null
+++ b/slips/src/app/Marina/Task/Mappers/ISlipsToDisplayDTOMapper.cs
@@ -0,0 +1,7 @@
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task.Mappers {
+ public interface ISlipsToDisplayDTOMapper : IMapper< ISlip, SlipDisplayDTO > {}
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/Mappers/LeaseToDtoMapper.cs b/slips/src/app/Marina/Task/Mappers/LeaseToDtoMapper.cs
new file mode 100644
index 0000000..a776f52
--- /dev/null
+++ b/slips/src/app/Marina/Task/Mappers/LeaseToDtoMapper.cs
@@ -0,0 +1,12 @@
+using Marina.Domain.Interfaces;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task.Mappers {
+ public class LeaseToDtoMapper : ILeaseToDtoMapper {
+ public DisplayLeaseDTO MapFrom( ISlipLease input ) {
+ return new DisplayLeaseDTO( input.Slip( ).ID( ).ToString( ),
+ input.StartDate( ).ToString( ),
+ input.ExpiryDate( ).ToString( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/Mappers/SlipsToDisplayDTOMapper.cs b/slips/src/app/Marina/Task/Mappers/SlipsToDisplayDTOMapper.cs
new file mode 100644
index 0000000..c5ba592
--- /dev/null
+++ b/slips/src/app/Marina/Task/Mappers/SlipsToDisplayDTOMapper.cs
@@ -0,0 +1,16 @@
+using Marina.Domain.Interfaces;
+using Marina.Presentation.DTO;
+
+namespace Marina.Task.Mappers {
+ public class SlipsToDisplayDTOMapper : ISlipsToDisplayDTOMapper {
+ public SlipDisplayDTO MapFrom( ISlip input ) {
+ return
+ new SlipDisplayDTO( input.Dock( ).ID( ).ToString( ),
+ input.Dock( ).Name( ),
+ input.Width( ).ToString( ),
+ input.Length( ).ToString( ),
+ input.Location( ).Name( ),
+ input.ID( ).ToString( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/app/Marina/Task/RegistrationTasks.cs b/slips/src/app/Marina/Task/RegistrationTasks.cs
new file mode 100644
index 0000000..44c60ee
--- /dev/null
+++ b/slips/src/app/Marina/Task/RegistrationTasks.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Infrastructure.Container;
+using Marina.Presentation.DTO;
+using Marina.Task.Mappers;
+
+namespace Marina.Task {
+ public class RegistrationTasks : IRegistrationTasks {
+ public RegistrationTasks()
+ : this(
+ Resolve.DependencyFor< IBrokenRulesToDisplayItemMapper >( ),
+ Resolve.DependencyFor< ICustomerRepository >( )
+ ) {}
+
+ public RegistrationTasks( IBrokenRulesToDisplayItemMapper mapper, ICustomerRepository customers ) {
+ _mapper = mapper;
+ _customers = customers;
+ }
+
+ public IEnumerable< DisplayResponseLineDTO > RegisterNew( RegisterCustomerDTO customer ) {
+ if ( null == _customers.FindBy( customer.UserName ) ) {
+ ICustomer newCustomer = _customers.NewCustomer( );
+ newCustomer.RegisterAccount( customer.UserName,
+ customer.Password,
+ customer.FirstName,
+ customer.LastName,
+ customer.Phone,
+ customer.City );
+ if ( !newCustomer.Registration( ).IsValid( ) ) {
+ return _mapper.MapFrom( newCustomer.Registration( ).BrokenRules( ) );
+ }
+ else {
+ _customers.Save( newCustomer );
+ return new DisplayResponseLines( "Success!" );
+ }
+ }
+ else {
+ return
+ new DisplayResponseLines(
+ string.Format( "The username {0} is already taken. Please try another!", customer.UserName ) );
+ }
+ }
+
+ public IEnumerable< DisplayResponseLineDTO > AddNewBoatUsing( BoatRegistrationDTO boat ) {
+ ICustomer customer = _customers.FindBy( boat.CustomerId );
+ customer.RegisterBoat( boat.RegistrationNumber,
+ boat.Manufacturer,
+ new DateTime( Convert.ToInt32( boat.ModelYear ), 1, 1 ),
+ Convert.ToInt64( boat.Length ) );
+ _customers.Save( customer );
+ return new DisplayResponseLines( "Success!" );
+ }
+
+ public CustomerRegistrationDisplayDTO LoadRegistrationFor( long customerId ) {
+ IRegistration registration = _customers.FindBy( customerId ).Registration( );
+ return
+ new CustomerRegistrationDisplayDTO( customerId.ToString( ),
+ registration.Username( ),
+ registration.FirstName( ),
+ registration.LastName( ),
+ registration.PhoneNumber( ),
+ registration.City( )
+ );
+ }
+
+ public IEnumerable< DisplayResponseLineDTO > UpdateRegistrationFor( UpdateCustomerRegistrationDTO registration ) {
+ ICustomer customer = _customers.FindBy( registration.CustomerId );
+
+ customer.UpdateRegistrationTo( registration.Username, registration.Password, registration.FirstName,
+ registration.LastName, registration.PhoneNumber, registration.City );
+ if ( customer.Registration( ).IsValid( ) ) {
+ _customers.Save( customer );
+ }
+ return _mapper.MapFrom( customer.Registration( ).BrokenRules( ) );
+ }
+
+ public IEnumerable< BoatRegistrationDTO > AllBoatsFor( long customerId ) {
+ ICustomer customer = _customers.FindBy( customerId );
+
+ foreach ( IBoat boat in customer.RegisteredBoats( ) ) {
+ yield return
+ new BoatRegistrationDTO( boat.RegistrationNumber( ), boat.Manufacturer( ), boat.YearOfModel( ).ToString( ),
+ boat.LengthInFeet( ).ToString( ), customerId );
+ }
+ }
+
+ private readonly IBrokenRulesToDisplayItemMapper _mapper;
+ private readonly ICustomerRepository _customers;
+ }
+} \ No newline at end of file