Skip to content

Commit

Permalink
Homework 2 done
Browse files Browse the repository at this point in the history
Implement IPropertyChangedNotifier for DataManger class
  • Loading branch information
imad24 committed Mar 6, 2016
1 parent 3f4350c commit 43976e1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 11 deletions.
16 changes: 14 additions & 2 deletions RestaurantManager.Models/DataManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
namespace RestaurantManager.Models
using System.ComponentModel;
using System.Diagnostics.Tracing;
using System.Runtime.CompilerServices;

namespace RestaurantManager.Models
{
public abstract class DataManager
public abstract class DataManager : INotifyPropertyChanged
{
protected RestaurantContext Repository { get; private set; }

Expand All @@ -16,6 +20,14 @@ private async void LoadData()
OnDataLoaded();
}

public event PropertyChangedEventHandler PropertyChanged;

public void OnPropertyChanged([CallerMemberName] string propName=null)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}

protected abstract void OnDataLoaded();
}
}
17 changes: 15 additions & 2 deletions RestaurantManager.Models/ExpediteDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,27 @@ namespace RestaurantManager.Models
{
public class ExpediteDataManager : DataManager
{
private List<Order> _orderItems;

protected override void OnDataLoaded()
{

OrderItems = Repository.Orders;
}

public List<Order> OrderItems
{
get { return base.Repository.Orders; }
get
{
return Repository.Orders;
}
set
{
if (_orderItems != value)
{
_orderItems = value;
OnPropertyChanged();
}
}
}
}
}
33 changes: 30 additions & 3 deletions RestaurantManager.Models/OrderDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace RestaurantManager.Models
{
public class OrderDataManager : DataManager
{
{
private List<MenuItem> _menuItems, _currentlySelectedMenuItems;

protected override void OnDataLoaded()
{
this.MenuItems = base.Repository.StandardMenuItems;
Expand All @@ -13,10 +15,35 @@ protected override void OnDataLoaded()
this.MenuItems[3],
this.MenuItems[5]
};

}

public List<MenuItem> MenuItems { get; set; }
public List<MenuItem> MenuItems
{
get { return _menuItems; }
set
{
if (_menuItems != value)
{
_menuItems = value;
OnPropertyChanged();
}

}
}

public List<MenuItem> CurrentlySelectedMenuItems { get; set; }
public List<MenuItem> CurrentlySelectedMenuItems
{
get { return _currentlySelectedMenuItems; }
set
{
if (value != _currentlySelectedMenuItems)
{
_currentlySelectedMenuItems = value;
OnPropertyChanged();

}
}
}
}
}
2 changes: 1 addition & 1 deletion RestaurantManager.Models/RestaurantContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class RestaurantContext
public async Task InitializeContextAsync()
{
//DO NOT REMOVE: Simulates network congestion
await Task.Delay(TimeSpan.FromSeconds(2.5d));
await Task.Delay(TimeSpan.FromSeconds(1.5d));

this.Tables = new List<Table>
{
Expand Down
3 changes: 1 addition & 2 deletions RestaurantManager.UniversalWindows/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Page
x:Class="RestaurantManager.UniversalWindows.MainPage"
<Page x:Class="RestaurantManager.UniversalWindows.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RestaurantManager.UniversalWindows"
Expand Down
2 changes: 1 addition & 1 deletion RestaurantManager.UniversalWindows/OrderPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<TextBlock Grid.Row="2" Grid.Column="2" Text="Order Items:" />
<TextBox Grid.Row="3" Grid.Column="1" />
<ListView Grid.Row="2" Grid.RowSpan="3" Grid.Column="0" Margin="10" ItemsSource="{Binding MenuItems}" DisplayMemberPath="Title" />
<ListView Grid.Row="3" Grid.RowSpan="2" Grid.Column="2" Margin="10" ItemsSource="{Binding CurrentlySelectedMenuItems}" DisplayMemberPath="Title" />
<ListView Grid.Row="3" Grid.RowSpan="2" Grid.Column="2" Margin="10" ItemsSource="{Binding CurrentlySelectedMenuItems, Mode=TwoWay}" DisplayMemberPath="Title" />
<Button Content="Add to Order" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="5" Grid.Column="0" />
<Button Content="Submit Order" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" />
</Grid>
Expand Down

0 comments on commit 43976e1

Please sign in to comment.