/// <summary> /// 评论管理 /// </summary> /// <returns></returns> public ActionResult Comments(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 0, int pageSize = 20) { //显示 if (string.IsNullOrEmpty(act)) { string filterSql = $"state=1 and aid={aId} and storeid={storeId}"; ViewModel <DishComment> vm = new ViewModel <DishComment>(); vm.DataList = DishCommentBLL.SingleModel.GetListBySql($"select * from dishcomment where {filterSql} order by id desc limit {pageIndex * pageSize},{pageSize}"); vm.PageIndex = pageIndex; vm.PageSize = pageSize; vm.TotalCount = DishCommentBLL.SingleModel.GetCount(filterSql); vm.aId = aId; vm.storeId = storeId; return(View(vm)); } else { //删除 if (act == "del") { if (id <= 0) { _result.msg = "参数错误"; } else { DishComment updateModel = DishCommentBLL.SingleModel.GetModel(id); if (updateModel != null) { updateModel.state = -1; bool updateResult = DishCommentBLL.SingleModel.Update(updateModel); if (updateResult) { _result.code = 1; _result.msg = "删除成功"; } else { _result.msg = "删除失败"; } } else { _result.msg = "删除失败,评论不存在或已删除"; } } } } return(Json(_result, JsonRequestBehavior.AllowGet)); }
public JsonResult Delete(DishStore store, int?commentId) { if (!commentId.HasValue) { return(ApiModel(message: "参数不能为空[commentId]")); } DishComment comment = DishCommentBLL.SingleModel.GetModel(commentId.Value); if (comment == null || comment.storeId != store.id) { return(ApiModel(message: "非法操作")); } bool success = DishCommentBLL.SingleModel.DeleteComment(comment); return(ApiModel(isok: success, message: success ? "删除成功" : $"删除失败[{commentId}]")); }
public string AddDishComment(dynamic requestData) { try { //增加留言 string addDishComment = JsonConvert.SerializeObject(requestData); DishComment model = JsonConvert.DeserializeObject <DishComment>(addDishComment); db.DishComment.Add(model); db.SaveChanges(); var q = (from v in db.DishComment where v.DishId == model.DishId select v); var count = q.Count(); var lastq = q.OrderByDescending(v => v.CreateTime).Skip(0).Take(3); //查找HotelName var lastResult = (from v in lastq join p in db.OpenIdAssociated on v.OpenId equals p.OpenId join n in db.RegistMember on p.UserId equals n.MemberId select new { HeadPicUrl = v.HeadPicUrl, MemebName = v.MemberName, Comment = v.Comment, CreateTime = v.CreateTime, HotelName = n.HotelName }); return("{ \"Count\":\"" + count + "\",\"data\":" + JsonConvert.SerializeObject(lastResult, DateTimeConvent.DateTimehh()) + "}"); } catch (Exception) { return("{\"Count\":0}"); } }