Code Monkey home page Code Monkey logo

mvvm-hotel-reservation-wpf's Introduction

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);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.