public YZ_CommodityCommentVM(YZ_CommodityComment bo) { Id = bo.Id; Commodity = bo.Commodity; Name = bo.Name; Description = bo.Description; CreateTime = bo.CreateTime; CommentUser = new ApplicationUserVM(bo.CommentUser); }
public async Task <IActionResult> SubmitComment(YZ_CommodityCommentVM input) { if (input.Id == Guid.Empty) { return(Json(new { result = false, message = "留言失败!" })); } if (string.IsNullOrEmpty(input.Description)) { return(Json(new { result = false, message = "请填写留言内容!" })); } var user = GetUser(); var userComment = await GetCommodityComment(x => x.CommentUser == user && x.Commodity.Id == input.Id); if (userComment != null) { TimeSpan ts = (DateTime.Now - userComment.CreateTime); if (ts.Minutes < 3) { return(Json(new { result = false, message = "操作过于频繁,距离上一次留言时间过短\n请几分钟后再来留言吧!" })); } } if (user == null) { return(Json(new { result = false, noLogin = true, message = "您未登录无法进行留言,是否现在登录?" })); } var commodity = await GetCommodity(input.Id); if (commodity != null) { var newComment = new YZ_CommodityComment { CommentUser = user, Commodity = commodity, Description = EncodeFilterHelper.EncodeHtmlToNull(input.Description) }; var r = await _commodityComment.AddOrEditAndSaveAsyn(newComment); if (r) { if (commodity.AscriptionUser != user) { //发送消息通知 var message = "用户[ " + user.ChineseFullName + " ] 在 [ " + DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss") + " ] 给您的商品 [ " + commodity.Name + " ] 留了言,可能是有意向购买,您可以点击链接查看。"; var notification = new Notification { Receiver = commodity.AscriptionUser, Name = "商品留言", Description = message, Link = "../../Home/GetCommodityDetail?id=" + commodity.Id, IsAbnormal = false, IsRead = false, NotificationSource = NotificationSourceEnum.App }; AppNotification.SendNotification(notification); } return(Json(new { result = true })); } return(Json(new { result = false, message = "留言失败!" })); } return(Json(new { result = false, message = "留言失败!" })); }