diff --git a/Quyd/Quyd.v12.suo b/Quyd/Quyd.v12.suo index ae279bf..acaaf20 100644 Binary files a/Quyd/Quyd.v12.suo and b/Quyd/Quyd.v12.suo differ diff --git a/Quyd/Quyd/Controls/ControlFeed.xaml.cs b/Quyd/Quyd/Controls/ControlFeed.xaml.cs index 2c43a7a..88a72dc 100644 --- a/Quyd/Quyd/Controls/ControlFeed.xaml.cs +++ b/Quyd/Quyd/Controls/ControlFeed.xaml.cs @@ -15,6 +15,6 @@ public partial class ControlFeed : UserControl public ControlFeed() { InitializeComponent(); - } + } } } diff --git a/Quyd/Quyd/Controls/ControlItemDetail.xaml.cs b/Quyd/Quyd/Controls/ControlItemDetail.xaml.cs index 7bbb922..eb22675 100644 --- a/Quyd/Quyd/Controls/ControlItemDetail.xaml.cs +++ b/Quyd/Quyd/Controls/ControlItemDetail.xaml.cs @@ -14,7 +14,7 @@ namespace Quyd.Controls { public partial class ControlItemDetail : UserControl { - private Item item; + public Item item; private int value; public ControlItemDetail() diff --git a/Quyd/Quyd/Controls/ControlPost.xaml.cs b/Quyd/Quyd/Controls/ControlPost.xaml.cs index 66a5ec7..ccb4b47 100644 --- a/Quyd/Quyd/Controls/ControlPost.xaml.cs +++ b/Quyd/Quyd/Controls/ControlPost.xaml.cs @@ -15,9 +15,11 @@ namespace Quyd.Controls { public partial class ControlPost : UserControl - { + { + public PivotPage1 parent; Post post; Store store; + public int num; public void setValue(Post post, Store store) { @@ -30,13 +32,14 @@ public ControlPost() InitializeComponent(); } - public void setItems(ItemList itemList) + public async void setItems(Post post) { + ItemList itemList = await post.getUserItem(); StackItem.Children.Clear(); foreach (Item item in itemList) { var controlItem = new Quyd.Controls.ControlItem(); - controlItem.icon.Source = new BitmapImage(new Uri("/Resources/Images/"+item.Name+".jpg", UriKind.Relative));//new BitmapImage(new Uri(@"/Resources/Images/"+item.Name+".png", UriKind.Absolute)); + controlItem.icon.Source = new BitmapImage(new Uri(item.Icon, UriKind.Absolute)); controlItem.quantity.Text = (item as Quantifiable).Quantity.ToString(); StackItem.Children.Add(controlItem); } @@ -50,6 +53,8 @@ private async void BtnBid_Click(object sender, RoutedEventArgs e) await bid.saveAsync(); Notification notification = new Notification(); //await notification.sendAsync(post.PostBy, false, post, notificationType.bid, false); + + parent.bidEvent(num, post); } } } diff --git a/Quyd/Quyd/LoginPage.xaml.cs b/Quyd/Quyd/LoginPage.xaml.cs index 6a17b70..7135f1c 100644 --- a/Quyd/Quyd/LoginPage.xaml.cs +++ b/Quyd/Quyd/LoginPage.xaml.cs @@ -57,6 +57,12 @@ private async void loginFace_Click(object sender, RoutedEventArgs e) user["name"] = fbData.Name; user["facebookId"] = fbData.Id; + dynamic parameters = new System.Dynamic.ExpandoObject(); + parameters.access_token = ParseFacebookUtils.AccessToken; + parameters.fields = "email"; + dynamic result = await fb.GetTaskAsync("me", parameters); + user["email"] = result.email; + await user.SaveAsync(); NavigationService.Navigate(new Uri("/PivotPage1.xaml", UriKind.Relative)); diff --git a/Quyd/Quyd/Models/Post.cs b/Quyd/Quyd/Models/Post.cs index ac63db2..5b7b385 100644 --- a/Quyd/Quyd/Models/Post.cs +++ b/Quyd/Quyd/Models/Post.cs @@ -25,7 +25,7 @@ public async Task loadUserPostAsync(ParseUser user) { var query = from post in ParseObject.GetQuery("Post").Include("postBy") where post.Get("postBy") == user - orderby post.CreatedAt ascending + orderby post.CreatedAt descending select post; try { @@ -52,7 +52,7 @@ public async Task loadStorePostAsync(Store store) { var query = from bid in ParseObject.GetQuery("Bid").Include("post").Include("post.postBy") where bid.Get("bidStore") == store.Object - orderby bid.CreatedAt ascending + orderby bid.CreatedAt descending select bid; try { @@ -80,7 +80,7 @@ public async Task loadFeedAsync(ParseUser user) { var query = from post in ParseObject.GetQuery("Post").Include("postBy") where post.Get("postBy") != user - orderby post.CreatedAt ascending + orderby post.CreatedAt descending select post; try { diff --git a/Quyd/Quyd/PagePost.xaml.cs b/Quyd/Quyd/PagePost.xaml.cs index ac22630..25d0392 100644 --- a/Quyd/Quyd/PagePost.xaml.cs +++ b/Quyd/Quyd/PagePost.xaml.cs @@ -58,17 +58,29 @@ private async void Button_Click(object sender, RoutedEventArgs e) await post.saveAsync(); int i = 0; ItemList itemList = await post.getUserItem(); - foreach (var item in (itemList)) + List saveList = new List(); + foreach (UIElement controlItemDetail in StackItem.Children) { - int q = Convert.ToInt32((StackItem.Children.ElementAt(i) as Quyd.Controls.ControlItemDetail).BoxValue.Text); + int q = Convert.ToInt32((controlItemDetail as Quyd.Controls.ControlItemDetail).BoxValue.Text); if (q > 0) { + Item item = itemList.itemList.ElementAt(i); (item as PostItem).Quantity = q; i++; (item as PostItem).Post = post; - await (item as PostItem).saveAsync(); + saveList.Add(item); } } + + foreach (var item in (saveList)) + { + await (item as PostItem).saveAsync(); + } + + if(saveList.Count() == 0) + { + await post.Object.DeleteAsync(); + } NavigationService.GoBack(); } diff --git a/Quyd/Quyd/PivotPage1.xaml b/Quyd/Quyd/PivotPage1.xaml index 90239ce..fd36bb2 100644 --- a/Quyd/Quyd/PivotPage1.xaml +++ b/Quyd/Quyd/PivotPage1.xaml @@ -14,7 +14,7 @@ FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" - shell:SystemTray.IsVisible="True"> + shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded"> diff --git a/Quyd/Quyd/PivotPage1.xaml.cs b/Quyd/Quyd/PivotPage1.xaml.cs index c7da2d6..73aedb3 100644 --- a/Quyd/Quyd/PivotPage1.xaml.cs +++ b/Quyd/Quyd/PivotPage1.xaml.cs @@ -39,17 +39,17 @@ public async void loadComponentAsync() fb.AccessToken = ParseFacebookUtils.AccessToken; dynamic me = await fb.GetTaskAsync("me"); UserProfile.usernameBox.Text = ParseUser.CurrentUser.Get("name"); - UserDetail.BoxMail.Text = me.email; + UserDetail.BoxMail.Text = ParseUser.CurrentUser.Email; UserDetail.BoxFacebook.NavigateUri = new Uri(me.link, UriKind.Absolute); UserDetail.BoxFacebook.TargetName = "_blank"; dynamic photo = await fb.GetTaskAsync("me/picture?redirect=false"); string facebookId = ParseUser.CurrentUser.Get("facebookId"); UserProfile.profilePictureBox.Source = new BitmapImage(new Uri("http://graph.facebook.com/" + facebookId + "/picture", UriKind.Absolute)); - await reloadAll(); + Init(); } - public async Task reloadAll() + public async void Init() { Store store = new Store(); try @@ -69,19 +69,13 @@ public async Task reloadAll() await store.saveAsync(); } - await reloadUserPage(); - await reloadFeedPage(store); - await reloadStorePage(store); + reloadUserPage(); + reloadFeedPage(store); + reloadStorePage(store); } - public async Task reloadUserPage() + public async void reloadUserPage() { - var fb = new Facebook.FacebookClient(); - fb.AccessToken = ParseFacebookUtils.AccessToken; - var me = await fb.GetTaskAsync("me"); - - var fbData = new Facebook.Client.GraphUser(me); - PostList posts = new PostList(); await posts.loadUserPostAsync(ParseUser.CurrentUser); @@ -95,23 +89,21 @@ 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(); controlPost.locationBox.Text = "Bangkok , Thailand"; - controlPost.setItems(await post.getUserItem()); + controlPost.setItems(post); controlPost.timeBox.Text = post.CreateAt.ToString(); - controlPost.BtnBid.Visibility = (await post.isBidable(ParseUser.CurrentUser))?Visibility.Visible:Visibility.Collapsed; + controlPost.BtnBid.Visibility = Visibility.Collapsed; UserPosts.Children.Add(controlPost); } } - public async Task reloadFeedPage(Store store) + public async void reloadFeedPage(Store store) { + FeedList.Children.Clear(); + PostList posts = new PostList(); await posts.loadFeedAsync(ParseUser.CurrentUser); @@ -124,7 +116,7 @@ public async Task reloadFeedPage(Store store) { FeedLoad.Text = "ไม่มีข้อมูล"; } - + int i = 0; foreach (var post in posts.posts) { var controlFeed = new Quyd.Controls.ControlFeed(); @@ -132,15 +124,17 @@ public async Task reloadFeedPage(Store store) string facebookId = post.PostBy.Get("facebookId"); controlFeed.controlUserProfile.profilePictureBox.Source = new BitmapImage(new Uri("http://graph.facebook.com/" + facebookId + "/picture", UriKind.Absolute)); controlFeed.controlPost.locationBox.Text = "Bangkok , Thailand"; - controlFeed.controlPost.BtnBid.Visibility = (await post.isBidable(ParseUser.CurrentUser)) ? Visibility.Visible : Visibility.Collapsed; - controlFeed.controlPost.setItems(await post.getUserItem()); + controlFeed.controlPost.BtnBid.Visibility = Visibility.Visible; + controlFeed.controlPost.setItems(post); controlFeed.controlPost.setValue(post, store); controlFeed.controlPost.timeBox.Text = post.CreateAt.ToString(); + controlFeed.controlPost.parent = this; + controlFeed.controlPost.num = i++; FeedList.Children.Add(controlFeed); } } - public async Task reloadStorePage(Store store) + public async void reloadStorePage(Store store) { ItemList itemList = await store.getStoreItemsAsync(); if (itemList.Size > 0) @@ -159,7 +153,7 @@ public async Task reloadStorePage(Store store) controlItemDetail.BoxInfo.Text = item.Description; controlItemDetail.BoxValue.Text = (item as Priceable).Price.ToString(); controlItemDetail.ImageIcon.Source = new BitmapImage(new Uri("/Resources/Images/" + item.Name + ".jpg", UriKind.Relative)); - + StackItemDetail.Children.Add(controlItemDetail); } @@ -182,21 +176,36 @@ public async Task reloadStorePage(Store store) string facebookId = post.PostBy.Get("facebookId"); controlFeed.controlUserProfile.profilePictureBox.Source = new BitmapImage(new Uri("http://graph.facebook.com/" + facebookId + "/picture", UriKind.Absolute)); controlFeed.controlPost.locationBox.Text = "Bangkok , Thailand"; - controlFeed.controlPost.setItems(await post.getUserItem()); + controlFeed.controlPost.setItems(post); controlFeed.controlPost.timeBox.Text = post.CreateAt.ToString(); - controlFeed.controlPost.BtnBid.Visibility = (await post.isBidable(ParseUser.CurrentUser)) ? Visibility.Visible : Visibility.Collapsed; + controlFeed.controlPost.BtnBid.Visibility = Visibility.Collapsed; StackPost.Children.Add(controlFeed); } } + public void bidEvent(int num, Post post) + { + FeedList.Children.RemoveAt(num); + + var controlFeed = new Quyd.Controls.ControlFeed(); + controlFeed.controlUserProfile.usernameBox.Text = post.PostBy.Get("name"); + string facebookId = post.PostBy.Get("facebookId"); + controlFeed.controlUserProfile.profilePictureBox.Source = new BitmapImage(new Uri("http://graph.facebook.com/" + facebookId + "/picture", UriKind.Absolute)); + controlFeed.controlPost.locationBox.Text = "Bangkok , Thailand"; + controlFeed.controlPost.setItems(post); + controlFeed.controlPost.timeBox.Text = post.CreateAt.ToString(); + controlFeed.controlPost.BtnBid.Visibility = Visibility.Collapsed; + StackPost.Children.Add(controlFeed); + } + private void Button_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri("/PagePost.xaml", UriKind.Relative)); } - protected void Page_InitComplete(object sender, EventArgs e) + private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { - reloadAll(); - } + reloadUserPage(); + } } } \ No newline at end of file diff --git a/Quyd/Quyd/Quyd.csproj b/Quyd/Quyd/Quyd.csproj index 6de7275..1b7e96e 100644 --- a/Quyd/Quyd/Quyd.csproj +++ b/Quyd/Quyd/Quyd.csproj @@ -198,18 +198,11 @@ PreserveNewest - - - - - - - PreserveNewest diff --git a/Quyd/Quyd/Quyd.csproj.user b/Quyd/Quyd/Quyd.csproj.user index 926f427..44361e4 100644 --- a/Quyd/Quyd/Quyd.csproj.user +++ b/Quyd/Quyd/Quyd.csproj.user @@ -2,17 +2,17 @@ 256 - 30F105C9-681E-420b-A277-7C086EAD8A4E + 5E7661DF-D928-40ff-B747-A4B1957194F9 256 - 30F105C9-681E-420b-A277-7C086EAD8A4E + 5E7661DF-D928-40ff-B747-A4B1957194F9 - False + True Managed Managed False