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 async Task <IActionResult> DeleteUnit(int id, IFormCollection form) { ProductComments comments = await _unitOfWork.Repository <ProductComments>().GetByIdAsync(id); if (comments != null) { await _unitOfWork.Repository <ProductComments>().DeleteAsync(comments); } return(RedirectToAction(nameof(Index))); }
public ActionResult CommentEdite(ProductComments Model) { if (ModelState.IsValid) { db.Entry(Model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ProductCommentManage")); } return(RedirectToAction("ProductCommentManage")); }
public ActionResult CommentEdite(int id) { ProductComments model = db.ProductCommentses.Find(id); if (model.ParentID != null) { ViewBag.parenttext = db.ProductCommentses.Find(model.ParentID).Comment; } return(PartialView(model)); }
public ActionResult UpdateProductComment(ProductComments entityComments) { var admin_cerez = Request.Cookies["admin_cerezim"]; var data = db.ProductComments.Where(x => x.ID == entityComments.ID).FirstOrDefault(); if (data != null) { data.IsApproved = entityComments.IsApproved; db.SaveChanges(); return(RedirectToAction("ProductComments", "Admin")); } return(View()); }
public async Task <JsonResult> Get(int pageIndex, int pageSize, string pageOrder, int?productID, string email, byte?commentStatus) { CommentStatus?status = null; if (commentStatus.HasValue && commentStatus != -1) { status = (CommentStatus)commentStatus; } var list = ProductComments.Get(pageIndex, pageSize, pageOrder, productID, email, status); foreach (var item in list) { item.UserFullName = item.UserID != null ? (await UserManager.FindByIdAsync(item.UserID)).Firstname + " " + (await UserManager.FindByIdAsync(item.UserID)).Lastname : item.UserName; } int total = ProductComments.Count(productID, email, status); int totalPage = (int)Math.Ceiling((decimal)total / pageSize); if (pageSize > total) { pageSize = total; } if (list.Count < pageSize) { pageSize = list.Count; } JsonResult result = new JsonResult() { Data = new { TotalPages = totalPage, PageIndex = pageIndex, PageSize = pageSize, Rows = list }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return(result); }
public async Task <IActionResult> AddComment(string commentMessage, int pro) { if (commentMessage != null) { ApplicationUsers user = _userManager.GetUserAsync(HttpContext.User).Result; ProductComments comments = new ProductComments(); comments.Comment = commentMessage; comments.ProductId = pro; comments.AddedDate = DateTime.Now; comments.ModifiedDate = DateTime.Now; comments.UserId = user.Id; await _unitOfWork.Repository <ProductComments>().InsertAsync(comments); } return(RedirectToAction("ProductDetails", new { product = pro })); }
public ActionResult Edit(int?id) { ProductComment comment; if (id.HasValue) { comment = ProductComments.GetByID(id.Value); } else { comment = new ProductComment(); } return(View(model: comment)); }
public JsonResult Delete(int id) { var jsonSuccessResult = new JsonSuccessResult(); try { ProductComments.Delete(id); jsonSuccessResult.Success = true; } catch (Exception ex) { jsonSuccessResult.Errors = new string[] { ex.Message }; jsonSuccessResult.Success = false; } return(new JsonResult() { Data = jsonSuccessResult }); }
public List <ProductComments> ShowListComments(int ProductId) { try { var qComment = database.Tbl_Comments.Where(c => c.ProductId_FK == ProductId && c.ConfirmComment == true) .OrderByDescending(c => c.CommentId).ToList(); if (qComment == null) { return(null); } List <ProductComments> lstComments = new List <ProductComments>(); foreach (var item in qComment) { if (item != null) { UserRepository Rep_User = new UserRepository(); var qUserId = Rep_User.GetUserById(item.UserId_FK); ProductComments vm = new ProductComments(); // => Is ViewModel vm.CommentId = item.CommentId; vm.DateComment = item.DateComment; vm.FulllName = qUserId.FirstName + " " + qUserId.LastName; vm.Email = item.Email; vm.ProductId_FK = item.ProductId_FK; vm.Text = item.Text; vm.Title = item.Title; vm.UserId_FK = qUserId.Id; lstComments.Add(vm); } } return(lstComments ?? null); } catch { throw; } }
public JsonResult Confirm(List <int> ids) { var jsonSuccessResult = new JsonSuccessResult(); try { ProductComments.Confirm(ids); jsonSuccessResult.Success = true; } catch (Exception ex) { jsonSuccessResult.Errors = new string[] { ex.Message }; jsonSuccessResult.Success = false; } return(new JsonResult() { Data = jsonSuccessResult }); }
public ActionResult AddProductComment(ProductComments productComments, int id) { var user_cerez = Request.Cookies["cerezim"]; if (ModelState.IsValid) { if (user_cerez == null) { return(RedirectToAction("Login", "Account")); } productComments.ProductID = id; productComments.CreatedDate = DateTime.Now; db.ProductComments.Add(productComments); db.SaveChanges(); Response.Redirect(Request.UrlReferrer.ToString()); } else { ViewBag.Error = "Lütfen tüm alanları doldurunuz"; } return(View()); }
public ActionResult AddComment(AddCommentViewModel model, int qualityRate, int worthRate) { if (ModelState.IsValid == false) { return(RedirectToAction("ShowProduct", new { id = model.ProductId })); } var user = db.AccountRepository.GetUserByEmail(User.Identity.Name.ToLower()); var comment = new ProductComments { CommentTitle = "Comment", CreateDate = DateTime.Now, Rate = (qualityRate + worthRate) / 2, Text = model.Text, ProductId = model.ProductId, UserId = user.UserId, ParentId = model.ParentId }; db.ProductCommentsRepository.Insert(comment); var product = db.ProductsRepository.GetById(model.ProductId); product.ProductRate = product.ProductComments.Select(r => r.Rate).Sum() / product.ProductComments.Count; db.Save(); var comments = product.ProductComments.AsEnumerable(); if (model.ParentId != null) { comments = comments.Reverse(); } return(PartialView("ShowComments", comments)); }
public async Task <IActionResult> DeleteComment(int id) { ProductComments comments = await _unitOfWork.Repository <ProductComments>().GetByIdAsync(id); return(PartialView("_DeleteComment", comments?.Comment)); }