Exemplo n.º 1
0
        private static async Task <IActionResult> PostOrPutExecution(HttpRequest req, string postId, CloudTable collector, ILogger log,
                                                                     FacebookProfileDto fbUser, HttpOperation httpMethod)
        {
            log.LogInformation($"Trigger for {httpMethod} http method");

            log.LogInformation($"Reading body");
            var body = await new StreamReader(req.Body).ReadToEndAsync();

            if (string.IsNullOrWhiteSpace(body))
            {
                log.LogWarning($"Empty Body");
                return(new BadRequestResult());
            }

            log.LogInformation($"Received body : {body}, trying to deserialize");
            var comment = JsonConvert.DeserializeObject <CommentDto>(body);

            var partitionKey = postId;
            var rowKey       = $"{fbUser.Id}";

            log.LogInformation(
                $"Deserialized, trying insert or replace comment, partitionKey: {partitionKey}, rowKey: {rowKey}");

            var tableEntity = new CommentTable
            {
                PartitionKey = partitionKey,
                RowKey       = rowKey,
                Comment      = comment.Comment,
                Title        = comment.Title,
                ETag         = "*"
            };

            TableOperation operation = null;

            switch (httpMethod)
            {
            case HttpOperation.Put:
                log.LogInformation("Have chosen table operation Replace");
                operation = TableOperation.Replace(tableEntity);
                break;

            case HttpOperation.Post:
                log.LogInformation("Have chosen table operation Insert");
                operation = TableOperation.Insert(tableEntity);
                break;

            default:
                // Unsupported HTTP verbs = HTTP 405 (method not allowed)
                return(new StatusCodeResult(405));
            }

            await collector.ExecuteAsync(operation);

            log.LogInformation("Done");
            if (httpMethod == HttpOperation.Post)
            {
                return(new OkObjectResult(comment));
            }
            return(new OkResult());
        }
Exemplo n.º 2
0
        public BaseResponse PostComment(CommentTable commentTable, string userId)
        {
            var response = new BaseResponse();

            try
            {
                var comment = _context.CommentTable.Add(commentTable);

                _context.SaveChanges();

                var internalUserId = _context.UserTable.Where(x => x.AspNetUserId == userId).Single().Id;

                var userComment = new UserCommentTable();

                userComment.UserId = internalUserId;

                userComment.CommentId = comment.Id;

                _context.UserCommentTable.Add(userComment);

                _context.SaveChanges();

                response.Message = "OK";

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Exemplo n.º 3
0
        private void RebuidTokens()
        {
            CommentTable.Clear();
            ClassfificationList.Clear();
            QuickInfoList.Clear();
            StructNameList.Clear();
            BracePairList.Clear();
            OutlineList.Clear();
            ErrorList.Clear();

            var snapshot = this.Buffer.CurrentSnapshot;

            var lexer = new FlatbufferLexer(new AntlrInputStream(snapshot.GetText()));

            foreach (var token in lexer.GetAllTokens())
            {
                if (token.Type == FlatbufferLexer.COMMENT)
                {
                    ClassfificationList.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1)), FBSComment));
                    var txt = token.Text;
                    if (txt.StartsWith("//"))
                    {
                        txt = txt.Substring(2).Trim();
                    }
                    else if (txt.StartsWith("/*"))
                    {
                        txt = txt.Substring(2, txt.Length - 4).Trim().Trim('*').Trim();
                    }
                    var lines = txt.Split('\n');
                    for (int i = 0; i < lines.Length; i++)
                    {
                        CommentTable.Add(token.Line + i, txt);
                    }
                }
            }
            lexer.Reset();

            var parser = new FlatbufferParser(new CommonTokenStream(lexer));

            parser.ErrorHandler = classificationErrorHandler;
            parser.RemoveErrorListeners();
            parser.AddErrorListener(classificationErrorListener);

            parser.schema().Accept <int>(classificationVisitor);

            var dom = this.Buffer.Properties.GetProperty(typeof(ITextDocument));

            if (dom != null)
            {
                filePath = (dom as ITextDocument).FilePath;

                FBSProject builder = new FBSProject("", new string[] { filePath }, ErrorReport);
                builder.Build(filePath, snapshot.GetText());
            }

            ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length)));
        }
Exemplo n.º 4
0
            public Comment(CommentTable s, UserTable User)
            {
                CB = s;

                UserName    = User.Name;
                UserAvatar  = JsonConvert.DeserializeObject <List <string> >(User.Avatar);
                CommentText = s.Comment;
                CommentNR   = s.CommentNR;
            }
Exemplo n.º 5
0
        public static void SyncAsync()
        {
            MobileService.SyncContext.PushAsync().ConfigureAwait(false);

            ModuleTable.PullAsync("allModules", ModuleTable.CreateQuery());
            QATable.PullAsync("allQA", QATable.CreateQuery());
            CommentTable.PullAsync("allComments", CommentTable.CreateQuery());
            SkillsTable.PullAsync("allSkills", SkillsTable.CreateQuery());
        }
Exemplo n.º 6
0
        public void MakeComment(CommentTable s)
        {
            var User = App.database.GetUser(s.User);

            if (User != null)
            {
                var C = new Comment(s, User.First());
                CommentList.Add(C);
            }
        }
Exemplo n.º 7
0
        public CommentModel ToCommentModelFrom(CommentTable from)
        {
            var comment = new CommentModel();

            comment.Id          = from.Id;
            comment.Content     = from.Content;
            comment.DateCreated = from.DateCreated;
            //comment.Post = ToPostModelFrom( from.Post);
            //comment.Author = ToUserModelFrom ( from.Author );

            return(comment);
        }
Exemplo n.º 8
0
        protected override void Seed(CommentTableContext context)
        {
            var comment = new CommentTable
            {
                HostID      = "1",
                UserID      = "1",
                PostID      = "1",
                Description = "Charles:This party sucks; Ichika:I know;"
            };

            context.Set <CommentTable>().Add(comment);
            base.Seed(context);
        }
Exemplo n.º 9
0
        public void SaveDomain(CommentTable domainTable, string currentUserName = "")
        {
            string          localUserName = getCurrentUserName(currentUserName);
            ApplicationUser user          = _AccountService.FirstOrDefault(x => x.UserName == localUserName);

            domainTable.CreatedDate               = DateTime.UtcNow;
            domainTable.ModifiedDate              = domainTable.CreatedDate;
            domainTable.ApplicationUserCreatedId  = user.Id;
            domainTable.ApplicationUserModifiedId = user.Id;
            domainTable.CompanyTableId            = user.CompanyTableId;
            repo.Add(domainTable);

            _uow.Save();
        }
Exemplo n.º 10
0
        public CommentPage(int argc, CommentTable s)
        {
            root      = s;
            ArticleNR = argc;
            InitializeComponent();

            BackButton.Clicked += (o, e) => {
                Chain.Remove(Chain.Last());
                CLVL--;
                LoadComments(CLVL, Chain.Last().ID);
            };
            Chain.Add(root);
            LoadComments(CLVL, Chain.Last().ID);
        }
Exemplo n.º 11
0
        public CommentTable ToCommentFrom(CommentModel from)
        {
            var comment = new CommentTable();

            comment.Id          = from.Id;
            comment.Content     = from.Content;
            comment.DateCreated = from.DateCreated;
            comment.AuthorId    = from.Author.Id;
            comment.Author      = ToUserFrom(from.Author);
            comment.PostId      = from.Post.Id;
            comment.Post        = ToPostFrom(from.Post);

            return(comment);
        }
Exemplo n.º 12
0
        public static int InsertOrUpdateComments(Comment comment)
        {
            var lookup = CommentTable.LookupAsync(comment.id);

            if (lookup == null || comment.id == null)
            {
                CommentTable.InsertAsync(comment);
            }
            else
            {
                CommentTable.UpdateAsync(comment);
            }
            MobileService.SyncContext.PushAsync();
            return(1);
        }
Exemplo n.º 13
0
        //Nullable<int> parentId
        public bool AddComment(string content, int houseId, int userId)
        {
            CommentTable comment = new CommentTable()
            {
                CommentContent = content,
                IsDelete       = false,
                HouseId        = houseId,
                UserId         = userId,
                CommentTime    = DateTime.Now,
                IsUpdata       = false,
            };

            forHouseContext.CommentTable.Add(comment);
            forHouseContext.SaveChanges();
            return(true);
        }
Exemplo n.º 14
0
 /// <summary>
 /// 管理员删除用户评论
 /// </summary>
 /// <param name="commentid">评论id</param>
 /// <returns></returns>
 public static int CommentDelAdmin(int commentid)
 {
     using (LgShopDBEntities db = new LgShopDBEntities()) {
         try
         {
             CommentTable con = db.CommentTable.Find(commentid);
             int          id  = con.UserID ?? 0;
             db.CommentTable.Remove(con);
             db.Database.ExecuteSqlCommand($"insert into NoticeTable values({id},'违规评论处理通知','尊敬的用户您好,您评论的内容:{con.CommentContent} 因违反了乐购商城相关规定,已被删除,请您遵守相关规定!','{DateTime.Now}',0)");
             return(db.SaveChanges());
         }
         catch (Exception)
         {
             return(0);
         }
     }
 }
Exemplo n.º 15
0
        public IActionResult Details(ProductsViewModels model)
        {
            if (HttpContext.Session.GetString("ID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            var data = new CommentTable()
            {
                ProductId = model.Id,
                UserId    = Convert.ToInt32(HttpContext.Session.GetString("ID")),
                Comments  = model.Comments
            };

            _context.Comments.Add(data);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 16
0
 protected void btnPost_Click(object sender, EventArgs e)
 {
     if (txtComment.Text == "")
     {
         ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "click", "alert('内容不能为空')", true);
         return;
     }
     else
     {
         string        strConn = WebConfigurationManager.ConnectionStrings["dmtucaoConnectionString"].ConnectionString;
         SqlConnection con     = new SqlConnection(strConn);
         con.Open();
         SqlCommand cmd = new SqlCommand("INSERT INTO [comment] ([comment],[date],[user],[type],[it]) values(@comment,@date,@user,@type,@it)", con);
         cmd.Parameters.AddWithValue("@comment", txtComment.Text);
         cmd.Parameters.AddWithValue("@date", DateTime.Now);
         if ((bool)Session["pass"])
         {
             cmd.Parameters.AddWithValue("@user", Session["NickName"].ToString());
         }
         else
         {
             cmd.Parameters.AddWithValue("@user", "_guest");
         }
         cmd.Parameters.AddWithValue("@type", Convert.ToByte(ddlType.SelectedValue));
         cmd.Parameters.AddWithValue("@it", Convert.ToInt32(PageIndex.Value));
         int count = cmd.ExecuteNonQuery();
         if (1 == count)
         {
             ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "click", "alert('评论成功')", true);
             CommentTable.DataBind();
             SqlCommand read = new SqlCommand("UPDATE [ImageText] SET [danmaku]=@danmaku WHERE [it]=@it", con);
             read.Parameters.AddWithValue("@danmaku", CommentTable.Rows.Count.ToString());
             read.Parameters.AddWithValue("@it", Context.Request["it"]);
             read.ExecuteNonQuery();
         }
         else
         {
             ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "click", "alert('评论失败,请重试')", true);
         }
         cmd = null;
         con.Close();
         con = null;
         return;
     }
 }
Exemplo n.º 17
0
        async void SubmitComment(object sender, EventArgs e)
        {
            CommentButton.IsEnabled = false;
            //CommentListView.IsRefreshing = true;
            if (App.Online)
            {
                var CNR = App.database.CommentCount(ArticleNR);

                if (App.database.TokenCheck() && CommentEntry.Text != null && CommentEntry.Text != "" && CommentEntry.Text.Length > 0 && CNR != -1)
                {
                    var SC = new CommentTable
                    {
                        Article       = ArticleNR,
                        CommentNR     = CNR,
                        UserSubmitted = 0,
                        User          = App.LoggedinUser.ID,
                        Replynr       = -1,
                        Replylvl      = 0,
                        Comment       = CommentEntry.Text,
                        Point         = 0
                    };
                    CommentEntry.Text = "";
                    Console.WriteLine("Inserting Comment");
                    App.database.InsertComment(SC);
                    Console.WriteLine("Loading Comments");

                    LoadComments();
                    Console.WriteLine("Refreshing Comments");
                    CommentListView.ItemsSource = null;
                    CommentListView.ItemsSource = CommentList;

                    CommentListView.HeightRequest = LWH;
                }
            }
            else
            {
                await DisplayAlert("Offline", "The Server is currently Offline. Please try again later.", "OK");
            }
            //CommentListView.IsRefreshing = false;
            CommentButton.IsEnabled = true;
        }
Exemplo n.º 18
0
        void SubmitComment(int ReplyNR)
        {
            Console.WriteLine("PING1");
            if (App.database.TokenCheck() && (Comment.Text != null || Comment.Text != ""))
            {
                Console.WriteLine("PING2");

                var CNR = App.database.CommentCount(ArticleNR);
                var SC  = new CommentTable
                {
                    Article       = ArticleNR,
                    CommentNR     = CNR,
                    UserSubmitted = root.UserSubmitted,
                    User          = App.LoggedinUser.ID,
                    Replynr       = ReplyNR
                };
                if (ReplyNR > -1)
                {
                    Console.WriteLine("PING3.1.1");
                    var Reply = new CommentTable(); //App.database.GetComment(ReplyNR).First();
                    Console.WriteLine("PING3.1.2");
                    var User = App.database.GetUser(Reply.User).First();
                    Console.WriteLine("PING3.1.3");
                    SC.Replylvl = Reply.Replylvl + 1;
                    SC.Comment  = "@" + User.Name + Reply.CommentNR + ", " + Comment.Text; //
                }
                else
                {
                    Console.WriteLine("PING3.2");
                    SC.Replylvl = 0;
                    SC.Comment  = Comment.Text;
                }

                SC.Point     = 0;
                Comment.Text = "";
                App.database.InsertComment(SC);
                Console.WriteLine("PING4");
                LoadComments(CLVL, Chain.Last().ID);
            }
        }
Exemplo n.º 19
0
        private void RebuidTokens()
        {
            CommentTable.Clear();
            ClassfificationList.Clear();
            StructNameList.Clear();
            BracePairList.Clear();
            OutlineList.Clear();
            ErrorList.Clear();

            var snapshot = this.Buffer.CurrentSnapshot;

            var lexer  = new TemplateLexer(new AntlrInputStream(snapshot.GetText()));
            var parser = new TemplateParser(new CommonTokenStream(lexer));

            //parser.ErrorHandler = classificationErrorHandler;
            //parser.RemoveErrorListeners();
            //parser.AddErrorListener(classificationErrorListener);

            parser.document().Accept <int>(classificationVisitor);

            FlagAllHiddenToken(snapshot, lexer);

            //ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length)));
        }
Exemplo n.º 20
0
        void AddComment(CommentTable s)
        {
            var User = App.database.GetUser(s.User).First();

            var Box = new Button
            {
                CornerRadius      = 10,
                Margin            = 5,
                BackgroundColor   = Color.White,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
            };
            var Comment = new Label
            {
                Text = s.Comment,
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalOptions       = LayoutOptions.Start,
                TextColor    = Color.Black,
                FontSize     = 16,
                WidthRequest = 290,
                Margin       = 20,
            };
            var Username = new Label
            {
                Text = "  " + User.Name,
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment   = TextAlignment.Start,
                TextColor = Color.Black,
                FontSize  = 16,
            };

            var CurLVL = new Label
            {
                Text              = s.Replylvl.ToString(),
                TextColor         = Color.Black,
                BackgroundColor   = Color.Transparent,
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions   = LayoutOptions.Center,
                Margin            = 0,
                FontSize          = 16,
            };

            var Reply = new Button()
            {
                BackgroundColor   = Color.FromHex("#649FD4"),
                TextColor         = Color.FromHex("#FFFFFF"),
                WidthRequest      = 60,
                HeightRequest     = 30,
                Text              = "Reply",
                FontSize          = 10,
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions   = LayoutOptions.End,
                Margin            = 20,
            };

            Reply.Clicked += (o, e) => {
                SubmitComment(s.ID);
            };

            CommentGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            CommentGrid.Children.Add(Box, 0, 6, s.CommentNR, s.CommentNR + 1);
            CommentGrid.Children.Add(Comment, 1, 5, s.CommentNR, s.CommentNR + 1);
            CommentGrid.Children.Add(Username, 1, 5, s.CommentNR, s.CommentNR + 1);

            CommentGrid.Children.Add(Reply, 5, 6, s.CommentNR, s.CommentNR + 1);
            CommentGrid.Children.Add(CurLVL, 4, 5, s.CommentNR, s.CommentNR + 1);

            if (s.Replylvl == CLVL)
            {
                var Replies = new Button()
                {
                    Text              = "X Replies",
                    BackgroundColor   = Color.FromRgb(80, 210, 194),
                    TextColor         = Color.Black,
                    WidthRequest      = 60,
                    HeightRequest     = 20,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions   = LayoutOptions.End,
                    Margin            = 0,
                };

                Replies.Clicked += (o, e) => {
                    Chain.Add(s);
                    CLVL++;
                    LoadComments(CLVL, Chain.Last().ID);
                };

                CommentGrid.Children.Add(Replies, 3, 4, s.CommentNR, s.CommentNR + 1);
            }

            if (CLVL > 1)
            {
                CommentGrid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
                CommentGrid.Children.Add(BackButton, 0, 6, s.CommentNR + 1, s.CommentNR + 2);
            }
        }
Exemplo n.º 21
0
        public static async Task <ObservableCollection <Comment> > GetModuleComments(string moduleId)
        {
            var x = new ObservableCollection <Comment>(await CommentTable.Where(y => y.moduleId == moduleId).ToCollectionAsync <Comment>().ConfigureAwait(false));

            return(x);
        }
Exemplo n.º 22
0
 protected void Timer1_Tick(object sender, EventArgs e)
 {
     CommentTable.DataBind();
 }