Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/waitwing/Quyd_App
Browse files Browse the repository at this point in the history
  • Loading branch information
tnnkrt committed Jul 10, 2014
2 parents 483fe73 + 9b65198 commit b7075ec
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 31 deletions.
Binary file modified Quyd/Quyd.v12.suo
Binary file not shown.
2 changes: 1 addition & 1 deletion Quyd/Quyd/Controls/ControlPost.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<StackPanel x:Name="StackItem" Height="76" VerticalAlignment="Top" Margin="0,39,0,0" Orientation="Horizontal">
<Quyd:ControlItem Margin="5,0,0,0" Height="73" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</StackPanel>
<Button x:Name="BtnBid" Content="BID" VerticalAlignment="Bottom" HorizontalAlignment="Right" FontFamily="Tahoma" BorderBrush="Black" Foreground="Black" Width="70" Height="50" FontSize="16" Padding="0"/>
<Button x:Name="BtnBid" Content="BID" VerticalAlignment="Bottom" HorizontalAlignment="Right" FontFamily="Tahoma" BorderBrush="Black" Foreground="Black" Width="70" Height="50" FontSize="16" Padding="0" Click="BtnBid_Click"/>
<TextBlock x:Name="SumBox" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Bottom" Foreground="Black" Margin="10,0,0,10" Height="35" Text="ราคาซื้อ"/>
</Grid>
</UserControl>
23 changes: 22 additions & 1 deletion Quyd/Quyd/Controls/ControlPost.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
using System.Windows.Media.Imaging;
using Quyd.Models;

using Parse;

namespace Quyd.Controls
{
public partial class ControlPost : UserControl
{
{
Post post;
Store store;

public void setValue(Post post, Store store)
{
this.post = post;
this.store = store;
}

public ControlPost()
{
InitializeComponent();
Expand All @@ -30,5 +41,15 @@ public void setItems(ItemList itemList)
StackItem.Children.Add(controlItem);
}
}

private async void BtnBid_Click(object sender, RoutedEventArgs e)
{
Bid bid = new Bid();
bid.bidStore = store;
bid.Post = post;
await bid.saveAsync();
Notification notification = new Notification();
await notification.sendAsync(post.PostBy, false, post, notificationType.bid, false);
}
}
}
33 changes: 32 additions & 1 deletion Quyd/Quyd/Models/Bid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class Bid

public Bid()
{

bid = new ParseObject("Bid");
}

public Bid(ParseObject bid)
Expand All @@ -106,5 +106,36 @@ public async Task<ItemList> getStoreBidItems(ItemList userItems)
}
return storeBidItems;
}

public async Task saveAsync()
{
await bid.SaveAsync();
}

public Post Post
{
get
{
return new Post(bid.Get<ParseObject>("post"));
}

set
{
bid["post"] = value.Object;
}
}

public Store bidStore
{
get
{
return new Store(bid.Get<ParseObject>("bidStore"));
}

set
{
bid["bidStore"] = value.Object;
}
}
}
}
16 changes: 10 additions & 6 deletions Quyd/Quyd/Models/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

namespace Quyd.Models
{
enum notificationType {bid, select, confirm, cancle };
public enum notificationType {bid, select, confirm, cancle };

public class NotificationList
{
//Don't forget pined post
private List<Notification> notifications;

public enum type { bid, select, confirm, cancle };

public NotificationList()
{
notifications = new List<Notification>();
Expand Down Expand Up @@ -98,6 +96,12 @@ public class Notification
ParseObject notification;
Post post;

public Notification()
{
notification = null;
post = null;
}

public Notification(ParseObject notification_t)
{
notification = notification_t;
Expand All @@ -124,7 +128,7 @@ private async Task saveAsync()
await notification.SaveAsync();
}

public async void sendAsync(ParseUser toUser, bool isForStore, Post fromPost, NotificationList.type type, bool pined)
public async Task sendAsync(ParseUser toUser, bool isForStore, Post fromPost, notificationType type, bool pined)
{
ParseObject notification = new ParseObject("Notification"); ;

Expand All @@ -138,11 +142,11 @@ public async void sendAsync(ParseUser toUser, bool isForStore, Post fromPost, No
await notification.SaveAsync();
}

public NotificationList.type Type
public notificationType Type
{
get
{
return notification.Get<NotificationList.type>("type");
return notification.Get<notificationType>("type");
}
}

Expand Down
49 changes: 27 additions & 22 deletions Quyd/Quyd/PivotPage1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,27 @@ public async void loadComponentAsync()

public async Task reloadAll()
{
Store store = new Store();
try
{
await store.loadAsync(ParseUser.CurrentUser);
}
catch (QuydException ex)
{
if (ex.Code == QuydException.ErrorCode.store_notFound)
{
store = new Store(ParseUser.CurrentUser.ObjectId, new ParseGeoPoint(-1, 1), new List<string> { "000 000 0000" });
}
}

if (store.Object.ObjectId == null)
{
await store.saveAsync();
}

await reloadUserPage();
await reloadFeedPage();
await reloadStorePage();
await reloadFeedPage(store);
await reloadStorePage(store);
}

public async Task reloadUserPage()
Expand All @@ -77,6 +95,10 @@ public async Task reloadUserPage()
UserLoad.Text = "ไม่มีข้อมูล";
}

Store store = new Store();

await store.loadAsync(ParseUser.CurrentUser);

foreach (var post in posts.posts)
{
var controlPost = new Quyd.Controls.ControlPost();
Expand All @@ -88,7 +110,7 @@ public async Task reloadUserPage()
}
}

public async Task reloadFeedPage()
public async Task reloadFeedPage(Store store)
{
PostList posts = new PostList();

Expand All @@ -112,31 +134,14 @@ public async Task reloadFeedPage()
controlFeed.controlPost.locationBox.Text += " (" + post.Location.Latitude + "," + post.Location.Longitude + ")";
controlFeed.controlPost.BtnBid.Visibility = (await post.isBidable(ParseUser.CurrentUser)) ? Visibility.Visible : Visibility.Collapsed;
controlFeed.controlPost.setItems(await post.getUserItem());
controlFeed.controlPost.setValue(post, store);
controlFeed.controlPost.timeBox.Text = post.CreateAt.ToString();
FeedList.Children.Add(controlFeed);
}
}

public async Task reloadStorePage()
public async Task reloadStorePage(Store store)
{
Store store = new Store();
try
{
await store.loadAsync(ParseUser.CurrentUser);
}
catch(QuydException ex)
{
if(ex.Code == QuydException.ErrorCode.store_notFound)
{
store = new Store(ParseUser.CurrentUser.ObjectId, new ParseGeoPoint(-1, 1), new List<string> { "000 000 0000" });
}
}

if(store.Object.ObjectId == null)
{
await store.saveAsync();
}

if ((await store.getStoreItemsAsync()).Size > 0)
{
StackItemDetail.Children.Clear();
Expand Down

0 comments on commit b7075ec

Please sign in to comment.