public ActionResult Comment(CommentDetail commentDetail) { Authentication authentication = (Authentication)Session["authentication"]; if (authentication == null) { TempData["msg"] = "<script>alert('Please Log in First');</script>"; return(RedirectToAction("SignUpView", "SignUp")); } commentDetail.PersonID = authentication.Id; int owenerId = homeManager.GetPostInformationById(commentDetail.PostID).SignUpID; if (homeManager.SetComment(commentDetail, owenerId)) { ViewBag.Message = "Successfully comment in the post"; } PostInfo postInfo = homeManager.GetPostInformationById(commentDetail.ID); List <CommentDetail> commentDetails = homeManager.GetAllComment(commentDetail.PostID); ViewBag.Name = authentication.Name; ViewBag.SignupID = authentication.Id; ViewBag.Password = authentication.Password; ViewBag.PostInfo = postInfo; ViewBag.CommentList = commentDetails; return(View(commentDetail.ID)); }
public CommentItem Add(CommentDetail item) { return(new CommentItem() { Id = Guid.NewGuid() }); }
public async Task <OperationResponse <CommentDetail> > EditAsync(CommentDetail model) { var comment = await _unitOfWork.Comments.GetByIdAsync(model.Id); if (comment == null) { return new OperationResponse <CommentDetail> { IsSuccess = false, Message = "Comment not found" } } ; comment.Content = model.Content; await _unitOfWork.CommitChangesAsync(_identity.UserId); return(new OperationResponse <CommentDetail> { IsSuccess = true, Data = model, Message = "Comment has been edited successfully!" }); }
public List <CommentDetail> GetAllPhotoComment(int typeId, int typeNo) { List <CommentDetail> commentDetails = new List <CommentDetail>(); GenarateConnection(); string query = "select * from CommentPhoto where TypeID=@TypeID and TypeNo=@TypeNo ORDER BY ID DESC;"; Command = new SqlCommand(query, Connection); Command.Parameters.Clear(); Command.Parameters.Add("@TypeID", SqlDbType.VarChar); Command.Parameters["@TypeID"].Value = typeId; Command.Parameters.Add("@TypeNo", SqlDbType.VarChar); Command.Parameters["@TypeNo"].Value = typeNo; Connection.Open(); Reader = Command.ExecuteReader(); if (Reader.HasRows) { while (Reader.Read()) { CommentDetail commentDetail = new CommentDetail(); commentDetail.ID = Convert.ToInt32(Reader["ID"].ToString()); commentDetail.Comment = Reader["Comment"].ToString(); commentDetail.PostID = Convert.ToInt32(Reader["TypeID"].ToString()); commentDetail.PersonID = Convert.ToInt32(Reader["PersonID"].ToString()); commentDetail.TypeNo = Convert.ToInt32(Reader["TypeNo"].ToString()); commentDetails.Add(commentDetail); } } Connection.Close(); return(commentDetails); }
public ActionResult CommentDetails(string id, string uid, string date, CommentDetail commentDetail, string Command) { if (id != null) { ViewBag.record = othersService.CommentRecordService(long.Parse(id)); ViewBag.comment = othersService.CommentDetail(long.Parse(id)); //return View(); } if (Command == "Submit") { //var user = (CustomPrincipal)System.Web.HttpContext.Current.User; commentDetail.CommentId = long.Parse(id); commentDetail.UserLoginId = ValidUserUtility.ValidUser(); //(int)user.UserId; commentDetail.CommentDate = Convert.ToDateTime(date); commentDetail.UpdatedBy = ValidUserUtility.ValidUser(); //user.UserId; othersService.AddComment(commentDetail); if (commentDetail.CommentDetId != 0) { return(Content("<script language='javascript' type='text/javascript'>alert('Replied Successfully');location.href='" + @Url.Action("comments", "others") + "'</script>")); } else { return(Content("<script language='javascript' type='text/javascript'>alert('Failed');location.href='" + @Url.Action("comments", "others") + "'</script>")); } } return(View()); }
public bool SetComment(CommentDetail commentDetail, int owenerId) { GenarateConnection(); using (Connection) { Connection.Open(); string query = "insert into Comment(Comment,PostID,PersonID,OwenerID,DateTime) values (@Comment,@PostID,@PersonID,@OwenerID,@DateTime);"; Command = new SqlCommand(query, Connection); Command.Parameters.Clear(); Command.Parameters.Add("@Comment", SqlDbType.VarChar); Command.Parameters["@Comment"].Value = commentDetail.Comment; Command.Parameters.Add("@PostID", SqlDbType.VarChar); Command.Parameters["@PostID"].Value = commentDetail.PostID; Command.Parameters.Add("@PersonID", SqlDbType.VarChar); Command.Parameters["@PersonID"].Value = commentDetail.PersonID; Command.Parameters.Add("@OwenerID", SqlDbType.VarChar); Command.Parameters["@OwenerID"].Value = owenerId; Command.Parameters.Add("@DateTime", SqlDbType.DateTime); Command.Parameters["@DateTime"].Value = DateTime.Now; try { Command.ExecuteNonQuery(); Connection.Close(); return(true); } catch (Exception) { throw new Exception("Error While Entering data into database"); } } }
public async Task <IActionResult> PostComment(CommentDetail comment) { dynamic json = new ExpandoObject(); json.Message = "success"; if (!string.IsNullOrWhiteSpace(comment.Name) && !string.IsNullOrWhiteSpace(comment.Message)) { comment.IsActive = true; comment.CreatedDate = DateTime.Now; _dbContext.CommentDetails.Add(comment); await _dbContext.SaveChangesAsync(); json.Comment = comment; Response.StatusCode = StatusCodes.Status201Created; } else { json.Message = "error while adding comments"; json.Comment = null; Response.StatusCode = StatusCodes.Status200OK; } json.Result = Response.StatusCode; return(new JsonResult(json)); }
//btnlike.BackColor = Color.FromArgb(224, 224, 224); //btndislike.BackColor = Color.FromArgb(224, 224, 224); //btnlike.BackColor = Color.LightSkyBlue; //btndislike.BackColor = Color.Red; private void btndislike_Click(object sender, EventArgs e) { //_dislikebool = true; var q = from m in dbContext.Members //取出登入會員的memberID where m.NickName == lblNickName.Text select m.MemberID; int _MemberID = 0; foreach (var s in q) { _MemberID = s; } var b = (int)dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value; //找出該登入會員對應的評論明細 CommentDetail ComDetail = (dbContext.CommentDetails.Where(c => c.CommentID == b && c.MemberID == _MemberID)).FirstOrDefault(); ComDetail.BP++; if (/*_dislikebool == true &&*/ ComDetail.BP <= 2) { var a = (int)dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value; Comment Com = (dbContext.Comments.Where(c => c.CommentID == a)).FirstOrDefault(); if (ComDetail.BP == 1 && ComDetail.GP == 1 /*_likebool == true*/) { Com.GP_Quantity--; Com.BP_Quantity++; ComDetail.GP = 0; btnlike.BackColor = Color.FromArgb(224, 224, 224); btndislike.BackColor = Color.Red; //_likebool = false; } else if (ComDetail.BP == 1 && ComDetail.GP == 0 /*_likebool == false*/) { btndislike.BackColor = Color.Red; Com.BP_Quantity++; } else if (ComDetail.BP == 2) { Com.BP_Quantity--; ComDetail.BP = 0; btndislike.BackColor = Color.FromArgb(224, 224, 224); } else { return; } } else { return; } this.dbContext.SaveChanges(); ShowAllCommentSource(); ShowTopCommentSource(); }
/// <summary> /// 评论 /// </summary> /// <returns>false:评论主体不可评论</returns> public async Task <bool> CreateCommentDetail(ObjectId bodyId, ObjectId detailId, long userId, string content, ObjectId?relatedCommentId = null)//(主表Id, 用户Id, 内容) { var result = await GetCommentBodyControlState(bodyId); if (result == ControlState.Closed) { return(false); } CommentDetail detail = new CommentDetail(); detail._id = detailId; detail.Parent = new MongoDBRef(CommentBody.CollectionName, bodyId); detail.UserId = userId; detail.Content = content; detail.CreateTime = DateTime.Now; if (relatedCommentId.HasValue) { detail.RelatedComment = new MongoDBRef(CommentDetail.CollectionName, relatedCommentId); } var collection = Session.GetBsonCollection(CommentDetail.CollectionName); await collection.InsertOneAsync(detail.ToBsonDocument()); return(true); }
public CommentDetail AddComment(CommentDetail commentDetail) { string updateddate = DateTime.UtcNow.ToShortDateString(); commentDetail.Status = "Active"; commentDetail.UpdatedDate = Convert.ToDateTime(updateddate); return(othersRepository.AddComment(commentDetail)); }
public async Task<IActionResult> Edit(CommentDetail model) { var result = await _commentService.EditAsync(model); if (result.IsSuccess) return Ok(result); return BadRequest(result); }
public async Task Handle(CommentCreatedEvent notification, CancellationToken cancellationToken) { var comment = new CommentDetail(); comment.When(notification); await _readModelRepository.InsertAsync(comment); }
public CommentDetail InsertCommentDetailService(CommentDetail commentDetail) { DateTime updateddate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE); commentDetail.CommentDate = updateddate; commentDetail.UpdatedDate = updateddate; commentDetail.Status = "Active"; return(dashBoardRepository.InsertCommentDetail(commentDetail)); }
public PostDetailViewModel() { currentPost = new PostDetail(); comment = new CommentDetail(); SaveCommand = new Command(SaveComment); LikePostCommand = new Command(OnLikePost); DisplayImageCommand = new Command(DisplayImage); comments = new ObservableCollection <CommentDetail>(); }
public HttpResponseMessage Post([FromBody] CommentDetail item) { var result = repository.Add(item); if (result == null) { return(Request.CreateResponse(HttpStatusCode.NotModified)); } return(Request.CreateResponse(HttpStatusCode.Created, result)); }
public async Task <IActionResult> Edit([FromBody] CommentDetail model) { var result = await _commentsService.EditAsync(model); if (result.IsSuccess) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult Post([FromBody] CommentDetail item) { var result = repository.Add(item); if (result == null) { return(NotFound()); } return(Ok(result)); }
public bool UpdateComment(CommentDetail model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Comments .Single(e => e.Id == model.Id); entity.Text = model.Text; return(ctx.SaveChanges() == 1); } }
public bool UpdateComment(CommentDetail model) { using (var ctx = new ApplicationDbContext()) { var entity = GetCommentByID(model.CommentId); entity.Text = model.Text; entity.ModifiedUtc = model.ModifiedUtc; return(ctx.SaveChanges() > 0); } }
/// <summary> /// Get comment detail /// </summary> /// <param name="c">Comment</param> /// <returns>Json comment detail</returns> public CommentDetail GetCommentDetail(Comment c) { var jc = new CommentDetail(); jc.Id = c.Id; jc.ParentId = c.ParentId; jc.PostId = c.Posts.Id; jc.Content = c.Content; jc.Title = c.Content.Length < 80 ? c.Content : c.Content.Substring(0, 80) + "..."; jc.Ip = c.Ip; return(jc); }
public CommentItem Add(CommentDetail item) { var c = new Comment(); try { var post = _ctx.Posts.Where(p => p.Id == item.PostId).FirstOrDefault(); c.CreateDate = DateTime.Now; c.ParentId = item.ParentId; c.IsApproved = true; c.Content = item.Content; //if (string.IsNullOrEmpty(item.Author.Id)) //{ // var guid = string.NewGuid().ToString().Replace("-", ""); // var user = new AppUser { UserName = "******" + guid, Email = item.Author.Email, DisplayName = "匿名_" + item.Author.DisplayName }; // user.Avatar = AvatarHelper.GetRandomAvatar(); // var result = _userManager.CreateAsync(user).Result; // if (!result.Succeeded) // { // return null; // } // item.Author = user; //} //if (item.Author != null) //{ // c.AuthorId = item.Author.Id; // c.DisplayName = item.Author.DisplayName; // c.SiteUrl = item.Author.SiteUrl; //} c.DisplayName = item.DislpayName; c.Email = item.Email; c.Ip = AspNetCoreHelper.GetRequestIP(); c.Posts = post; _ctx.Comments.Add(c); _ctx.SaveChanges(); //var profile = AuthorProfile.GetProfile(c.Author); //if (profile != null && !string.IsNullOrEmpty(profile.DisplayName)) //{ // c.Author = profile.DisplayName; //} //c.Email = Membership.Provider.GetUser(Security.CurrentUser.Identity.Name, true).Email; //c.IP = WebUtils.GetClientIP(); //c.DateCreated = DateTime.Now; //c.Parent = post; var newComm = post.Comments.Where(cm => cm.Content == c.Content).FirstOrDefault(); return(_jsonService.GetComment(newComm, post.Comments.ToList())); } catch (Exception ex) { return(null); } }
/// <summary> /// insert comment detail to db /// </summary> /// <param name="cmd"></param> /// <returns></returns> public bool InsertCommentDetail(CommentDetail cmd) { try { db.CommentDetail.Add(cmd); db.SaveChanges(); return(true); } catch { return(false); } }
/// <summary> /// Get comment detail /// </summary> /// <param name="c">Comment</param> /// <returns>Json comment detail</returns> public static CommentDetail GetCommentDetail(Comment c) { var jc = new CommentDetail(); jc.Id = c.Id; jc.ParentId = c.ParentId; jc.PostId = c.Parent.Id; jc.Title = c.Teaser.Length < 80 ? c.Teaser : c.Teaser.Substring(0, 80) + "..."; jc.Content = c.Content; jc.Website = c.Website == null ? "" : c.Website.ToString(); jc.Ip = c.IP; return(jc); }
public bool CreateComment(CommentDetail model) { var entity = new Comment() { Text = model.Text }; using (var ctx = new ApplicationDbContext()) { ctx.Comments.Add(entity); return(ctx.SaveChanges() == 1); } }
public async Task <IActionResult> Comment(CommentViewModel model) { if (!ModelState.IsValid) { return(Json(new { Error = "提交的信息有误,请检查后再试" })); } var validateCode = _session.GetString("ValidateCode"); if (string.IsNullOrEmpty(validateCode)) { return(Json(new { Error = "验证码过期,请刷新重试!", })); } _session.Remove("ValidateCode"); if (!string.Equals(validateCode, model.Captcha, StringComparison.OrdinalIgnoreCase)) { return(Json(new { Error = "提交的验证码错误!", })); } var replyToCommentId = Request.Form["hiddenReplyTo"].ToString(); var post = _repo.GetPost(model.PostId); var commentDetail = new CommentDetail() { PostId = model.PostId, Author = await GetCurrentUserAsync(), Content = model.Content }; Guid parentId; if (!string.IsNullOrEmpty(replyToCommentId) && Guid.TryParse(replyToCommentId, out parentId)) { commentDetail.ParentId = parentId; } var comment = _commentsRepository.Add(commentDetail); var result = await _viewRenderService.RenderToStringAsync(this, "_Comment", comment); return(Json(new { Error = "", CommentId = comment.Id, CommentCount = (post.Comments.Count + 1), Result = result, Content = model.Content })); }
public IHttpActionResult Put(CommentDetail comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateCommentService(); if (!service.UpdateComment(comment)) { return(InternalServerError()); } return(Ok()); }
//GET : Delete public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CommentDetail comment = CreateCommentService().GetCommentsByID(id); if (comment == null) { return(HttpNotFound()); } return(View(comment)); }
public ActionResult CommentPhoto(CommentDetail commentDetail) { Authentication authentication = (Authentication)Session["authentication"]; if (authentication == null) { TempData["msg"] = "<script>alert('Please Log in First');</script>"; return(RedirectToAction("SignUpView", "SignUp")); } homeManager.SetPhotoComment(commentDetail, authentication.Id); return(RedirectToAction("CommentPhoto", "Home", new { photoId = commentDetail.PostID, typeNo = commentDetail.TypeNo })); }
public async Task <object> Map( [FromQuery][Required] long MapId, [FromServices] AppDbContext context) { var map = await context.Maps.FindAsync(MapId); if (map is null || map.Deleted) { return(StatusCode(404)); } return(map.Comments.AsQueryable() .Include(c => c.User).Include(c => c.LikeDislikes) .Select(c => CommentDetail.FromComment(c, false))); }
public object Info( [FromQuery][Required] long id, [FromServices] AppDbContext context) { var comment = context.Comments .Include(c => c.User).Include(c => c.LikeDislikes) .Where(c => c.Id == id).FirstOrDefault(); if (comment is null) { return(StatusCode(404)); } return(CommentDetail.FromComment(comment)); }