public string FollowsAll() { ApiResult result = new ApiResult(); try { var CreateUserNumber = ZNRequest.GetString("CreateUserNumber"); if (string.IsNullOrWhiteSpace(CreateUserNumber)) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } var CurrUserNumber = ZNRequest.GetString("CurrUserNumber"); if (string.IsNullOrWhiteSpace(CurrUserNumber)) { CurrUserNumber = CreateUserNumber; } var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <Fan>().Where <Fan>(x => x.CreateUserNumber == CreateUserNumber); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Fan>(); var array = list.Select(x => x.ToUserNumber).Distinct().ToList(); var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Signature", "Number").From <User>().Where <User>(x => x.Status == Enum_Status.Approved).And("Number").In(array.ToArray()).ExecuteTypedList <User>(); var follows = db.Find <Fan>(x => x.CreateUserNumber == CurrUserNumber).ToList(); var newlist = (from l in list join u in users on l.ToUserNumber equals u.Number select new { ID = l.ID, CreateDate = FormatTime(l.CreateDate), UserID = u.ID, Cover = u.Cover, NickName = u.NickName, Signature = u.Signature, Avatar = u.Avatar, Number = u.Number, IsFollow = follows.Exists(x => x.ToUserNumber == u.Number) ? 1 : 0 }).ToList(); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Fan_FollowsAll:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string ToUser_1_3() { ApiResult result = new ApiResult(); try { var UserNumber = ZNRequest.GetString("UserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var query = new SubSonic.Query.Select(provider).From <Order>().Where <Order>(x => x.Status == Enum_Status.Approved); query = query.And("CreateUserNumber").IsEqualTo(UserNumber); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Order>(); var userarray = list.Select(x => x.ToUserNumber).Distinct().ToList(); var allusers = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number", "Cover").From <User>().And("Number").In(userarray.ToArray()).ExecuteTypedList <User>(); List <OrdersJson> newlist = new List <OrdersJson>(); list.ForEach(x => { var user = allusers.FirstOrDefault(y => y.Number == x.ToUserNumber); if (user != null) { OrdersJson model = new OrdersJson(); model.ID = x.ID; model.CreateDate = x.CreateDate.ToString("yyyy-MM-dd hh:mm:ss"); model.Price = x.Price; model.UserID = user.ID; model.UserNumber = user.Number; model.UserAvatar = user.Avatar; model.UserName = user.NickName; model.UserCover = user.Cover; newlist.Add(model); } }); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Order_ToUser_1_3:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string LinkAll() { ApiResult result = new ApiResult(); try { User user = GetUserInfo(); if (user == null) { result.message = EnumBase.GetDescription(typeof(Enum_ErrorCode), Enum_ErrorCode.UnLogin); result.code = Enum_ErrorCode.UnLogin; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var query = new SubSonic.Query.Select(provider, "ID", "Number", "Title", "Cover", "CreateUserNumber", "CreateDate", "ArticlePower", "ArticlePowerPwd").From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.Submission >= Enum_Submission.Approved); query = query.And("CreateUserNumber").IsEqualTo(user.Number); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var sort = new string[] { "ID" }; var list = query.Paged(pager.Index, pager.Size).OrderDesc(sort).ExecuteTypedList <Article>(); var newlist = (from l in list select new { ID = l.ID, Number = l.Number, Title = l.Title, Cover = l.Cover, CreateDate = l.CreateDate.ToString("yyyy-MM-dd hh:mm:ss"), ArticlePower = l.ArticlePower, ArticlePowerPwd = l.ArticlePowerPwd }); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Article_LinkAll:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string All() { ApiResult result = new ApiResult(); try { var CreateUserNumber = ZNRequest.GetString("CreateUserNumber"); if (string.IsNullOrWhiteSpace(CreateUserNumber)) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <Black>().Where <Black>(x => x.CreateUserNumber == CreateUserNumber); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var list = query.OrderDesc("ID").ExecuteTypedList <Black>(); var array = list.Select(x => x.ToUserNumber).ToArray(); var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Signature", "Number", "Cover").From <User>().Where("Number").In(array).ExecuteTypedList <User>(); var newlist = (from b in list join u in users on b.ToUserNumber equals u.Number select new BlackJson { ID = b.ID, CreateDate = b.CreateDate.ToString("yyyy-MM-dd"), UserID = u.ID, Number = u.Number, NickName = u.NickName, Avatar = u.Avatar, Signature = u.Signature, Cover = u.Cover }).ToList(); result.result = true; result.message = new { currpage = 1, records = newlist.Count, totalpage = 1, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Black_All:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string Search() { ApiResult result = new ApiResult(); try { var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.ArticlePower == Enum_ArticlePower.Public && x.Submission >= Enum_Submission.Approved); var title = SqlFilter(ZNRequest.GetString("Title")); if (!string.IsNullOrWhiteSpace(title)) { query.And("Title").IsNotNull().And("Title").Like("%" + title + "%"); } var UserNumber = ZNRequest.GetString("UserNumber"); if (!string.IsNullOrWhiteSpace(UserNumber)) { var black = db.Find <Black>(x => x.CreateUserNumber == UserNumber); if (black.Count > 0) { var userids = black.Select(x => x.ToUserNumber).ToArray(); query = query.And("CreateUserNumber").NotIn(userids); } } var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.result = true; result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc(new string[] { "Recommend", "Views" }).ExecuteTypedList <Article>(); List <ArticleJson> newlist = ArticleListInfo(list, UserNumber); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Article_Search:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string Article() { ApiResult result = new ApiResult(); try { var UserNumber = ZNRequest.GetString("UserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } var fans = db.Find <Fan>(x => x.CreateUserNumber == UserNumber).ToList(); if (fans.Count == 0) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved); query = query.And("ArticlePower").In(new int[] { Enum_ArticlePower.Public, Enum_ArticlePower.Password }); query.And("CreateUserNumber").In(fans.Select(x => x.ToUserNumber).ToArray()); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc(new string[] { "ID" }).ExecuteTypedList <Article>(); List <ArticleJson> newlist = ArticleListInfo(list, UserNumber); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Fan_Article:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string Apply_1_3() { ApiResult result = new ApiResult(); try { var UserNumber = ZNRequest.GetString("UserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var query = new SubSonic.Query.Select(provider).From <ApplyMoney>().Where <ApplyMoney>(x => x.Status == Enum_Status.Approved); query = query.And("CreateUserNumber").IsEqualTo(UserNumber); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <ApplyMoney>(); List <OrdersJson> newlist = new List <OrdersJson>(); list.ForEach(x => { OrdersJson model = new OrdersJson(); model.ID = x.ID; model.CreateDate = x.CreateDate.ToString("yyyy-MM-dd hh:mm:ss"); model.Price = Tools.SafeInt(System.Configuration.ConfigurationManager.AppSettings["applymoney"]) * 100; newlist.Add(model); }); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Order_Apply_1_3:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string Public() { var query = new SubSonic.Query.Select(provider, "Number", "Title", "CreateDate", "ArticlePowerPwd").From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.ArticlePower != Enum_ArticlePower.Myself && x.Submission != Enum_Submission.Approved); var list = query.ExecuteTypedList <Article>(); var newlist = (from l in list select new { Number = l.Number, Title = l.Title, ArticlePowerPwd = l.ArticlePowerPwd, CreateDate = l.CreateDate.ToString("yyyy-MM-dd hh:mm:ss") }).ToList(); return(Newtonsoft.Json.JsonConvert.SerializeObject(newlist)); }
public string All() { ApiResult result = new ApiResult(); try { var CreateUserNumber = ZNRequest.GetString("CreateUserNumber"); if (string.IsNullOrWhiteSpace(CreateUserNumber)) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } var CurrUserNumber = ZNRequest.GetString("CurrUserNumber"); if (string.IsNullOrWhiteSpace(CurrUserNumber)) { CurrUserNumber = CreateUserNumber; } var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <Keep>().Where <Keep>(x => x.CreateUserNumber == CreateUserNumber); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Keep>(); var articles = new SubSonic.Query.Select(provider, "ID", "Number", "Title", "TypeID", "Cover", "Views", "Goods", "CreateUserNumber", "CreateDate", "ArticlePower", "ArticlePowerPwd", "Recommend", "City", "Province", "Submission").From <Article>().Where("Number").In(list.Select(x => x.ArticleNumber).ToArray()).And("Status").IsNotEqualTo(Enum_Status.Audit).OrderDesc(new string[] { "Recommend", "ID" }).ExecuteTypedList <Article>(); List <ArticleJson> newlist = ArticleListInfo(articles, CurrUserNumber); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Keep_All:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string ToMe_1_4() { ApiResult result = new ApiResult(); try { var UserNumber = ZNRequest.GetString("UserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var query = new SubSonic.Query.Select(provider).From <Red>().Where <Red>(x => x.ToUserNumber == UserNumber); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Red>(); list.ForEach(x => { x.RedTypeText = EnumBase.GetDescription(typeof(Enum_RedType), x.RedType); x.CreateDateText = x.CreateDate.ToString("yyyy-MM-dd hh:mm:ss"); }); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = list }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Red_ToMe_1_3:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string Pic() { ApiResult result = new ApiResult(); try { var Number = ZNRequest.GetString("Number"); var UserNumber = ZNRequest.GetString("UserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <ArticlePart>().Where <ArticlePart>(x => x.Types == Enum_ArticlePart.Pic && x.Status != Enum_Status.Delete && x.Status != Enum_Status.DeleteCompletely); if (Number != UserNumber) { query = query.And("Status").IsEqualTo(Enum_Status.Approved); } query = query.And("CreateUserNumber").IsEqualTo(UserNumber); var recordCount = query.GetRecordCount(); var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <ArticlePart>(); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = list }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_User_Pic:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string DeleteAll() { ApiResult result = new ApiResult(); try { var pager = new Pager(); var UserNumber = ZNRequest.GetString("CreateUserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var query = new SubSonic.Query.Select(provider).From <Article>().Where <Article>(x => x.Status == Enum_Status.Delete && x.CreateUserNumber == UserNumber); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc(new string[] { "UpdateDate" }).ExecuteTypedList <Article>(); List <ArticleJson> newlist = ArticleListInfo(list, UserNumber); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Article_DeleteAll:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
/// <summary> /// 编辑 /// ShareType(0:文章,1:用户,2:新手红包,3:banner) /// </summary> public ActionResult Edit() { try { var UserNumber = ZNRequest.GetString("UserNumber"); var Number = ZNRequest.GetString("Number"); var ShareType = ZNRequest.GetInt("ShareType"); ShareLog model = new ShareLog(); model.CreateDate = DateTime.Now; model.CreateUserNumber = UserNumber; model.CreateIP = Tools.GetClientIP; model.ArticleNumber = ShareType == 0 ? Number : ""; model.UserNumber = ShareType == 1 ? Number : ""; model.Source = ZNRequest.GetString("Source"); var result = false; result = Tools.SafeInt(db.Add <ShareLog>(model)) > 0; if (result) { if (ShareType == 0 && !string.IsNullOrWhiteSpace(Number)) { Article article = new SubSonic.Query.Select(provider, "ID", "Shares", "Number").From <Article>().Where <Article>(x => x.Number == Number).ExecuteSingle <Article>(); if (article != null) { result = new SubSonic.Query.Update <Article>(provider).Set("Shares").EqualTo(article.Shares + 1).Where <Article>(x => x.ID == article.ID).Execute() > 0; } } } return(Json(new { result = true, message = "成功" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { LogHelper.ErrorLoger.Error("ShareLogController_Edit:" + ex.Message); } return(Json(new { result = false, message = "失败" }, JsonRequestBehavior.AllowGet)); }
public string Edit() { ApiResult result = new ApiResult(); try { User user = GetUserInfo(); if (user == null) { result.message = EnumBase.GetDescription(typeof(Enum_ErrorCode), Enum_ErrorCode.UnLogin); result.code = Enum_ErrorCode.UnLogin; return(JsonConvert.SerializeObject(result)); } var articleID = ZNRequest.GetInt("ArticleID"); if (articleID <= 0) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } Article article = new SubSonic.Query.Select(provider, "ID", "CreateUserNumber", "Goods", "Number").From <Article>().Where <Article>(x => x.ID == articleID).ExecuteSingle <Article>(); if (article == null) { result.message = "文章信息异常"; return(JsonConvert.SerializeObject(result)); } //判断是否拉黑 var black = db.Exists <Black>(x => x.CreateUserNumber == article.CreateUserNumber && x.ToUserNumber == user.Number); if (black) { result.code = Enum_ErrorCode.NoPower; result.message = "没有权限"; return(JsonConvert.SerializeObject(result)); } var success = 0; var model = db.Single <ArticleZan>(x => x.CreateUserNumber == user.Number && x.ArticleNumber == article.Number); var goods = model == null ? article.Goods + 1 : article.Goods - 1; //是否新增 var isadd = model == null ? 0 : 1; if (model == null) { model = new ArticleZan(); model.CreateDate = DateTime.Now; model.CreateUserNumber = user.Number; model.CreateIP = Tools.GetClientIP; model.ArticleNumber = article.Number; model.ArticleUserNumber = article.CreateUserNumber; success = Tools.SafeInt(db.Add <ArticleZan>(model)); //操作记录 var now = DateTime.Now.ToString("yyyy-MM-dd"); var action = db.Single <UserAction>(x => x.CreateUserNumber == user.Number && x.CreateTimeText == now && x.ActionType == Enum_ActionType.Like); LogHelper.ErrorLoger.Error(JsonConvert.SerializeObject(action)); if (action == null) { action = new UserAction(); action.CreateUserNumber = user.Number; action.ActionType = Enum_ActionType.Like; action.CreateTime = DateTime.Now; action.CreateTimeText = now; action.ActionInfo = article.Number; db.Add <UserAction>(action); } else { if (!action.ActionInfo.Contains(article.Number)) { action.ActionInfo += "," + article.Number; db.Update <UserAction>(action); } } } else { success = db.Delete <ArticleZan>(model.ID); } if (success > 0) { if (goods < 0) { goods = 0; } new SubSonic.Query.Update <Article>(provider).Set("Goods").EqualTo(goods).Where <Article>(x => x.ID == articleID).Execute(); result.result = true; result.message = isadd + "|" + goods; } } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Zan_ArticleZanEdit" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
/// <summary> /// 列表 /// </summary> public ActionResult All() { try { var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <Order>().Where <Order>(x => x.Status == Enum_Status.Approved); var CreateUserNumber = ZNRequest.GetString("CreateUserNumber"); var ToUserNumber = ZNRequest.GetString("ToUserNumber"); if (!string.IsNullOrWhiteSpace(CreateUserNumber)) { query = query.And("CreateUserNumber").IsEqualTo(CreateUserNumber); } if (!string.IsNullOrWhiteSpace(ToUserNumber)) { query = query.And("ToUserNumber").IsEqualTo(ToUserNumber); } var recordCount = query.GetRecordCount(); if (recordCount == 0) { return(Json(new { currpage = pager.Index, records = recordCount, totalpage = 1, list = string.Empty }, JsonRequestBehavior.AllowGet)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <Order>(); var fromarray = list.Select(x => x.CreateUserNumber).Distinct().ToList(); var toarray = list.Select(x => x.ToUserNumber).Distinct().ToList(); fromarray.AddRange(toarray); var allusers = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number", "Cover").From <User>().And("Number").In(fromarray.ToArray()).ExecuteTypedList <User>(); List <OrderJson> newlist = new List <OrderJson>(); list.ForEach(x => { var fromUser = allusers.FirstOrDefault(y => y.Number == x.CreateUserNumber); var toUser = allusers.FirstOrDefault(y => y.Number == x.ToUserNumber); OrderJson model = new OrderJson(); model.ID = x.ID; model.CreateDate = x.CreateDate.ToString("yyyy-MM-dd"); model.Price = x.Price; if (fromUser != null) { model.FromUserID = fromUser.ID; model.FromUserNumber = fromUser.Number; model.FromUserAvatar = fromUser.Avatar; model.FromUserName = fromUser.NickName; model.FromUserCover = fromUser.Cover; } if (toUser != null) { model.ToUserID = toUser.ID; model.ToUserNumber = toUser.Number; model.ToUserAvatar = toUser.Avatar; model.ToUserName = toUser.NickName; model.ToUserCover = toUser.Cover; } newlist.Add(model); }); var result = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { LogHelper.ErrorLoger.Error("OrderController_All:" + ex.Message); return(Json(null, JsonRequestBehavior.AllowGet)); } }
public string Pic_1_3() { ApiResult result = new ApiResult(); try { var Number = ZNRequest.GetString("Number"); var UserNumber = ZNRequest.GetString("UserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); //日期分组 var datequery = new SubSonic.Query.Select(provider, "ID", "CreateDate", "Status").From <ArticlePart>().Where <ArticlePart>(x => x.Types == Enum_ArticlePart.Pic && x.Status != Enum_Status.Delete && x.Status != Enum_Status.DeleteCompletely && x.CreateUserNumber == UserNumber); if (Number != UserNumber) { datequery = datequery.And("Status").IsEqualTo(Enum_Status.Approved); } var datelist = datequery.ExecuteTypedList <ArticlePart>(); var newdatelist = new List <DateTime>(); datelist.OrderByDescending(x => x.ID).GroupBy(x => x.CreateDate.ToString("yyyy-MM-dd")).ToList().ForEach(x => { newdatelist.Add(x.FirstOrDefault().CreateDate); }); var recordCount = newdatelist.Count(); if (recordCount == 0) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; newdatelist = newdatelist.Skip((pager.Index - 1) * pager.Size).Take(pager.Size).ToList(); //获取数据 var query = new SubSonic.Query.Select(provider).From <ArticlePart>().Where <ArticlePart>(x => x.Types == Enum_ArticlePart.Pic && x.Status != Enum_Status.Delete && x.Status != Enum_Status.DeleteCompletely && x.CreateUserNumber == UserNumber); if (Number != UserNumber) { query = query.And("Status").IsEqualTo(Enum_Status.Approved); } query.And("CreateDate").IsGreaterThanOrEqualTo(newdatelist[newdatelist.Count - 1].ToString("yyyy-MM-dd 00:00:00")); query.And("CreateDate").IsLessThanOrEqualTo(newdatelist[0].ToString("yyyy-MM-dd 23:59:59")); var list = query.ExecuteTypedList <ArticlePart>(); var newlist = new List <PicJson>(); //组织输出 string[] Month = new string[] { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" }; string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; Console.WriteLine(); newdatelist.ForEach(x => { PicJson pic = new PicJson(); pic.Month = Month[x.Month - 1]; pic.Day = x.Day; pic.Week = Day[Convert.ToInt16(x.DayOfWeek)]; pic.CreateDate = x.ToString("yyyy年MM月dd日"); pic.List = list.FindAll(y => y.CreateDate.Year == x.Year && y.CreateDate.Month == x.Month && y.CreateDate.Day == x.Day); newlist.Add(pic); }); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_User_Pic_1_3:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string Edit() { ApiResult result = new ApiResult(); try { User user = GetUserInfo(); if (user == null) { result.message = EnumBase.GetDescription(typeof(Enum_ErrorCode), Enum_ErrorCode.UnLogin); result.code = Enum_ErrorCode.UnLogin; return(JsonConvert.SerializeObject(result)); } var ArticleNumber = ZNRequest.GetString("ArticleNumber"); if (string.IsNullOrWhiteSpace(ArticleNumber)) { result.message = "文章信息异常"; return(JsonConvert.SerializeObject(result)); } var summary = SqlFilter(ZNRequest.GetString("Summary"), false, false); if (string.IsNullOrWhiteSpace(summary)) { result.message = "请填写评论内容"; return(JsonConvert.SerializeObject(result)); } summary = CutString(summary, 2000); var dirtyword = AppHelper.HasDirtyWord(summary); if (!string.IsNullOrWhiteSpace(dirtyword)) { result.message = "您的输入内容含有敏感内容[" + dirtyword + "],请检查后重试哦"; return(JsonConvert.SerializeObject(result)); } Article article = new SubSonic.Query.Select(provider, "ID", "Number", "CreateUserNumber").From <Article>().Where <Article>(x => x.Number == ArticleNumber).ExecuteSingle <Article>(); if (article == null) { result.message = "文章信息异常"; return(JsonConvert.SerializeObject(result)); } //判断是否拉黑 var black = db.Exists <Black>(x => x.CreateUserNumber == article.CreateUserNumber && x.ToUserNumber == user.Number); if (black) { result.code = Enum_ErrorCode.NoPower; result.message = "没有权限"; return(JsonConvert.SerializeObject(result)); } Comment model = new Comment(); model.ArticleNumber = article.Number; model.ArticleUserNumber = article.CreateUserNumber; model.Summary = summary; model.Number = BuildNumber(); model.CreateDate = DateTime.Now; model.CreateUserNumber = user.Number; model.CreateIP = Tools.GetClientIP; model.ParentCommentNumber = ZNRequest.GetString("ParentCommentNumber"); model.ParentUserNumber = ZNRequest.GetString("ParentUserNumber"); model.Province = ZNRequest.GetString("Province"); model.City = ZNRequest.GetString("City"); model.District = ZNRequest.GetString("District"); model.Street = ZNRequest.GetString("Street"); model.DetailName = ZNRequest.GetString("DetailName"); model.CityCode = ZNRequest.GetString("CityCode"); model.Latitude = Tools.SafeDouble(ZNRequest.GetString("Latitude")); model.Longitude = Tools.SafeDouble(ZNRequest.GetString("Longitude")); model.ShowPosition = ZNRequest.GetInt("ShowPosition"); model.ID = Tools.SafeInt(db.Add <Comment>(model)); if (model.ID > 0) { result.result = true; result.message = model.ID; //推送 new AppHelper().Push(article.CreateUserNumber, article.ID, article.Number, user.NickName, Enum_PushType.Comment, false); } } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Comment_Edit:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string SubComment() { ApiResult result = new ApiResult(); try { var pager = new Pager(); var Number = ZNRequest.GetString("Number"); if (string.IsNullOrWhiteSpace(Number)) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } var UserNumber = ZNRequest.GetString("UserNumber"); var query = new SubSonic.Query.Select(provider).From <Comment>().Where <Comment>(x => x.ParentCommentNumber == Number); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.result = true; result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderAsc("ID").ExecuteTypedList <Comment>(); var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number").From <User>().Where("Number").In(list.Select(x => x.CreateUserNumber).Distinct().ToArray()).ExecuteTypedList <User>(); var parentComments = new SubSonic.Query.Select(provider, "ID", "ParentCommentNumber", "Number", "CreateUserNumber").From <Comment>().Where("ParentCommentNumber").In(list.Select(x => x.Number).ToArray()).ExecuteTypedList <Comment>(); var zans = db.Find <CommentZan>(x => x.CreateUserNumber == UserNumber).ToList(); List <CommentJson> newlist = new List <CommentJson>(); list.ForEach(x => { CommentJson model = new CommentJson(); var user = users.FirstOrDefault(y => y.Number == x.CreateUserNumber); if (user == null) { return; } model.ID = x.ID; model.Summary = x.Summary; model.Goods = x.Goods; model.Number = x.Number; model.CreateDateText = x.CreateDate.ToString("yyyy-MM-dd"); model.ShowPosition = x.ShowPosition; model.City = x.City; if (string.IsNullOrWhiteSpace(model.City)) { model.ShowPosition = 0; } model.UserID = user.ID; model.UserNumber = user.Number; model.NickName = user.NickName; model.Avatar = user.Avatar; model.SubCommentCount = parentComments.Count(y => y.ParentCommentNumber == x.Number); if (model.SubCommentCount == 1) { var subuser = db.Single <User>(y => y.Number == parentComments[0].CreateUserNumber); var comment = db.Single <Comment>(y => y.Number == parentComments[0].Number); if (subuser == null && comment == null) { model.SubCommentCount = 0; } if (subuser != null) { model.SubUserName = subuser.NickName; } if (comment != null) { model.SubSummary = comment.Summary; } } model.ArticleNumber = x.ArticleNumber; model.IsZan = zans.Count(y => y.CommentNumber == x.Number); newlist.Add(model); }); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Comment_SubComment:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string List() { ApiResult result = new ApiResult(); try { var ActionID = ZNRequest.GetInt("ActionID"); var UserNumber = ZNRequest.GetString("UserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } //我的关注 var follows = db.Find <Fan>(x => x.CreateUserNumber == UserNumber).ToList(); if (follows.Count == 0) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <UserAction>().Where("CreateUserNumber").In(follows.Select(x => x.ToUserNumber).ToArray()); //if (ActionID > 0) //{ // query = query.And("ID").IsLessThan(ActionID); //} var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <UserAction>(); var like = Enum_ActionType.Like; var follow = Enum_ActionType.Follow; var keep = Enum_ActionType.Keep; var userList = new List <string>(); list.ForEach(x => { userList.Add(x.CreateUserNumber); }); var newlist = new List <UserActionJson>(); if (list.Count > 0) { var allUser = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Number").From <User>().Where <User>(y => y.Status == Enum_Status.Approved).And("Number").In(userList.Distinct().ToArray()).ExecuteTypedList <User>(); list.ForEach(x => { var userModel = allUser.FirstOrDefault(y => y.Number == x.CreateUserNumber); if (userModel != null) { UserActionJson action = new UserActionJson(); action.ID = x.ID; action.Number = x.CreateUserNumber; action.NickName = userModel.NickName; action.Avatar = userModel.Avatar; action.Cover = userModel.Cover; action.CreateTime = FormatTime(x.CreateTime); action.ActionType = x.ActionType; action.ArticleInfoJson = new List <ArticleInfoJson>(); action.UserInfoJson = new List <UserInfoJson>(); //喜欢、收藏 if (x.ActionType == like || x.ActionType == keep) { var articles = new SubSonic.Query.Select(provider, "ID", "Number", "Cover", "ArticlePower", "CreateUserNumber", "Status", "Title").From <Article>().Where("Number").In(x.ActionInfo.Split(',')).And("Status").IsEqualTo(Enum_Status.Approved).And("ArticlePower").IsEqualTo(Enum_ArticlePower.Public).And("Submission").IsGreaterThan(Enum_Submission.Audit).ExecuteTypedList <Article>(); if (articles.Count > 0) { articles.ForEach(y => { ArticleInfoJson article = new ArticleInfoJson(); article.ID = y.ID; article.Title = y.Title; article.Number = y.Number; article.Cover = y.Cover; article.ArticlePower = y.ArticlePower; action.ArticleInfoJson.Add(article); }); action.ArticleInfoJson.Reverse(); newlist.Add(action); } } //关注 if (x.ActionType == follow) { var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Number").From <User>().Where <User>(y => y.Status == Enum_Status.Approved).And("Number").In(x.ActionInfo.Split(',')).ExecuteTypedList <User>(); if (users.Count > 0) { users.ForEach(y => { UserInfoJson user = new UserInfoJson(); user.ID = y.ID; user.NickName = y.NickName; user.Number = y.Number; user.Avatar = y.Avatar; user.Cover = y.Cover; action.UserInfoJson.Add(user); }); action.ArticleInfoJson.Reverse(); newlist.Add(action); } } } }); } result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api/UserAction/List:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string ToUser() { ApiResult result = new ApiResult(); try { var UserNumber = ZNRequest.GetString("UserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <ArticleZan>().Where <ArticleZan>(x => x.CreateUserNumber == UserNumber); var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("ID").ExecuteTypedList <ArticleZan>(); var articles = new SubSonic.Query.Select(provider, "ID", "Number", "Cover", "ArticlePower", "CreateUserNumber", "Status", "Title").From <Article>().Where("Number").In(list.Select(x => x.ArticleNumber).ToArray()).ExecuteTypedList <Article>(); var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Number", "Cover").From <User>().Where("Number").In(list.Select(x => x.ArticleUserNumber).ToArray()).ExecuteTypedList <User>(); List <ZanJson> newlist = new List <ZanJson>(); list.ForEach(x => { var article = articles.FirstOrDefault(y => y.Number == x.ArticleNumber); var user = users.FirstOrDefault(y => y.Number == x.ArticleUserNumber); if (article != null && user != null) { ZanJson model = new ZanJson(); model.ID = x.ID; model.CreateDate = x.CreateDate.ToString("yyyy-MM-dd"); model.ArticleID = article.ID; model.Title = article.Title; model.Number = article.Number; model.Cover = article.Cover; model.ArticlePower = article.ArticlePower; model.CreateUserNumber = article.CreateUserNumber; model.NickName = user.NickName; model.Avatar = user.Avatar; model.UserNumber = user.Number; model.UserCover = user.Cover; newlist.Add(model); } }); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Zan_ToUser:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string Article_1_3() { ApiResult result = new ApiResult(); try { var UserNumber = ZNRequest.GetString("UserNumber"); var CurrUserNumber = ZNRequest.GetString("CurrUserNumber"); if (string.IsNullOrWhiteSpace(UserNumber)) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var pager = new Pager(); //日期分组 var datequery = new SubSonic.Query.Select(provider, "ID", "CreateDate", "ArticlePower").From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.CreateUserNumber == UserNumber); if (UserNumber != CurrUserNumber) { datequery = datequery.And("ArticlePower").IsEqualTo(Enum_ArticlePower.Public); datequery = datequery.And("Submission").IsGreaterThan(Enum_Submission.Audit); } var datelist = datequery.ExecuteTypedList <Article>(); var newdatelist = new List <DateTime>(); datelist.OrderByDescending(x => x.ID).GroupBy(x => x.CreateDate.ToString("yyyy-MM")).ToList().ForEach(x => { newdatelist.Add(x.FirstOrDefault().CreateDate); }); var recordCount = newdatelist.Count(); if (recordCount == 0) { result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; newdatelist = newdatelist.Skip((pager.Index - 1) * pager.Size).Take(pager.Size).ToList(); //获取数据 var query = new SubSonic.Query.Select(provider, "ID", "Number", "CreateUserNumber", "Cover", "ArticlePower", "Status", "CreateDate").From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved && x.CreateUserNumber == UserNumber); if (UserNumber != CurrUserNumber) { query = query.And("ArticlePower").IsEqualTo(Enum_ArticlePower.Public); query = query.And("Submission").IsGreaterThan(Enum_Submission.Audit); } recordCount = query.GetRecordCount(); query.And("CreateDate").IsGreaterThanOrEqualTo(newdatelist[newdatelist.Count - 1].ToString("yyyy-MM-01 00:00:00")); var day = DateTime.DaysInMonth(newdatelist[0].Year, newdatelist[0].Month);; query.And("CreateDate").IsLessThanOrEqualTo(newdatelist[0].ToString("yyyy-MM-" + day + " 23:59:59")); var list = query.ExecuteTypedList <Article>(); var newlist = new List <UserArticleJson>(); //组织输出 newdatelist.ForEach(x => { UserArticleJson model = new UserArticleJson(); model.List = new List <UserArticleSubJson>(); var items = list.FindAll(y => y.CreateDate.Year == x.Year && y.CreateDate.Month == x.Month); items.ForEach(y => { UserArticleSubJson item = new UserArticleSubJson(); item.ID = y.ID; item.Number = y.Number; item.CreateUserNumber = y.CreateUserNumber; item.Cover = y.Cover; item.ArticlePower = y.ArticlePower; model.List.Add(item); }); model.CreateDate = x.Year + "年" + x.Month + "月"; model.Count = model.List.Count; newlist.Add(model); }); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_User_Article_1_3:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string All() { ApiResult result = new ApiResult(); try { var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <Article>().Where <Article>(x => x.Status == Enum_Status.Approved); //昵称 var title = SqlFilter(ZNRequest.GetString("Title")); if (!string.IsNullOrWhiteSpace(title)) { query.And("Title").Like("%" + title + "%"); } var CreateUserNumber = ZNRequest.GetString("CreateUserNumber"); if (!string.IsNullOrWhiteSpace(CreateUserNumber)) { query = query.And("CreateUserNumber").IsEqualTo(CreateUserNumber); } //其他用户的文章 var CurrUserNumber = ZNRequest.GetString("CurrUserNumber"); if (CreateUserNumber != CurrUserNumber || string.IsNullOrWhiteSpace(CreateUserNumber)) { query = query.And("ArticlePower").IsEqualTo(Enum_ArticlePower.Public); query = query.And("Submission").IsGreaterThan(Enum_Submission.Audit); } //文章类型 var TypeID = ZNRequest.GetInt("TypeID"); if (TypeID > 0) { query = query.And("TypeIDList").Like("%-0-" + TypeID.ToString() + "-%"); } //过滤黑名单 if (!string.IsNullOrWhiteSpace(CurrUserNumber)) { var black = db.Find <Black>(x => x.CreateUserNumber == CurrUserNumber); if (black.Count > 0) { var userids = black.Select(x => x.ToUserNumber).ToArray(); query = query.And("CreateUserNumber").NotIn(userids); } } var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.message = new { records = recordCount, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var sort = new string[] { "Recommend", "ID" }; if (CreateUserNumber == CurrUserNumber) { sort = new string[] { "ID" }; } var Source = ZNRequest.GetString("Source"); if (!string.IsNullOrWhiteSpace(Source)) { sort = new string[] { "Views" }; } var list = query.Paged(pager.Index, pager.Size).OrderDesc(sort).ExecuteTypedList <Article>(); List <ArticleJson> newlist = ArticleListInfo(list, CurrUserNumber); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Article_All:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string CommentZanEdit() { ApiResult result = new ApiResult(); try { User user = GetUserInfo(); if (user == null) { result.message = EnumBase.GetDescription(typeof(Enum_ErrorCode), Enum_ErrorCode.UnLogin); result.code = Enum_ErrorCode.UnLogin; return(JsonConvert.SerializeObject(result)); } var number = ZNRequest.GetString("CommentNumber"); if (string.IsNullOrWhiteSpace(number)) { result.message = "评论信息异常"; return(JsonConvert.SerializeObject(result)); } Comment comment = new SubSonic.Query.Select(provider, "ID", "CreateUserNumber", "Goods", "Number").From <Comment>().Where <Comment>(x => x.Number == number).ExecuteSingle <Comment>(); if (comment == null) { result.message = "评论信息异常"; return(JsonConvert.SerializeObject(result)); } //判断是否拉黑 var black = db.Exists <Black>(x => x.CreateUserNumber == comment.CreateUserNumber && x.ToUserNumber == user.Number); if (black) { result.code = Enum_ErrorCode.NoPower; result.message = "没有权限"; return(JsonConvert.SerializeObject(result)); } var success = 0; var model = db.Single <CommentZan>(x => x.CreateUserNumber == user.Number && x.CommentNumber == number); var goods = model == null ? comment.Goods + 1 : comment.Goods - 1; //是否新增 var isadd = model == null ? 0 : 1; if (model == null) { model = new CommentZan(); model.CreateDate = DateTime.Now; model.CreateUserNumber = user.Number; model.CreateIP = Tools.GetClientIP; model.CommentNumber = number; success = Tools.SafeInt(db.Add <CommentZan>(model)); } else { success = db.Delete <CommentZan>(model.ID); } if (success > 0) { if (goods < 0) { goods = 0; } new SubSonic.Query.Update <Comment>(provider).Set("Goods").EqualTo(goods).Where <Comment>(x => x.ID == comment.ID).Execute(); result.result = true; result.message = isadd + "|" + goods; } } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Zan_CommentZanEdit" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
public string Edit() { ApiResult result = new ApiResult(); try { User user = GetUserInfo(); if (user == null) { result.message = EnumBase.GetDescription(typeof(Enum_ErrorCode), Enum_ErrorCode.UnLogin); result.code = Enum_ErrorCode.UnLogin; return(JsonConvert.SerializeObject(result)); } var articleID = ZNRequest.GetInt("ArticleID"); if (articleID <= 0) { result.message = "参数异常"; return(JsonConvert.SerializeObject(result)); } Article article = new SubSonic.Query.Select(provider, "ID", "CreateUserNumber", "Number").From <Article>().Where <Article>(x => x.ID == articleID).ExecuteSingle <Article>(); if (article == null) { result.message = "文章信息异常"; return(JsonConvert.SerializeObject(result)); } Keep model = db.Single <Keep>(x => x.CreateUserNumber == user.Number && x.ArticleNumber == article.Number); if (model == null) { model = new Keep(); model.CreateDate = DateTime.Now; model.CreateUserNumber = user.Number; model.CreateIP = Tools.GetClientIP; } else { result.result = true; result.message = ""; return(JsonConvert.SerializeObject(result)); } model.ArticleNumber = article.Number; model.ArticleUserNumber = article.CreateUserNumber; var success = Tools.SafeInt(db.Add <Keep>(model)) > 0; if (success) { result.result = true; result.message = user.Follows; //操作记录 var now = DateTime.Now.ToString("yyyy-MM-dd"); var action = db.Single <UserAction>(x => x.CreateUserNumber == user.Number && x.CreateTimeText == now && x.ActionType == Enum_ActionType.Keep); if (action == null) { action = new UserAction(); action.CreateUserNumber = user.Number; action.ActionType = Enum_ActionType.Keep; action.CreateTime = DateTime.Now; action.CreateTimeText = now; action.ActionInfo = article.Number; db.Add <UserAction>(action); } else { if (!action.ActionInfo.Contains(article.Number)) { action.ActionInfo += "," + article.Number; db.Update <UserAction>(action); } } } } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api_Keep_Edit:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }
protected List <ArticleJson> ArticleListInfo(List <Article> list, string usernumber = "") { //文章编号集合 var array = list.Select(x => x.Number).ToArray(); var articletypes = AppHelper.GetArticleType(); var parts = new SubSonic.Query.Select(provider).From <ArticlePart>().Where <ArticlePart>(x => x.Types == Enum_ArticlePart.Pic).And("ArticleNumber").In(array).OrderAsc("SortID").ExecuteTypedList <ArticlePart>(); List <string> userids = new List <string>(); list.ForEach(x => { userids.Add(x.CreateUserNumber); }); var users = new SubSonic.Query.Select(provider, "ID", "NickName", "Avatar", "Cover", "Signature", "Number", "IsPay").From <User>().Where("Number").In(userids.ToArray()).ExecuteTypedList <User>(); //判断是否关注、判断是否点赞、判断是否收藏 var fans = new List <Fan>(); var zans = new List <ArticleZan>(); var keeps = new List <Keep>(); if (!string.IsNullOrWhiteSpace(usernumber)) { fans = db.Find <Fan>(x => x.CreateUserNumber == usernumber).ToList(); zans = db.Find <ArticleZan>(x => x.CreateUserNumber == usernumber).ToList(); keeps = db.Find <Keep>(x => x.CreateUserNumber == usernumber).ToList(); } var tags = GetTag(); List <ArticleJson> newlist = new List <ArticleJson>(); list.ForEach(x => { var user = users.FirstOrDefault(y => y.Number == x.CreateUserNumber); if (user != null) { ArticleJson model = new ArticleJson(); var articletype = articletypes.FirstOrDefault(y => y.ID == x.TypeID); model.UserID = user.ID; model.NickName = user.NickName; model.Avatar = user.Avatar; model.Signature = user.Signature; model.UserCover = user.Cover; model.IsPay = user.IsPay; model.ArticleID = x.ID; model.ArticleNumber = x.Number; model.Title = x.Title; model.Views = x.Views; model.Goods = x.Goods; //标签 model.TagList = new List <Tag>(); if (!string.IsNullOrWhiteSpace(x.Tag)) { var tag = x.Tag.Split(',').ToList(); tag.ForEach(y => { var id = Tools.SafeInt(y); var item = tags.FirstOrDefault(z => z.ID == id); if (item != null) { model.TagList.Add(item); } }); } model.IsFollow = fans.Count(y => y.ToUserNumber == x.CreateUserNumber); model.IsZan = zans.Count(y => y.ArticleNumber == x.Number); model.IsKeep = keeps.Count(y => y.ArticleNumber == x.Number); model.UserNumber = x.CreateUserNumber; model.Cover = x.Cover; model.CreateDate = x.CreateDate.ToString("yyyy-MM-dd hh:mm"); model.TypeName = articletype == null ? "" : articletype.Name; model.ArticlePart = parts.Where(y => y.ArticleNumber == x.Number).OrderBy(y => y.ID).Take(4).ToList(); model.ArticlePower = x.ArticlePower; model.Recommend = x.Recommend; model.Province = x.Province; model.City = x.City; model.Submission = x.Submission; newlist.Add(model); } }); return(newlist); }
public string Search() { ApiResult result = new ApiResult(); try { var UserNumber = ZNRequest.GetString("UserNumber"); var nickname = ZNRequest.GetString("NickName"); var pager = new Pager(); var query = new SubSonic.Query.Select(provider).From <User>().Where <User>(x => x.Status == Enum_Status.Approved); if (!string.IsNullOrWhiteSpace(nickname)) { query.And("NickName").IsNotNull().And("NickName").Like("%" + nickname + "%"); } if (!string.IsNullOrWhiteSpace(UserNumber)) { var black = db.Find <Black>(x => x.CreateUserNumber == UserNumber); if (black.Count > 0) { var userids = black.Select(x => x.ToUserNumber).ToArray(); query = query.And("Number").NotIn(userids); } } var recordCount = query.GetRecordCount(); if (recordCount == 0) { result.result = true; result.message = new { records = 0, totalpage = 1 }; return(JsonConvert.SerializeObject(result)); } var totalPage = recordCount % pager.Size == 0 ? recordCount / pager.Size : recordCount / pager.Size + 1; var list = query.Paged(pager.Index, pager.Size).OrderDesc("LoginTimes").ExecuteTypedList <User>(); var follows = db.Find <Fan>(x => x.CreateUserNumber == UserNumber).ToList(); var newlist = (from l in list select new { ID = l.ID, NickName = l.NickName, Signature = l.Signature, Avatar = l.Avatar, Cover = l.Cover, Number = l.Number, IsFollow = follows.Exists(x => x.ToUserNumber == l.Number) ? 1 : 0 }).ToList(); result.result = true; result.message = new { currpage = pager.Index, records = recordCount, totalpage = totalPage, list = newlist }; } catch (Exception ex) { LogHelper.ErrorLoger.Error("Api/User/Search:" + ex.Message); result.message = ex.Message; } return(JsonConvert.SerializeObject(result)); }