Skip to content

itayG98/MVVM-Hotel-Reservation-WPF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MVVM With SingeleTonSean

Disclaimer

I'm learning MVVM pattern and i started this repo as exercising while coding along with SingeleToneSean's Playlist about MVVM I donw own the idea of the apps i summerise the key features here to help myself learn more and my use this reop as example of abstract ideas and design patterns examples reasource.

Preview of the app

Purpose

The app should simply allow a costumer to reserve a room in fictional hotel inserting 5 inputs

  1. UserName
  2. FloorNum
  3. RoomNum
  4. Date of start
  5. Date of end

It should show list of all the reservation validate new ones and update SQL local Server .

Validation

All this properties are binded to the MakeReservationViewModel properties :

<TextBlock Grid.Row="0" Text="Room Number"/>
<TextBox Grid.Row="1" Text="{Binding RoomID ,UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Column="1" Grid.Row="0" Text="Floor Number"/>
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding FloorNum ,UpdateSourceTrigger=PropertyChanged}" />

Using Commands I enable and disable the button of submiting checking if there is username , room number and floor number if so calls the OnCanExecute() that invokes the boolian method :

public override bool CanExecute(object? parameter)
{
return !string.IsNullOrEmpty(_makeReservationViewModel.UserName)&&
_makeReservationViewModel .FloorNum>0
&& _makeReservationViewModel.RoomID>0
&& base.CanExecute(parameter);
}

When CanExecute is true the submit button beacome enabled and clicking it calls async method that uses a validator objects to check if there is error in the data / conflict with reservation from the data base
The validator named DatabaseReservationConflictValidator and implementing IReservationConflicValidator so the app is open for new Validetors addition in the future

public async Task<Reservation> GetConflictReservation(Reservation reservation)
{
using (ReserveRoomDBContext context = _dbContextFactory.CreateDbContext())
{
ReservationDTO reservationDTO = await context.Reservations.
Where(r => r.FloorNum== reservation.roomID.FloorNum).
Where(r => r.RoomNum== reservation.roomID.RoomNum).
Where(r => r.End>reservation.Start ).
Where(r=> r.Start < reservation.End).
FirstOrDefaultAsync();
if (reservationDTO is null)
return null;
return ToReservationMapper(reservationDTO);
}

Releases

No releases published

Packages

No packages published

Languages