Ejemplo n.º 1
0
        private async Task <bool> GetApiToDatabase()
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                var comments = await commentApi.Get("postId", PostVM.Id.ToString());

                foreach (var comment in comments)
                {
                    var commentDb = commentDatabase.Get(i => i.Id == comment.Id);
                    if (commentDb.Any())
                    {
                        continue;
                    }

                    var commentToInsert = new CommentEntity()
                    {
                        Id      = comment.Id,
                        Comment = comment.Body,
                        Name    = comment.Name,
                        Email   = comment.Email,
                        PostId  = comment.PostId
                    };

                    commentDatabase.Insert(commentToInsert);
                }

                return(await Task.FromResult(true));
            }

            return(await Task.FromResult(false));
        }
Ejemplo n.º 2
0
 private void btnComment_Click(object sender, RoutedEventArgs e)
 {
     if (user.Email.Equals(owner.Email))
     {
         Helpers.MakeErrorMessage(Window.GetWindow(this), "You are owner so can't rating", "Error");
     }
     else
     {
         if (BookDatabase.GetEmailBookDorm(owner.Email, dorm.Id).Equals(user.Email))
         {
             ValueRating = ratingBar.Value;
             Comment     = tbComment.Text.Trim();
             if (ValueRating == 0)
             {
                 Helpers.MakeErrorMessage(Window.GetWindow(this), "You must rating dorm ", "Error");
             }
             else
             {
                 if (CommentDatabase.Insert(owner.Email, dorm.Id, user.Email, Comment, ValueRating))
                 {
                     Helpers.MakeConfirmMessage(Window.GetWindow(this), "Thanks you bro", "Notify");
                     if (CommentDatabase.GetAvgRating(owner.Email, dorm.Id) != -1)
                     {
                         DormDatabase.UpdateRating(dorm.Id, CommentDatabase.GetAvgRating(owner.Email, dorm.Id));
                         dorm.Quality = (dorm.Quality + ValueRating) / DormDatabase.GetCount(dorm.Id);
                         MainControl mainControl = (MainControl)Window.GetWindow(this);
                         mainControl.MainHomeLayout.Children.Clear();
                         mainControl.MainHomeLayout.VerticalAlignment   = VerticalAlignment.Top;
                         mainControl.MainHomeLayout.HorizontalAlignment = HorizontalAlignment.Left;
                         mainControl.MainHomeLayout.Width  = 1150;
                         mainControl.MainHomeLayout.Height = 720;
                         mainControl.MainHomeLayout.Children.Add(new ShowDorm(dorm, user, 1));
                     }
                 }
                 else
                 {
                     Helpers.MakeErrorMessage(Window.GetWindow(this), "You already rating this dorm", "Error");
                 }
             }
         }
         else
         {
             Helpers.MakeErrorMessage(Window.GetWindow(this), "You can't comment because you have never book this dorm", "Error");
         }
     }
 }