/// <summary> /// Submit a comment for inclusion on a post. This method will either update Sitecore or submit the comment through the comment service, depending on settings /// </summary> /// <param name="entryId">The ID of the entry to add the comment to</param> /// <param name="comment">The comment to add to the entry</param> /// <param name="language">The language to create the comment in</param> /// <returns>The ID of the created comment item, or ID.Null if creation failed</returns> public virtual ID SubmitComment(ID entryId, Model.Comment comment, Language language = null) { if (Settings.CommentServiceEnabled) { // Submit comment through WCF service ChannelFactory <ICommentService> commentProxy = new ChannelFactory <ICommentService>("WeBlogCommentService"); commentProxy.Open(); ICommentService service = commentProxy.CreateChannel(); var result = service.SubmitComment(Context.Item.ID, comment, language); commentProxy.Close(); if (result == ID.Null) { Logger.Error("Comment submission through WCF failed. Check server Sitecore log for details", typeof(CommentManager)); } return(result); } else { var commentEvent = new CommentSubmitted { EntryId = entryId, RequestedCommentId = ID.NewID, Language = language ?? Context.Language, Comment = comment }; EventQueue.QueueEvent(commentEvent, true, CommentSettings.HandleSubmittedCommentsLocally); return(commentEvent.RequestedCommentId); } }
public ActionResult Post([FromBody] Model.Comment comment) { comment.commentTime = DateTime.Now; try { int n = DAL.Comment.Instance.Add(comment); return(Json(Result.Ok("发表评论成功", n))); } catch (Exception ex) { if (ex.Message.ToLower().Contains("foreign key")) { if (ex.Message.ToLower().Contains("username")) { return(Json(Result.Err("合法用户才能添加记录"))); } else { return(Json(Result.Err("评论所属作品不存在"))); } } else if (ex.Message.ToLower().Contains("null")) { return(Json(Result.Err("评论内容、作品Id、用户名不能为空"))); } else { return(Json(Result.Err(ex.Message))); } } }
public async Task AddComment() { if (string.IsNullOrWhiteSpace(Text)) { await Application.Current.MainPage.DisplayAlert("Error", "Comment text field is required !", "OK"); return; } CommentInsertRequest comment = new CommentInsertRequest { Date = DateTime.UtcNow, UserId = BaseAPIService.Id, Text = Text }; Model.Comment newComment = await _commentsApiService.Insert <Model.Comment>(comment); if (newComment != null) { _comments.Add(newComment); Text = string.Empty; await Application.Current.MainPage.DisplayAlert("Success", "Comment added successfuly!", "OK"); } }
public ActionResult Comment(int sarcasmID, string content) { if (!OperateHelper.IsLogin()) { return JsonMsgNoOk("请先登陆"); } if (content == null || sarcasmID == 0) { return JsonMsgNoOk("请填写评论内容"); } Comment model = new Model.Comment(); model.Content = content; model.CreateTime = DateTime.Now; model.IsDel = false; model.SarcasmID = sarcasmID; model.UserID = CurrentUser.UserID; BLLSession.ICommentService.Add(model); //获取当前吐槽所有的评论 var CurCommentList = BLLSession.ICommentService.GetListBy(m => m.SarcasmID == sarcasmID && !m.IsDel); var UserIDs = CurCommentList.Select(m => m.UserID).Distinct(); var UserList = BLLSession.IUserService.GetListBy(m => UserIDs.Contains(m.UserID)); var CommnetList = (from a in CurCommentList join c in UserList on a.UserID equals c.UserID select new { a.Content, CreateTime = a.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), c.UserName }).OrderByDescending(m => m.CreateTime).ToList(); return JsonMsgOk("评论成功", null, JsonConvert.SerializeObject(CommnetList)); }
public ID SubmitComment(ID EntryId, Model.Comment comment, Language language) { // Sitecore is not preprocessing the WCF request, so much of the Sitecore context is not set. using (new SecurityDisabler()) { var toRet = ManagerFactory.CommentManagerInstance.AddCommentToEntry(EntryId, comment, language); return(toRet); } }
public CustomMessageBox ShowCommentDialog(Model.Comment comment) { var messageBox = new CustomMessageBox(); var imageBrush = new ImageBrush(); var scrollViewer = new ScrollViewer(); imageBrush.ImageSource = StorageHelper.GetDisplayPicture(comment.Author.UserName); var border = new Border { Background = imageBrush, CornerRadius = new CornerRadius(5), Width = 48, Height = 48, Margin = new Thickness(3) }; var txtDisplayName = new TextBlock { Text = comment.Author.DisplayName, VerticalAlignment = VerticalAlignment.Center, FontSize = 24, FontWeight = FontWeights.SemiBold, Margin = new Thickness(10, 0, 0, 0) }; var txtComment = new TextBlock { Text = comment.Message, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(15, 15, 10, 0) }; scrollViewer.Content = txtComment; var userInfoPanel = new StackPanel { Margin = new Thickness(10, 0, 0, 0), Orientation = Orientation.Horizontal }; userInfoPanel.Children.Add(border); userInfoPanel.Children.Add(txtDisplayName); var rootPanel = new StackPanel { Margin = new Thickness(10, 30, 0, 0) }; rootPanel.Children.Add(userInfoPanel); rootPanel.Children.Add(scrollViewer); messageBox.Content = rootPanel; messageBox.LeftButtonContent = "OK"; messageBox.Show(); return(messageBox); }
public ActionResult <CommentViewModel> Post([FromBody] CommentCreationViewModel model) { var creationTime = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds(); var comm = new Model.Comment { BlogId = model.BlogId, UserId = NVLInt64(HttpContext.User.Identity.Name, 0), Content = model.Content, CreationTime = creationTime, }; _commentRepository.Add(comm); _commentRepository.Commit(); return(_mapper.Map <Model.Comment, CommentViewModel>(comm)); }
public static DTO.Comment TranslateModelCommentToDTOComment(Model.Comment c) { if (c == null) { return(null); } return(new DTO.Comment { Id = c.Id, Text = c.Text, LastModified = c.LastModified, LastModifiedByUser = UserMapper.TranslateModelUserToDTOUser(c.LastModifiedByUser) }); }
private void OnOk() { if (Button == "add") { RegularViewModel r = new RegularViewModel(Userr); r.KomentarAdded(CommentText, Userr, SelectedCiti); } else if (Button == "edit") { Model.Comment cc = new Model.Comment(); DateTime dt = new DateTime(); dt = DateTime.Now; cc.Update(Userr, CommentText, dt); } Window.Hide(); }
protected void buttonSaveComment_Click(object sender, EventArgs e) { if (MessagePanel != null) { MessagePanel.Visible = false; } if (Page.IsValid) { Model.Comment comment = new Model.Comment() { AuthorName = txtCommentName != null ? txtCommentName.Text : string.Empty, AuthorEmail = txtCommentEmail != null ? txtCommentEmail.Text : string.Empty, Text = txtCommentText != null ? txtCommentText.Text : string.Empty }; if (txtCommentWebsite != null) { string website = txtCommentWebsite.Text; website = website.Contains("://") ? website : String.Format("//{0}", website); comment.Fields.Add(Constants.Fields.Website, website); } comment.Fields.Add(Constants.Fields.IpAddress, Context.Request.UserHostAddress); var submissionResult = ManagerFactory.CommentManagerInstance.SubmitComment(Sitecore.Context.Item.ID, comment, Sitecore.Context.Language); if (submissionResult.IsNull) { SetErrorMessage(Translator.Text("COMMENT_SUBMIT_ERROR")); } else { SetSuccessMessage(Translator.Text("COMMENT_SUBMIT_SUCCESS")); ResetCommentFields(); } //check if added comment is available. if so, send it along with the event //won't happen unless publishing and indexing is really fast, but worth a try CommentItem newComment = ManagerFactory.CommentManagerInstance.GetEntryComments(Sitecore.Context.Item).Where(item => item.ID == submissionResult).SingleOrDefault(); Sitecore.Events.Event.RaiseEvent(Constants.Events.UI.COMMENT_ADDED, new object[] { newComment }); //display javascript to scroll right to the comments list CommentScroll.Visible = true; } }
/// <summary> /// Adds a comment to a blog /// </summary> /// <param name="entryId">The ID of the entry to add the comment to</param> /// <param name="comment">The comment to add to the entry</param> /// <param name="language">The language to create the comment in</param> /// <returns>The ID of the created comment item, or ID.Null if creation failed</returns> public virtual ID AddCommentToEntry(ID entryId, Model.Comment comment, Language language = null) { var args = new CreateCommentArgs(); args.EntryID = entryId; args.Comment = comment; args.Database = ContentHelper.GetContentDatabase(); args.Language = language ?? Context.Language; CorePipeline.Run("weblogCreateComment", args, true); if (args.CommentItem != null) { return(args.CommentItem.ID); } else { return(ID.Null); } }
public CommentViewModel(string username, string kom, string choosenButton, Model.Comment Selected, string selectedCity) { OK = new MyICommand(OnOk); Userr = username; Button = choosenButton; SelectedCiti = selectedCity; if (Selected != null) { if (Button == "edit") { CommentText = Selected.Comments; } else if (Button == "view") { CommentText = "Grad: " + Selected.City + "\nKomentar: " + Selected.Comments + "\n\n\nUser: "******"\nLast modified: " + Selected.Modified; IsNew = true; FontSize = 18; } } }
/// <summary> /// Submit a comment for inclusion on a post. This method will either update Sitecore or submit the comment through the comment service, depending on settings /// </summary> /// <param name="entryId">The ID of the entry to add the comment to</param> /// <param name="comment">The comment to add to the entry</param> /// <param name="language">The language to create the comment in</param> /// <returns>The ID of the created comment item, or ID.Null if creation failed</returns> public virtual ID SubmitComment(ID entryId, Model.Comment comment, Language language = null) { if (Settings.CommentServiceEnabled) { // Submit comment through WCF service ChannelFactory <ICommentService> commentProxy = new ChannelFactory <ICommentService>("WeBlogCommentService"); commentProxy.Open(); ICommentService service = commentProxy.CreateChannel(); var result = service.SubmitComment(Context.Item.ID, comment, language); commentProxy.Close(); if (result == ID.Null) { Logger.Error("Comment submission through WCF failed. Check server Sitecore log for details", typeof(CommentManager)); } return(result); } else { return(AddCommentToEntry(Context.Item.ID, comment, language)); } }
public List <Model.Comment> GetComments() { var sqlString = new StringBuilder(); sqlString.Append("with tb as "); sqlString.Append("( "); sqlString.AppendFormat("select t1.* from Comment t1 where t1.ParentId='{0}' ", this.ParentId); sqlString.Append(" "); sqlString.Append("union all "); sqlString.Append(" "); sqlString.Append("select t2.* from Comment t2 inner join tb "); sqlString.Append("on t2.ID=tb.PID) "); sqlString.Append("select * from tb "); var list = new List <Model.Comment>(); try { using (var dataReader = SqlDBHelper.ExecuteReader(sqlString.ToString())) { while (dataReader.Read()) { var commnet = new Model.Comment { Id = dataReader["Id"].ToString(), ParentId = dataReader["ParentId"].ToString(), Replayer = dataReader["Replayer"].ToString(), CommentDate = dataReader["CommnetDate"].ToString(), Content = dataReader["Content"].ToString(), QuestionId = dataReader["QuestionId"].ToString() }; list.Add(commnet); } } return(list); } catch { return(null); } }
private void btAddComment_Click(object sender, EventArgs e) { try { var item = lbSharesFiles.SelectedItem as Model.File; var fileId = item.Id; var comment = new Model.Comment { Text = rbCommentText.Text, File = _client.GetFile(fileId), User = _client.GetUser(_userId) }; _client.CreateComment(comment); RefreshCommentList(fileId); MessageBox.Show($"Комментарий успешно добавлен", "Добавление комментария", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exception) { MessageBox.Show($"Не удалось добавить комментарий, текст ошибки: {Environment.NewLine}{exception.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ActionResult Comment(int sarcasmID, string content) { if (!OperateHelper.IsLogin()) { return(JsonMsgNoOk("请先登陆")); } if (content == null || sarcasmID == 0) { return(JsonMsgNoOk("请填写评论内容")); } Comment model = new Model.Comment(); model.Content = content; model.CreateTime = DateTime.Now; model.IsDel = false; model.SarcasmID = sarcasmID; model.UserID = CurrentUser.UserID; BLLSession.ICommentService.Add(model); //获取当前吐槽所有的评论 var CurCommentList = BLLSession.ICommentService.GetListBy(m => m.SarcasmID == sarcasmID && !m.IsDel); var UserIDs = CurCommentList.Select(m => m.UserID).Distinct(); var UserList = BLLSession.IUserService.GetListBy(m => UserIDs.Contains(m.UserID)); var CommnetList = (from a in CurCommentList join c in UserList on a.UserID equals c.UserID select new { a.Content, CreateTime = a.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), c.UserName }).OrderByDescending(m => m.CreateTime).ToList(); return(JsonMsgOk("评论成功", null, JsonConvert.SerializeObject(CommnetList))); }
protected override void Seed(PhotoSharingContext context) { //Create listof Photo objects List <Photo> photos = new List <Photo>(); Photo photo = new Photo(); photo.Title = "Test Photo"; photo.Description = "test"; photo.Owner = "NaokiSato"; photo.PhotoFile = System.IO.File.ReadAllBytes("C:\\Users\\Rahma_Fgaier\\photoSharingApplication\\PhotoSharingApp\\Images\\flower.jpeg"); photo.ImageMimeType = "image/jpeg"; photo.CreateDate = DateTime.Now; photos.Add(photo); //Add the list of photos to the database and save changes foreach (var p in photos) { context.Photos.Add(p); } context.SaveChanges(); //Create List of Comments List <Comment> comments = new List <Comment>(); Comment comment = new Model.Comment(); comment.PhotoID = 1; comment.User = "******"; comment.Subject = "Test Comment"; comment.Body = "This comment should appear in photo 1"; comments.Add(comment); foreach (var c in comments) { context.Comments.Add(c); } context.SaveChanges(); }
protected void Page_Load(object sender, EventArgs e) { Page.Title = GetLocalResourceObject("title").ToString(); //No esta autenticado try { userId = SessionManager.GetUserSession(Context).UserProfileId; } catch { this.pnlNonAuthenticated.Visible = true; return; } //No se puede pillar el producto if (!Int64.TryParse(Request.Params.Get("id"), out commentId)) { //this.aspXml.Visible = this.pnlInfo.Visible = this.pnlError.Visible = this.pnlForm.Visible = this.pnlAddRight.Visible= false; this.pnlNotFound.Visible = true; return; } try { comm = commentService.getCommentById(commentId); } catch (InstanceNotFoundException) { this.pnlNotFound.Visible = true; return; } if (comm.userProfileId != userId) { this.pnlDenyPermission.Visible = true; return; } try { aspXml.Visible = true; //Traemos los productos aspXml.XPathNavigator = productService.searchProductByIdXML(comm.productId); // Anadimos los argumentos aspXml.TransformArgumentList = CreateArgumentListAndParams(); // Indicamos la transformacion xslt aspXml.TransformSource = Server.MapPath("~/XSLT/ProductDetails.xslt"); int tmp = aspXml.XPathNavigator.Select("//product").Count; if (tmp != 1) { aspXml.Visible = false; } } catch (ServerNotRespondingException) { aspXml.Visible = false; } this.pnlComment.Visible = true; this.userName.Text = comm.UserProfile.loginName; this.addDate.Text = comm.addDate.ToString(); this.comment.Text = comm.txt; if (comm.Label.Count == 0) { this.tags.Text = "<small>("+GetLocalResourceObject("NoTags").ToString()+")</small>"; } else { foreach (Model.Label tag in comm.Label) { this.tags.Text += "<a href='" + Response.ApplyAppPathModifier(String.Format("~/Pages/Comment/SeeCommentByTag.aspx?id={0}", tag.labelId)) + "'>" + "<span class='label label-primary'>" + tag.name + "</span></a> "; } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; BLL.CommentManager bll = new BLL.CommentManager(); string action = context.Request["action"]; // 获得分页 if (action == "get") { int pageIndex, pageSize; try { pageIndex = Convert.ToInt32(context.Request["pageIndex"]); pageSize = Convert.ToInt32(context.Request["pageSize"]); } catch { return; } pageIndex = pageIndex < 1 ? 1 : pageIndex; pageSize = pageSize <= 0 || pageSize > 10 ? 10 : pageSize; int pageCount = (int)Math.Ceiling((double)bll.GetModelCount() / (double)pageSize); List <Model.Comment> list = bll.GetPageList(pageIndex, pageSize); object obj = new { pageIndex, pageSize, pageCount, data = list, }; JavaScriptSerializer js = new JavaScriptSerializer(); context.Response.Write(js.Serialize(obj)); } // 获得一个 else if (action == "getById") { int id; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } var model = bll.GetModel(id); if (model == null) { context.Response.Write("no:该项目不存在"); return; } JavaScriptSerializer js = new JavaScriptSerializer(); context.Response.Write("ok:" + js.Serialize(model)); } // 添加 else if (action == "add") { Model.Comment comment = new Model.Comment(); try { comment.UserId = Convert.ToInt32(context.Request["userId"]); comment.ProjectId = Convert.ToInt32(context.Request["projectId"]); comment.Content = context.Request["content"]; } catch { context.Response.Write("no:参数错误"); return; } if (string.IsNullOrWhiteSpace(comment.Content)) { context.Response.Write("no:参数错误"); return; } if (bll.Add(comment)) { context.Response.Write("ok:添加成功"); } else { context.Response.Write("no:添加失败"); } } // 修改 else if (action == "edit") { int id; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } Model.Comment comment = bll.GetModel(id); if (comment == null) { context.Response.Write("no:支持的项目不存在"); return; } try { comment.UserId = Convert.ToInt32(context.Request["userId"]); comment.ProjectId = Convert.ToInt32(context.Request["projectId"]); comment.Content = context.Request["content"]; } catch { context.Response.Write("error:参数错误"); return; } if (string.IsNullOrWhiteSpace(comment.Content)) { context.Response.Write("no:参数错误"); return; } if (bll.Update(comment)) { context.Response.Write("ok:修改成功"); } else { context.Response.Write("no:修改失败"); } } // 删除 else if (action == "delete") { int id = 0; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } if (bll.Delete(id)) { context.Response.Write("ok:删除成功"); } else { context.Response.Write("no:删除失败"); } } else { context.Response.Write("error:非法的action"); } }
protected void Page_Load(object sender, EventArgs e) { Page.Title = GetLocalResourceObject("title").ToString(); //No esta autenticado try { userId = SessionManager.GetUserSession(Context).UserProfileId; } catch { this.pnlNonAuthenticated.Visible = true; return; } //No se puede pillar el producto if (!Int64.TryParse(Request.Params.Get("id"), out commentId)) { //this.aspXml.Visible = this.pnlInfo.Visible = this.pnlError.Visible = this.pnlForm.Visible = this.pnlAddRight.Visible= false; this.pnlNotFound.Visible = true; return; } try { comm = commentService.getCommentById(commentId); } catch (InstanceNotFoundException) { this.pnlNotFound.Visible = true; return; } if (comm.userProfileId != userId) { this.pnlDenyPermission.Visible = true; return; } try { aspXml.Visible = true; //Traemos los productos aspXml.XPathNavigator = productService.searchProductByIdXML(comm.productId); // Anadimos los argumentos aspXml.TransformArgumentList = CreateArgumentListAndParams(); // Indicamos la transformacion xslt aspXml.TransformSource = Server.MapPath("~/XSLT/ProductDetails.xslt"); int tmp = aspXml.XPathNavigator.Select("//product").Count; if (tmp != 1) { aspXml.Visible = false; } } catch (ServerNotRespondingException) { aspXml.Visible = false; } if (!IsPostBack) { this.pnlForm.Visible = true; this.writeComment.Text = comm.txt; foreach (Model.Label tag in comm.Label) { this.writeLabel.Text += tag.name + ","; } } }
public List<Model.Comment> GetList(Int32 Id, int TypeId, Int32 BookId, Int32 MemberId, int Status, int Start, int Limit) { List<Model.Comment> result = new List<Model.Comment>(); try { string cmdText = "Comment_Select"; SqlParameter[] p = { new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@TypeId", SqlDbType.Int, 4), new SqlParameter("@BookId", SqlDbType.Int, 4), new SqlParameter("@MemberId", SqlDbType.Int, 4), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@Start", SqlDbType.Int, 4), new SqlParameter("@Limit", SqlDbType.Int, 4) }; p[0].Value = Id; p[1].Value = TypeId; p[2].Value = BookId; p[3].Value = MemberId; p[4].Value = Status; p[5].Value = Start; p[6].Value = Limit; DataTable dt = db.ExcuteSelectReturnDataTable(cmdText, CommandType.StoredProcedure, p); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { Model.Comment model = new Model.Comment(); model.Ind = Convert.ToInt32(dr["Ind"]); model.Id = Convert.ToInt32(dr["Id"]); model.TypeId = Convert.ToInt32(dr["TypeId"]); model.BookId = Convert.ToInt32(dr["BookId"]); model.Title = dr["Title"].ToString(); model.MemberId = Convert.ToInt32(dr["MemberId"]); model.Email = dr["Email"].ToString(); model.FullName = dr["FullName"].ToString(); model.Avatar = dr["Avatar"].ToString(); model.Link = dr["Link"].ToString(); model.Content = dr["Content"].ToString(); model.Status = Convert.ToInt32(dr["Status"]); model.StatusText = dr["StatusText"].ToString(); model.CreateBy = dr["CreateBy"].ToString(); model.CreateTime = dr["CreateTime"].ToString(); model.ModifyBy = dr["ModifyBy"].ToString(); model.ModifyTime = dr["ModifyTime"].ToString(); model.TotalRow = Convert.ToInt16(dr["TotalRow"]); result.Add(model); } } } catch (Exception ex) { PTSLog.Error(ex); } return result; }