public async Task <IActionResult> Add(string content, string user, string comment, string article) { string ip = _accessor.HttpContext.Connection.RemoteIpAddress.ToString(); //ip = "106.12.126.88"; var address = await IpService.GetIpCity(ip); user = base._UserInfo.UserId; if (string.IsNullOrEmpty(user)) { return(ErrRes("请先登陆")); } var commentModel = await _unitOfWork.SysCmsInfoCommentRepository.GetAsync(comment); SysCmsInfoComment sysCmsInfoComment = new SysCmsInfoComment { SysCmsInfoId = article, SysCmsInfoCommentId = GuidKey, Ip = ip, Status = 1, Address = address, Comment = content, CommentTime = DateTime.Now, SysUserId = user, ToCommentId = comment, UserLable = user == "admin"?"1":"2", }; var articleModel = await _unitOfWork.SysCmsInfoRepository.GetAsync(article); if (articleModel != null) { sysCmsInfoComment.SysCmsColumnId = articleModel.SysCmsColumnId; articleModel.InfoComments = articleModel.InfoComments + 1; } if (commentModel != null) { sysCmsInfoComment.ToUserId = commentModel.SysUserId; } var result = _unitOfWork.SysCmsInfoCommentRepository.Insert(sysCmsInfoComment); if (articleModel != null) { result = _unitOfWork.SysCmsInfoRepository.Update(articleModel); } if (result) { if (string.IsNullOrEmpty(comment)) { var formartComment = _sysCmsInfoCommentService.GetComment(sysCmsInfoComment.SysCmsInfoCommentId); return(SuccessRes(formartComment)); } else { var formartComment = _sysCmsInfoCommentService.GetReply(sysCmsInfoComment.SysCmsInfoCommentId); return(SuccessRes(formartComment)); } } return(ErrRes("添加留言失败失败")); }
public async Task <IActionResult> Save(SysCmsInfoComment model, string columns = "") { var errMsg = GetModelErrMsg(); if (!string.IsNullOrEmpty(errMsg)) { return(ErrRes(errMsg)); } model.Status = model.Status ?? 2; if (string.IsNullOrEmpty(model.SysCmsInfoCommentId)) { model.SysCmsInfoCommentId = GuidKey; model.CommentTime = DateTime.Now; result = await _unitOfWork.SysCmsInfoCommentRepository.InsertAsync(model); if (result) { _logger.LogInformation($"添加{_entityName}{model.SysCmsInfoCommentId}"); } } else { //定义可以修改的列 var lstColumn = new List <string>() { nameof(SysCmsInfoComment.Address), nameof(SysCmsInfoComment.Comment), nameof(SysCmsInfoComment.Status), nameof(SysCmsInfoComment.CommentTime), nameof(SysCmsInfoComment.UserLable), nameof(SysCmsInfoComment.ToUserId), nameof(SysCmsInfoComment.ToUserId) }; if (!string.IsNullOrEmpty(columns))//固定过滤只修改某字段 { if (lstColumn.Count == 0) { lstColumn = columns.Split(',').ToList(); } else { lstColumn = lstColumn.Where(o => columns.Split(',').Contains(o)).ToList(); } } result = await _unitOfWork.SysCmsInfoCommentRepository.UpdateAsync(model, true, lstColumn); if (result) { _logger.LogInformation($"修改{_entityName}{model.SysCmsInfoCommentId}"); } } return(result ? SuccessRes() : ErrRes()); }