private void ReplyToProductComment(ProductComment productComment, IProductCommentCommand command) { var comment = _productCommentRepository.GetById(command.CommentId); productComment.ParentId = command.CommentId; AssigneCommentToProduct(comment, command); }
/// <summary> /// 添加一条评论 /// </summary> /// <param name="userid"></param> /// <param name="comment"></param> /// <returns></returns> public bool AddComment(int userid, string comment, int pid) { using (ShopEntities db = new ShopEntities()) { bool flag = false; using (var transaction = db.Database.BeginTransaction()) { try { ProductComment pc = new ProductComment(); pc.UserID = userid; pc.Comment = comment; pc.ProductID = pid; db.ProductComment.Add(pc); db.SaveChanges(); var p = db.Product.SingleOrDefault(o => o.ID == pid); if (p.ProductNumber > 0) { p.CmtNum = p.CmtNum + 1; } db.SaveChanges(); transaction.Commit(); flag = true; } catch (Exception ex) { transaction.Rollback(); } return(flag); } } }
public static void Add(ProductComment comment) { var info = comment.Map <ProductCommentInfo>(); Service.AddComment(info); comment.Id = info.Id; }
public async Task <ProductCommentsDto> Handle(Command request, CancellationToken cancellationToken) { var product = await _context.Products.FindAsync(request.ProductId); if (product == null) { throw new RestException(HttpStatusCode.NotFound, new { Product = "Not found" }); } var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == request.Username); var comment = new ProductComment { Author = user, Product = product, Body = request.Body, CreatedAt = DateTime.Now }; // job.Comments.Add(jobcomment); product.ProductComments.Add(comment); var success = await _context.SaveChangesAsync() > 0; if (success) { return(_mapper.Map <ProductCommentsDto>(comment)); } throw new Exception("Problem saving changes"); }
[Authorize] //登入會員才可留言 public ActionResult AddComment(int productId, string commentContent) { //如果留言為空 if (string.IsNullOrEmpty(commentContent)) { return(RedirectToAction("Details", new { id = productId })); } string userId = User.Identity.GetUserId(); DateTime datetime = DateTime.Now; ProductComment productComment = new ProductComment { ProductId = productId, Content = commentContent, UserId = userId, CreateDate = datetime }; using (CartsEntities db = new CartsEntities()) { db.ProductComments.Add(productComment); db.SaveChanges(); } return(RedirectToAction("Details", new { id = productId })); }
public ProductCommentPartialViewModel(ProductComment comment, ReplyCommentInputModel replyCommentInputModels, ProductRatingViewModel userProductRating, int commentCounter) { this.Comment = comment; this.UserProductRating = userProductRating; this.CommentCounter = commentCounter; this.ReplyCommentInputModel = replyCommentInputModels; }
public ActionResult ProductEvaluation(ModelProductComments modelProductComments) { String UserName = Session["UserName"].ToString(); ProductComment myComment = new ProductComment(); int PID = modelProductComments.product.ProductID; int CID = db.Customer.Where(x => x.UserName == UserName).Select(x => x.CustomerID).FirstOrDefault(); Product myProduct = db.Product.Where(x => x.ProductID == PID).Select(x => x).FirstOrDefault(); //comment is already in the database, so update the database with new comment. if (db.ProductComment.Where(x => x.CustomerID == CID && x.ProductID == PID).Select(x => x.CustomerID).FirstOrDefault() == CID) { myComment = db.ProductComment.Where(x => x.CustomerID == CID && x.ProductID == PID).Select(x => x).FirstOrDefault(); myProduct.ProductStar = ((myProduct.ProductStar * myProduct.ProductNumberOfEvaluate - myComment.ProductStar) + modelProductComments.productComment.ProductStar) / (myProduct.ProductNumberOfEvaluate); myComment.Comment = modelProductComments.productComment.Comment; myComment.ProductStar = modelProductComments.productComment.ProductStar; db.SaveChanges(); } else { //add the new comment to the database. myComment.ProductStar = modelProductComments.productComment.ProductStar; myComment.ProductID = PID; myComment.CustomerID = CID; myComment.CustomerName = db.Customer.Where(x => x.CustomerID == CID).Select(x => x.UserName).FirstOrDefault(); myComment.Comment = modelProductComments.productComment.Comment; db.ProductComment.Add(myComment); myProduct.ProductStar = ((myProduct.ProductStar * myProduct.ProductNumberOfEvaluate) + modelProductComments.productComment.ProductStar) / (myProduct.ProductNumberOfEvaluate + 1); myProduct.ProductNumberOfEvaluate += 1; db.SaveChanges(); } db.SaveChanges(); return(RedirectToAction("Home", "My")); }
private void InsertProductComment(ProductCommentsModel productCommentsModel, Product product) { bool productCommentsMustBeApproved = !_productCommentsSetting.ProductCommentsMustBeApproved; ProductComment productComment = new ProductComment() { ProductId = product.Id, CustomerId = _workContext.CurrentCustomer.Id, CommentText = productCommentsModel.AddProductComment.CommentText, HelpfulYesTotal = 0, HelpfulNoTotal = 0, IsApproved = productCommentsMustBeApproved, CreatedOnUtc = DateTime.UtcNow, StoreId = _storeContext.CurrentStore.Id, Visited = false }; _productCommentService.InsertProductComment(productComment); _productCommentModelFactory.PrepareProductCommentsModel(productCommentsModel, product); productCommentsModel.AddProductComment.CommentText = null; productCommentsModel.AddProductComment.SuccessfullyAdded = true; if (!productCommentsMustBeApproved) { productCommentsModel.AddProductComment.Result = _localizationService.GetResource("Comments.SeeAfterApproving"); return; } productCommentsModel.AddProductComment.Result = _localizationService.GetResource("Comments.SuccessfullyAdded"); }
private void Approve(int status) { try { bool isUpdated = false; foreach (GridDataItem data in grid.SelectedItems) { int commentId = Convert.ToInt32(data.GetDataKeyValue("CommentId")); ProductComment comment = new ProductComment(commentId); if (comment != null && comment.CommentId > -1) { comment.Status = status; if (comment.Save()) { isUpdated = true; LogActivity.Write("Approval comment", comment.FullName); } } } if (isUpdated) { message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "UpdateSuccessMessage"); BindGrid(); } } catch (Exception ex) { log.Error(ex); } }
public async Task <IActionResult> PostComment(ProductComment comment) { if (comment == null) { return(BadRequest(new { message = "Comment is null!" })); } if (string.IsNullOrEmpty(comment.Content)) { return(BadRequest(new { message = "Missing comment content" })); } if (string.IsNullOrEmpty(comment.Role)) { return(Unauthorized(new { message = "User is unauthorized!" })); } var newComment = await _commentService.PostCommentAsync(comment); return(Ok(new { status = "success", message = "Comment posted" })); }
public void Delete(int commentId) { try { Context.Response.ContentType = "application/json"; Encoding encoding = new UTF8Encoding(); Context.Response.ContentEncoding = encoding; if (!ProductPermission.CanDeleteComment) { Context.Response.Write("{\"Result\":\"Access Denined\"}"); return; } ProductComment comment = new ProductComment(commentId); if (comment != null && comment.CommentId > -1) { ProductComment.Delete(comment.CommentId); LogActivity.Write("Delete comment", comment.FullName); } Context.Response.Write("{\"Result\":\"Success\"}"); } catch (Exception ex) { log.Error(ex); Context.Response.Write("{\"Result\":\"Error\"}"); } }
public async Task <IActionResult> PutProductComment(int id, ProductComment productComment) { if (id != productComment.Id) { return(BadRequest()); } _context.Entry(productComment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductCommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(ProductComment comment) { try { comment.LastUpdate = DateTime.Now; ViewBag.Success = true; if (comment.ID == -1) { ProductComments.Insert(comment); UserNotifications.Send(UserID, String.Format("ویرایش نظر محصول '{0}'", comment.Subject), "/Admin/ProductComments/Edit/" + comment.ID, NotificationType.Success); comment = new ProductComment(); } else { ProductComments.Update(comment); } } catch (Exception ex) { SetErrors(ex); } return(ClearView(model: comment)); }
public JsonResult AddOrderEvaluationAndComment(int packMark, int deliveryMark, int serviceMark, long orderId, string productCommentsJSON) { if (packMark != 0 || deliveryMark != 0 || serviceMark == 0) { var info = new DTO.OrderComment(); info.UserId = CurrentUser.Id; info.PackMark = packMark; info.DeliveryMark = deliveryMark; info.ServiceMark = serviceMark; info.OrderId = orderId; TradeCommentApplication.Add(info); } var productComments = JsonConvert.DeserializeObject <List <ProductCommentsModel> >(productCommentsJSON); var list = new List <DTO.ProductComment>(); foreach (var productComment in productComments) { var model = new ProductComment(); model.ReviewDate = DateTime.Now; model.ReviewContent = productComment.content; model.UserId = CurrentUser.Id; model.UserName = CurrentUser.UserName; model.Email = CurrentUser.Email; model.SubOrderId = productComment.subOrderId; model.ReviewMark = productComment.star; if (productComment.proimages != null && productComment.proimages.Length > 0) { model.Images = new List <ProductCommentImage>(); foreach (var img in productComment.proimages) { var p = new ProductCommentImage(); p.CommentType = 0; //0代表默认的表示评论的图片 p.CommentImage = MoveImages(img, CurrentUser.Id); model.Images.Add(p); } } list.Add(model); } var comments = CommentApplication.GetProductEvaluationByOrderIdNew(orderId, CurrentUser.Id); foreach (var item in comments) { var addComment = productComments.FirstOrDefault(e => e.subOrderId == item.Id); if (addComment != null) { return(Json(new Result() { success = false, msg = "您已进行过评价!", status = -1 })); } } CommentApplication.Add(list); return(Json(new Result() { success = true, msg = "评价成功" })); }
private async Task SeedProductCommentsWithAttitude() { Product[] products = db.Products.ToArray(); var usersIds = db.Users.Select(x => x.Id).ToArray(); for (int i = 0; i < products.Length; i++) { Product currentProduct = products[i]; var randomUsersCommentorsIds = usersIds.OrderBy(x => random.Next()).Take(random.Next(0, (int)(usersIds.Length / 1.5))).ToArray(); foreach (var id in randomUsersCommentorsIds) { var comment = new ProductComment { AuthorId = id, Comment = GetRandom(Constants.ProductComments) }; var randomAttitudeGivvers = usersIds.Where(x => x != id).OrderBy(x => random.Next()).Take(random.Next(0, 4)).ToArray(); foreach (var attitudeGiver in randomAttitudeGivvers) { comment.UsersAttitude.Add(new CommentSympathy { SympathiserId = attitudeGiver, Attitude = (Attitude)random.Next(1, 3) }); } currentProduct.ProductComments.Add(comment); } } await db.SaveChangesAsync(); }
public ActionResult SubmitComment(string name, string email, string message, string urlParam) { try { Product product = db.Products.FirstOrDefault(current => current.Code == urlParam); if (product != null) { ProductComment comment = new ProductComment() { Id = Guid.NewGuid(), Name = name, Email = email, Message = message, IsDeleted = false, IsActive = false, CreationDate = DateTime.Now, ProductId = product.Id }; db.ProductComments.Add(comment); db.SaveChanges(); return(Json("true", JsonRequestBehavior.AllowGet)); } else { return(Json("false", JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json("false", JsonRequestBehavior.AllowGet)); } }
private void BindComments() { var iCount = ProductComment.GetCount(product.SiteId, product.ProductId, (int)commentType, 10, -1, -1, null, null, null); string pageUrl = ProductHelper.FormatProductUrl(product.Url, product.ProductId, product.ZoneId); pageUrl += "?cmtpg={0}"; pgr.PageURLFormat = pageUrl; pgr.ItemCount = iCount; pgr.CurrentIndex = pageNumber; divPager.Visible = (iCount > pgr.PageSize); var lstComments = ProductComment.GetPage(product.SiteId, product.ProductId, (int)commentType, 10, -1, -1, null, null, null, 0, pageNumber, pgr.PageSize); if (lstComments.Count > 0) { rptComments.DataSource = lstComments; rptComments.DataBind(); var lstTopComments = ProductComment.GetPage(product.SiteId, product.ProductId, (int)commentType, 10, 0, 1, null, null, null, 0, 1, 3); if (lstTopComments.Count > 0) { rptCommentTop.DataSource = lstTopComments; rptCommentTop.DataBind(); } } else { rptComments.Visible = false; } }
public void AddComment(ProductComment comment) { comment.CreateDate = DateTime.Now; comment.IsDelete = false; _context.ProductComments.Add(comment); _context.SaveChanges(); }
public ActionResult DeleteConfirmed(int id) { ProductComment productComment = db.ProductComments.Find(id); db.ProductComments.Remove(productComment); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ProductComment> PostCommentAsync(ProductComment comment) { await _context.ProductComments.AddAsync(comment); await _context.SaveChangesAsync(); return(comment); }
private int Create() { if (!Page.IsValid) { return(-1); } if (!reply) { return(-1); } if (!canApprove) { return(-1); } try { ProductComment cm = new ProductComment(); cm.ProductId = comment.ProductId; cm.ParentId = comment.CommentId; cm.FullName = txtFullName.Text.Trim(); cm.Email = txtEmail.Text.Trim(); cm.Title = txtCommentTitle.Text.Trim(); cm.Status = 1; cm.ContentText = txtComment.Text; cm.Rating = Convert.ToInt32(ratRating.Value); cm.CreatedFromIP = SiteUtils.GetIP4Address(); SiteUser siteUser = SiteUtils.GetCurrentSiteUser(); if (siteUser != null) { cm.UserId = siteUser.UserId; } cm.Status = 1; cm.IsModerator = true; if (comment.Status != 1) { comment.Status = 1; comment.Save(); } cm.Save(); LogActivity.Write("Reply comment", comment.FullName); message.SuccessMessage = ResourceHelper.GetResourceString("Resource", "InsertSuccessMessage"); return(cm.CommentId); } catch (Exception ex) { log.Error(ex.Message); } return(-1); }
public async Task EditCommentTextAsync(ProductComment comment, string text) { if (comment != null) { comment.Text = text; } comment.ModifiedOn = DateTime.UtcNow; await context.SaveChangesAsync(); }
public IActionResult CreateComment(ProductComment comment) { comment.IsDelete = false; comment.CreateDate = DateTime.Now; comment.UserId = _userService.GetUserIdByUserName(User.Identity.Name); _productService.AddComment(comment); return(View("ShowComment", _productService.GetProductComment(comment.ProductId))); }
public ProductCommentPartialViewModel(ProductComment comment, ReplyCommentInputModel replyCommentInputModels, ProductRatingViewModel userProductRating, string currentUserId, int commentCounter, int repliesCount = 0) { this.Comment = comment; this.UserProductRating = userProductRating; this.RepliesCount = repliesCount; this.CurrentUserId = currentUserId; this.CommentCounter = commentCounter; this.ReplyCommentInputModel = replyCommentInputModels; }
public void uruneYorumYap(Guid urunId, Guid bahsedenId, string yorum, List <Guid> bahsedilenler) { if (urunId != Guid.Empty && bahsedenId != Guid.Empty) { VotedressUserManager votedressUserManager = new VotedressUserManager(); VotedressUser bahseden = votedressUserManager.KullaniciGetir(bahsedenId); BahsedilenManager bahsedilenManager = new BahsedilenManager(); for (int i = 0; i < bahsedilenler.Count; i++) { bahsedilenManager.BahsedilenEkleUrun(urunId, bahsedenId, bahsedilenler[i], yorum); } ProductManager productManager = new ProductManager(); ProductComment productComment = productManager.UruneYorumEkle(urunId, bahsedenId, yorum); OnlineUserManager onlineUserManager = new OnlineUserManager(); List <OnlineUser> bahsedilenlerOnlineMi = onlineUserManager.OnlineKullaniciyiGetir(bahsedilenler); Clients.Group(urunId.ToString()).UruneYorumYapildi(productComment.id, bahseden.id, bahseden.UserDetail.Name + " " + bahseden.UserDetail.SurName, bahseden.ProfileImage, yorum, DateTime.Now); VotedressUser_sade votedressUser_sade_bahseden; Bahsedilen_sade bahsedilen_sade; for (int i = 0; i < bahsedilenlerOnlineMi.Count; i++) { votedressUser_sade_bahseden = new VotedressUser_sade() { id = bahsedilenlerOnlineMi[i].UserId, Birthday = bahsedilenlerOnlineMi[i].User.UserDetail.Birthday, Email = bahsedilenlerOnlineMi[i].User.Email, Name = bahsedilenlerOnlineMi[i].User.UserDetail.Name, ProfileImage = bahsedilenlerOnlineMi[i].User.ProfileImage, Sex = bahsedilenlerOnlineMi[i].User.UserDetail.Sex, SocialId = bahsedilenlerOnlineMi[i].User.SocialId, SocialName = bahsedilenlerOnlineMi[i].User.SocialName, SurName = bahsedilenlerOnlineMi[i].User.UserDetail.SurName }; bahsedilen_sade = new Bahsedilen_sade(); bahsedilen_sade.GorulmeDurumu = false; bahsedilen_sade.BahsetmeTarihi = DateTime.Now; bahsedilen_sade.Mesaj = yorum; bahsedilen_sade.TipId = urunId; bahsedilen_sade.Tip = "product"; bahsedilen_sade.bahsedilenYerAdi = productManager.UrunGetir(urunId).User.UserDetail.CompanyName; bahsedilen_sade.Bahseden = votedressUser_sade_bahseden; Clients.Client(bahsedilenlerOnlineMi[i].ConnectionId).SizdenBahsedildi(bahsedilen_sade); } } }
public ActionResult Edit(ProductComment comment) { if (ModelState.IsValid) { _repo.Update(comment); return(RedirectToAction("Index", new { productId = comment.ProductId })); } return(View(comment)); }
public virtual void UpdateProductComment(ProductComment productComment) { if (productComment == null) { throw new ArgumentNullException("productComment"); } _productCommentRepository.Update(productComment); }
public ActionResult DeleteConfirmed(Guid id) { ProductComment productComment = db.ProductComments.Find(id); productComment.IsDeleted = true; productComment.DeletionDate = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Index", new { id = productComment.ProductId })); }
public IActionResult CreateComment(ProductComment comment) { comment.isDelete = false; comment.CreateDate = DateTime.Now; comment.UserID = _userServices.getuseridbyusername(User.Identity.Name); _productServices.AddComment(comment); return(View("ShowComment", _productServices.getproductcomment(comment.ProductID))); }
/// <summary> /// 更新ProductComment信息 /// </summary> public void UpdateProductComment(ProductComment entity) { IDataCommand cmd = IocManager.Instance.Resolve <IDataCommand>(); cmd.CreateCommand("UpdateProductComment"); //DataCommand cmd = new DataCommand("UpdateProductComment"); cmd.SetParameter <ProductComment>(entity); cmd.ExecuteNonQuery(); }
/// <summary> /// Will add comment on selected product with Ajax post from client side /// </summary> /// <param name="ProductID"></param> /// <param name="CommentText"></param> /// <returns></returns> public JsonResult CommentAdd(int ProductID, string CommentText) { ProductComment pc = new ProductComment() { Comment = (CommentText + "").Trim(), ProductID = ProductID }; ProductDAL.addComment(pc); return Json(true, JsonRequestBehavior.AllowGet); }