/// <summary> /// Save the customer comment /// </summary> /// <param name="customerCommentVO">Value object of customer comment</param> public void SaveCustomerComment(CustomerCommentVO customerCommentVO) { if (customerCommentVO.CustomerCommentId == 0) { //Insert New Record CustomerComment newCustomerComment = new CustomerComment(); newCustomerComment.CustomerID = customerCommentVO.InvoiceCustomerId; newCustomerComment.OACustomer = mdbDataContext.OACustomers.Where(c => c.ID == customerCommentVO.InvoiceCustomerId).SingleOrDefault(); newCustomerComment.CustomerName = newCustomerComment.OACustomer.CustomerName; //newCustomerComment.CustomerName = customerCommentVO.InvoiceCustomerName; newCustomerComment.CompanyID = customerCommentVO.CompanyId; newCustomerComment.Comment = customerCommentVO.CustomerComment; newCustomerComment.Group = customerCommentVO.Group; newCustomerComment.CreationDate = DateTime.Now; newCustomerComment.CreatedBy = customerCommentVO.CreatedByUserId; mdbDataContext.CustomerComments.InsertOnSubmit(newCustomerComment); mdbDataContext.SubmitChanges(); } else { //Update Existing Record CustomerComment selectedCustomerComment = mdbDataContext.CustomerComments.SingleOrDefault(c => c.ID == customerCommentVO.CustomerCommentId); selectedCustomerComment.CustomerID = customerCommentVO.InvoiceCustomerId; selectedCustomerComment.OACustomer = mdbDataContext.OACustomers.Where(c => c.ID == customerCommentVO.InvoiceCustomerId).SingleOrDefault(); selectedCustomerComment.CustomerName = selectedCustomerComment.OACustomer.CustomerName; //selectedCustomerComment.CustomerName = customerCommentVO.InvoiceCustomerName; selectedCustomerComment.CompanyID = customerCommentVO.CompanyId; selectedCustomerComment.Comment = customerCommentVO.CustomerComment; selectedCustomerComment.Group = customerCommentVO.Group; selectedCustomerComment.LastUpdatedDate = DateTime.Now; selectedCustomerComment.LastUpdatedBy = customerCommentVO.LastUpdatedByUserId; mdbDataContext.SubmitChanges(); } }
public ActionResult Edit(CustomerComment customerComment) { try { var files = Utilities.SaveFiles(Request.Files, Utilities.GetNormalFileName(customerComment.UserName), StaticPaths.CustomerImages); if (files.Count > 0) { customerComment.Image = files[0].Title; } customerComment.LastUpdate = DateTime.Now; ViewBag.Success = true; if (customerComment.ID == -1) { CustomerComments.Insert(customerComment); UserNotifications.Send(UserID, String.Format("جدید - سخن مشتریان '{0}'", customerComment.Text), "/Admin/CustomerComments/Edit/" + customerComment.ID, NotificationType.Success); customerComment = new CustomerComment(); } else { CustomerComments.Update(customerComment); } } catch (Exception ex) { SetErrors(ex); } return(ClearView(customerComment)); }
public async Task WhenCreate_ThenSuccess() { var headers = await _defaultRequestHeadersService.GetAsync(); var source = await _create.CustomerSource.BuildAsync(); var customer = await _create.Customer .WithSourceId(source.Id) .BuildAsync(); var comment = new CustomerComment { Id = Guid.NewGuid(), CustomerId = customer.Id, Value = "Test".WithGuid() }; await _customerCommentsClient.CreateAsync(comment, headers); var request = new CustomerCommentGetPagedListRequest { CustomerId = customer.Id }; var createdComment = (await _customerCommentsClient.GetPagedListAsync(request, headers)).Comments.First(); Assert.NotNull(createdComment); Assert.Equal(comment.CustomerId, createdComment.CustomerId); Assert.True(!createdComment.CommentatorUserId.IsEmpty()); Assert.Equal(comment.Value, createdComment.Value); Assert.True(createdComment.CreateDateTime.IsMoreThanMinValue()); }
public Task CreateAsync( CustomerComment comment, Dictionary <string, string> headers = default, CancellationToken ct = default) { return(_factory.PostAsync(_host + "/Customers/Comments/v1/Create", null, comment, headers, ct)); }
public async Task <ActionResult> Create(CustomerComment comment, CancellationToken ct = default) { var customer = await _customersService.GetAsync(comment.CustomerId, false, ct); return(await ActionIfAllowed( () => _customerCommentsService.CreateAsync(_userContext.UserId, comment, ct), Roles.Customers, customer.AccountId)); }
/// <summary> /// Get check whether customer is grouped or not /// </summary> /// <param name="companyId">The company id</param> /// <param name="customerId">The customer id</param> /// <returns>value object of customer comment</returns> public CustomerCommentVO GetCustomerCommentByCompanyIdAndCustomerId(int companyId, int customerId) { CustomerComment customerComment = mdbDataContext.CustomerComments.FirstOrDefault(c => c.CompanyID == companyId && c.CustomerID == customerId && !c.IsDeleted); CustomerCommentVO customerCommentVO = customerComment != null ? new CustomerCommentVO(customerComment) : new CustomerCommentVO(); return(customerCommentVO); }
public CustomerCommentBuilder( IDefaultRequestHeadersService defaultRequestHeadersService, ICustomerCommentsClient customerCommentsClient) { _customerCommentsClient = customerCommentsClient; _defaultRequestHeadersService = defaultRequestHeadersService; _comment = new CustomerComment { Id = Guid.NewGuid(), Value = "Test".WithGuid() }; }
/// <summary> /// Gets customer comment details by Id /// </summary> /// <param name="customerCommentId">customerCommentId</param> /// <returns>Customer comment details</returns> public CustomerCommentVO GetCustomerCommentById(int customerCommentId) { CustomerComment customerComment = mdbDataContext.CustomerComments.SingleOrDefault(c => c.ID == customerCommentId); CustomerCommentVO customerCommentVO = null; if (customerComment != null) { customerCommentVO = new CustomerCommentVO(customerComment); } return(customerCommentVO); }
public async Task CreateAsync(Guid userId, CustomerComment comment, CancellationToken ct) { var newComment = new CustomerComment { Id = Guid.NewGuid(), CustomerId = comment.CustomerId, CommentatorUserId = userId, Value = comment.Value, CreateDateTime = DateTime.UtcNow }; await _storage.AddAsync(newComment, ct); await _storage.SaveChangesAsync(ct); }
public ActionResult Edit(int?id) { CustomerComment comment; if (id.HasValue) { comment = CustomerComments.GetByID(id.Value); } else { comment = new CustomerComment(); } return(View(comment)); }
/// <summary> /// Transpose LINQ object to Value object /// </summary> /// <param name="customerComment">LINQ customerComment object</param> public CustomerCommentVO(CustomerComment customerComment) { CustomerCommentId = customerComment.ID; InvoiceCustomerId = customerComment.CustomerID; OldCustomerId = customerComment.OACustomer.CustomerID; InvoiceCustomerName = customerComment.CustomerName; //InvoiceCustomerName = customerComment.OACustomer.CustomerName;// customerComment.CustomerName; InvoiceCustomer = InvoiceCustomerName + '-' + OldCustomerId; CompanyId = customerComment.CompanyID; CompanyName = customerComment.OACompany.CompanyName; Company = customerComment.OACompany.CompanyName + '-' + customerComment.CompanyID; CustomerComment = customerComment.Comment; Group = (customerComment.Group ? customerComment.Group : false); CreatedByUserId = customerComment.CreatedBy; LastUpdatedByUserId = customerComment.LastUpdatedBy; }
public async Task <IActionResult> Post([FromForm] int?customerId, [FromForm] string comment) { if (customerId == null || string.IsNullOrEmpty(comment)) { return(BadRequest()); } CustomerComment customerComment = new CustomerComment() { Comment = comment, CustomerId = customerId.Value, TimeStamp = DateTime.Now }; CustomerContext.CustomerComments.Add(customerComment); await CustomerContext.SaveChangesAsync(); return(Ok(customerComment)); }
/// <summary> /// 提交评论 /// </summary> /// <param name="CommentFrom"></param> /// <returns></returns> public bool SubmitComment(CommentFrom CommentFrom) { CustomerComment comment = new CustomerComment { CustomerID = CommentFrom.CustomerID, OrderID = CommentFrom.OrderID, ProductID = CommentFrom.ProductID, Reply = CommentFrom.Reply }; if (_db.Insertable(comment).ExecuteCommand() > 0) { return(ChangeCustomerSign(CommentFrom.CustomerID, SignEnum.添加评论10点积分)); } else { throw new Exception("提交评论异常!"); } }
public ActionResult Add(FormCollection form) { var comment = form["Comment"].ToString(); var articleId = int.Parse(form["ProductId"]); var rating = int.Parse(form["Rating"]); var email = form["Email"].ToString(); CustomerComment comments = new CustomerComment() { PID = articleId, Comments = comment, Rating = rating, Email = email, ThisDateTime = DateTime.Now }; _ctx.CustomerComments.Add(comments); _ctx.SaveChanges(); return(RedirectToAction("comments", "Home", new { id = articleId })); }
/// <summary> /// Gets the customer comment /// </summary> /// <param name="comment">comment</param> /// <param name="companyId">company Id</param> /// <param name="customerId">customer Id</param> /// <returns>customer comment</returns> public CustomerCommentVO GetCustomerCommentByName(string comment, int companyId, int customerId) { CustomerComment customercomment = null; if (!string.IsNullOrEmpty(comment)) { customercomment = mdbDataContext.CustomerComments.Where(c => c.Comment.Equals(comment) && c.CompanyID == companyId && c.CustomerID == customerId && c.IsDeleted == false).SingleOrDefault(); } else { customercomment = mdbDataContext.CustomerComments.Where(c => c.CompanyID == companyId && c.CustomerID == customerId && c.IsDeleted == false).SingleOrDefault(); } CustomerCommentVO customerCommentVO = null; if (customercomment != null) { customerCommentVO = new CustomerCommentVO(customercomment); } return(customerCommentVO); }
/// <summary> /// Edit customer comment /// </summary> /// <param name="id">The customer comment id</param> /// <returns>Customer comment details</returns> public ActionResult CustomerCommentEdit(int id) { MODEL.CustomerComment customercomment = new CustomerComment(); try { CustomerCommentService customerCommentService = new CustomerCommentService(); //Get Customercomment details CustomerCommentVO customerCommentVO = customerCommentService.GetCustomerCommentById(id); if (customerCommentVO == null) { ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.CUSTOMERCOMMENT)); } else { customercomment = new CustomerComment(customerCommentVO); } } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(PartialView("CustomerCommentDetails", customercomment)); }
private CustomerCommentPublicModel PrepareCommentPublicModel(CustomerComment comment, IEnumerable <Customer> customers) { //get the customer var customer = customers.FirstOrDefault(x => x.Id == comment.CustomerId); if (customer == null) { return(null); } var likeStatus = _customerLikeService.GetCustomerLike <CustomerComment>(_workContext.CurrentCustomer.Id, comment.Id) == null ? 0 : 1; //and create it's response model var cModel = new CustomerCommentPublicModel() { EntityName = comment.EntityName, EntityId = comment.EntityId, CommentText = comment.CommentText, AdditionalData = comment.AdditionalData, Id = comment.Id, DateCreatedUtc = comment.DateCreated, DateCreated = _dateTimeHelper.ConvertToUserTime(comment.DateCreated, DateTimeKind.Utc), CanDelete = comment.CustomerId == _workContext.CurrentCustomer.Id || _workContext.CurrentCustomer.IsAdmin(), IsSpam = false, //TODO: change it when spam system has been implemented LikeCount = _customerLikeService.GetLikeCount <CustomerComment>(comment.Id), CustomerName = customer.GetFullName(), CustomerProfileUrl = Url.RouteUrl("CustomerProfileUrl", new RouteValueDictionary() { { "SeName", customer.GetSeName(_workContext.WorkingLanguage.Id, true, false) } }), CustomerProfileImageUrl = _pictureService.GetPictureUrl( customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, true), LikeStatus = likeStatus }; return(cModel); }
/// <summary> /// Delete the Customer comment(s) /// </summary> /// <param name="Ids">Ids of customercomments to be deleted</param> /// <param name="userId">The logged in user id</param> public void DeleteCustomerComment(List <int> Ids, int?userId) { CustomerComment deleteCustomerComment = new CustomerComment(); foreach (var id in Ids) { if (id != 0) { deleteCustomerComment = mdbDataContext.CustomerComments.Where(c => c.ID == id).SingleOrDefault(); //To check weather Invoice Customer is associated with contrat or not Contract contract = mdbDataContext.Contracts.Where(c => c.InvoiceCustomerID == deleteCustomerComment.CustomerID && c.CompanyID == deleteCustomerComment.CompanyID && !c.IsDeleted).FirstOrDefault(); if (contract == null) { deleteCustomerComment.IsDeleted = true; deleteCustomerComment.LastUpdatedBy = userId; deleteCustomerComment.LastUpdatedDate = DateTime.Now; } } } mdbDataContext.SubmitChanges(); }
public IHttpActionResult Post(CustomerCommentModel model) { if (!ModelState.IsValid) { return(Response(new { Success = false })); } //save the comment var comment = new CustomerComment() { AdditionalData = model.AdditionalData, CommentText = model.CommentText, EntityName = model.EntityName, EntityId = model.EntityId, DateCreated = DateTime.UtcNow, DateUpdated = DateTime.UtcNow, CustomerId = _workContext.CurrentCustomer.Id }; _customerCommentService.Insert(comment); var cModel = PrepareCommentPublicModel(comment, new[] { _workContext.CurrentCustomer }); return(Response(new { Success = true, Comment = cModel })); }