/// <summary> /// 获取信息列表 /// </summary> /// <param name="page">当前页</param> /// <param name="row">每页显示数</param> /// <param name="searchKey">查询条件</param> /// <returns></returns> public static List <ht_news> GetNewsList(int page, int rows, ht_news searchKey) { using (Entities db = new Entities()) { return(GetNewsData(db, searchKey, true).Skip((page - 1) * rows).Take(rows).ToList()); } }
/// <summary> /// 获取信息总数 /// </summary> /// <param name="searchKey">查询条件</param> /// <returns></returns> public static int GetNewsCount(ht_news searchKey) { using (Entities db = new Entities()) { return(GetNewsData(db, searchKey).Count()); } }
public ActionResult Edit(ht_news model) { if (BLLNews.Edit(model)) { return(JsonResult(APIErrCode.Success, "编辑成功")); } else { return(JsonResult(APIErrCode.OperateFail, "编辑失败")); } }
public void ProcessRequest(HttpContext context) { string id = context.Request["id"]; ht_news model = HT.BLL.Admin.BLLProject.GetNew(int.Parse(id)); apiResp.msg = "查询完成"; apiResp.status = true; apiResp.result = model; context.Response.Write(HT.Utility.JSONHelper.ObjectToJson(apiResp)); }
/// <summary> /// 信息列表 /// </summary> /// <param name="searchKey"></param> /// <param name="page"></param> /// <param name="rows"></param> /// <returns></returns> public ActionResult BaseNewsList(ht_news searchKey, int page = 1, int rows = 5, bool recommend = false) { Model.Model.PageResult <ht_news> pageModel = BLLNews.GetNewsListPageResult(page, rows, searchKey, recommend); if (Request.IsAjaxRequest()) { apiResp.status = true; apiResp.result = pageModel; return(Json(apiResp)); } return(View(pageModel)); }
public ActionResult PostGoodsSubmit(ht_news model) { string msg = ""; string orderNo = ""; model.add_userid = BLLUser.GetLoginUserInfo().id; if (BLLNews.Add(model, out msg, out orderNo)) { return(JsonResult(APIErrCode.Success, "OK", new { order_no = orderNo })); } else { return(JsonResult(APIErrCode.OperateFail, msg)); } }
public ActionResult PostSubmit(ht_news model) { string msg = ""; string orderNo = ""; var authenticationUser = BLLAuthentication.GetAuthenticationUser(); model.add_userid = authenticationUser.id; model.add_nickname = authenticationUser.nickname; model.add_avatar = authenticationUser.avatar; if (BLLNews.Add(model, out msg, out orderNo)) { return(JsonResult(APIErrCode.Success, "OK", new { order_no = orderNo })); } else { return(JsonResult(APIErrCode.OperateFail, msg)); } }
/// <summary> /// 信息列表 /// </summary> /// <param name="searchKey"></param> /// <param name="page"></param> /// <param name="rows"></param> /// <returns></returns> public ActionResult BaseNewsList(ht_news searchKey, int page = 1, int rows = 5) { var curUserid = BLLAuthentication.GetAuthenticationUser().id; if (searchKey.isme.HasValue && searchKey.isme.Value) { searchKey.add_userid = curUserid; //我的发布 } Model.Model.PageResult <ht_news> pageModel = BLLNews.GetNewsListPageResult(page, rows, searchKey, curUserid); if (Request.IsAjaxRequest()) { apiResp.status = true; apiResp.result = pageModel; return(Json(apiResp)); } return(View(pageModel)); }
/// <summary> /// 发布项目 /// </summary> /// <param name="model">模型</param> /// <param name="msg">提示消息</param> /// <param name="orderNo">订单号,成功时返回</param> /// <returns>成功 失败</returns> public static bool Add(ht_news model, out string msg, out string orderNo) { msg = ""; orderNo = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(111111, 999999); using (Entities db = new Entities()) { try { model.add_time = DateTime.Now; model.order_no = orderNo; db.ht_news.Add(model); if (db.SaveChanges() > 0) { return(true); } } catch (Exception ex) { msg = ex.Message; } return(false); } }
/// <summary> /// 编辑 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool Edit(ht_news model) { using (Entities db = new Entities()) { var detailSource = new ht_news(); var detail = db.ht_news.Single(p => p.id == model.id); detailSource = detail; detail.add_time = detailSource.add_time; //detail.update_time = DateTime.Now; //model.id: 178 //model.cateid: 1 //model.cate: 有货找车 // model.title: //model.description: detail.contact_name = model.contact_name; detail.contact_phone = model.contact_phone; detail.validity_num = model.validity_num; detail.validity_unit = model.validity_unit; detail.start_province = model.start_province; detail.start_city = model.start_city; detail.start_district = model.start_district; detail.start_address = model.start_address; detail.stop_province = model.stop_province; detail.stop_city = model.stop_city; detail.stop_district = model.stop_district; detail.stop_address = model.stop_address; detail.tags = model.tags; detail.use_type = model.use_type; detail.use_img = model.use_img; detail.car_length = model.car_length; detail.car_style = model.car_style; detail.goods_type = model.goods_type; detail.goods_weight = model.goods_weight; detail.goods_weight_unit = model.goods_weight_unit; detail.freight = model.freight; detail.use_time = model.use_time; detail.use_mode = model.use_mode; detail.other_remark = model.other_remark; detail.set_top = model.set_top; detail.set_top_money = model.set_top_money; detail.reward_money = model.reward_money; detail.recruit_num = model.recruit_num; detail.imgs = model.imgs; detail.total = model.total; detail.update_time = DateTime.Now; // detail.pay_method = model. //detail.add_userid = model. //detail.add_nickname = model. //detail.add_avatar = model. //detail.add_time = model. //detail.update_userid = model. //detail.update_nickname = model. //detail.audit_userid = model. //detail.audit_nickname = model. //detail.audit_time = model. //detail.status: 0 //detail.pay: //detail.pay_status: 0 //detail.pay_time: //detail.pay_trade_no: //detail.order_no: B20180610175715607351974764 //detail.view_num: 0 //detail.praise_num: 0 //detail.share_num: 0 //detail.is_delete: 0 //detail.is_praise: false //detail.expire: //detail.recommend: //detail.isme: return(db.SaveChanges() > 0); } }
/// <summary> /// 发布项目 /// </summary> /// <param name="model">模型</param> /// <param name="msg">提示消息</param> /// <param name="orderNo">订单号,成功时返回</param> /// <returns>成功 失败</returns> public static bool Add(ht_news model, out string msg, out string orderNo) { msg = ""; orderNo = "B" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + new Random().Next(111111, 999999); using (Entities db = new Entities()) { try { model.add_time = DateTime.Now; model.update_time = model.add_time; model.order_no = orderNo; model.status = 0; if (!model.set_top.HasValue) { model.set_top = 0; } model.pay_status = 0; model.is_delete = 0; db.ht_news.Add(model); if (db.SaveChanges() > 0) { if (model.cateid != 1) { return(true); } //线程插入线路关系 new Thread(p => { using (Entities dbt = new Entities()) { Expression <Func <ht_news_subscribe, bool> > rcountWhere = s => (s.start_province + s.start_city + s.start_district) .StartsWith(model.start_province + model.start_city + model.start_district) && (s.stop_province + s.stop_city + s.stop_district) .StartsWith(model.stop_province + model.stop_city + model.stop_district); List <ht_news_subscribe_relation> relList = dbt.ht_news_subscribe .Where(rcountWhere.Compile()) .Select(x => new ht_news_subscribe_relation { news_id = model.id, subscribe_id = x.id, is_look = 0 }).ToList(); dbt.ht_news_subscribe_relation.AddRange(relList); dbt.SaveChanges(); dbt.ht_news_subscribe .Where(rcountWhere.Compile()).AsQueryable() .Update(x => new ht_news_subscribe { ncount = x.ncount + 1, rcount = x.rcount + 1 }); } }).Start(); return(true); } } catch (Exception ex) { msg = ex.Message; } return(false); } }
private static IQueryable <ht_news> GetLikeNewsData(Entities db, int id, int min) { db.Configuration.ProxyCreationEnabled = false; var data = db.ht_news.Where(p => true); ht_news searchKey = db.ht_news.FirstOrDefault(p => p.id == id); if (searchKey == null) { return(data); } //排除id if (searchKey.id != 0) { data = data.Where(p => p.id != searchKey.id); } //分类一致 if (searchKey.cateid != 0) { data = data.Where(p => p.cateid == searchKey.cateid); } if (!string.IsNullOrWhiteSpace(searchKey.use_type)) { if (data.Where(p => p.use_type == searchKey.use_type).Count() < min) { return(data); } data = data.Where(p => p.use_type == searchKey.use_type); } if (!string.IsNullOrWhiteSpace(searchKey.car_style)) { if (data.Where(p => p.car_style == searchKey.car_style).Count() < min) { return(data); } data = data.Where(p => p.car_style == searchKey.car_style); } if (!string.IsNullOrWhiteSpace(searchKey.car_length)) { if (data.Where(p => p.car_length == searchKey.car_length).Count() < min) { return(data); } data = data.Where(p => p.car_length == searchKey.car_length); } if (!string.IsNullOrWhiteSpace(searchKey.goods_type)) { if (data.Where(p => p.goods_type == searchKey.goods_type).Count() < min) { return(data); } data = data.Where(p => p.goods_type == searchKey.goods_type); } if (!string.IsNullOrWhiteSpace(searchKey.start_province)) { if (data.Where(p => p.start_province == searchKey.start_province).Count() < min) { return(data); } data = data.Where(p => p.start_province == searchKey.start_province); } if (!string.IsNullOrWhiteSpace(searchKey.start_city)) { if (data.Where(p => p.start_city == searchKey.start_city).Count() < min) { return(data); } data = data.Where(p => p.start_city == searchKey.start_city); } if (!string.IsNullOrWhiteSpace(searchKey.start_district)) { if (data.Where(p => p.start_district == searchKey.start_district).Count() < min) { return(data); } data = data.Where(p => p.start_district == searchKey.start_district); } if (!string.IsNullOrWhiteSpace(searchKey.stop_province)) { if (data.Where(p => p.stop_province == searchKey.stop_province).Count() < min) { return(data); } data = data.Where(p => p.stop_province == searchKey.stop_province); } if (!string.IsNullOrWhiteSpace(searchKey.stop_city)) { if (data.Where(p => p.stop_city == searchKey.stop_city).Count() < min) { return(data); } data = data.Where(p => p.stop_city == searchKey.stop_city); } if (!string.IsNullOrWhiteSpace(searchKey.stop_district)) { if (data.Where(p => p.stop_district == searchKey.stop_district).Count() < min) { return(data); } data = data.Where(p => p.stop_district == searchKey.stop_district); } return(data); }
/// <summary> /// 构造查询IQueryable /// </summary> /// <param name="db">查询条件</param> /// <param name="searchKey">查询条件</param> /// <param name="searchKey">查询条件</param> /// <param name="searchKey">查询条件</param> /// <returns></returns> private static IQueryable <ht_news> GetNewsData(Entities db, ht_news searchKey, bool isOrder = false) { db.Configuration.ProxyCreationEnabled = false; var data = db.ht_news.Where(p => true); data = data.Where(p => p.is_delete == 0); if (searchKey.cateid != 0) { data = data.Where(p => p.cateid == searchKey.cateid); } if (!string.IsNullOrWhiteSpace(searchKey.start_province)) { data = data.Where(p => p.start_province == searchKey.start_province); } if (!string.IsNullOrWhiteSpace(searchKey.start_city)) { data = data.Where(p => p.start_city == searchKey.start_city); } if (!string.IsNullOrWhiteSpace(searchKey.start_district)) { data = data.Where(p => p.start_district == searchKey.start_district); } if (!string.IsNullOrWhiteSpace(searchKey.stop_province)) { data = data.Where(p => p.stop_province == searchKey.stop_province); } if (!string.IsNullOrWhiteSpace(searchKey.stop_city)) { data = data.Where(p => p.stop_city == searchKey.stop_city); } if (!string.IsNullOrWhiteSpace(searchKey.stop_district)) { data = data.Where(p => p.stop_district == searchKey.stop_district); } if (!string.IsNullOrWhiteSpace(searchKey.use_type)) { data = data.Where(p => p.use_type == searchKey.use_type); } if (!string.IsNullOrWhiteSpace(searchKey.car_length)) { data = data.Where(p => p.car_length == searchKey.car_length); } if (!string.IsNullOrWhiteSpace(searchKey.car_style)) { data = data.Where(p => p.car_style == searchKey.car_style); } if (!string.IsNullOrWhiteSpace(searchKey.goods_type)) { data = data.Where(p => p.goods_type == searchKey.goods_type); } if (searchKey.expire.HasValue && searchKey.expire == 1) { data = data.Where(p => (p.validity_unit == "月" && DbFunctions.AddMonths(p.add_time, p.validity_num.Value) < DateTime.Now) || (p.validity_unit == "天" && DbFunctions.AddDays(p.add_time, p.validity_num.Value) < DateTime.Now)); } else if (searchKey.expire.HasValue && searchKey.expire == 0) { data = data.Where(p => (p.validity_unit == "月" && DbFunctions.AddMonths(p.add_time, p.validity_num.Value) > DateTime.Now) || (p.validity_unit == "天" && DbFunctions.AddDays(p.add_time, p.validity_num.Value) > DateTime.Now)); } if (searchKey.status.HasValue) { data = data.Where(p => p.status == searchKey.status); } if (searchKey.pay_status.HasValue) { data = data.Where(p => p.pay_status == searchKey.pay_status); } if (searchKey.add_userid != 0) { data = data.Where(p => p.add_userid == searchKey.add_userid); } if (isOrder == false) { return(data); } var orderData = searchKey.add_userid != 0? data.OrderByDescending(p => p.id) : data.OrderByDescending(p => p.set_top); if (searchKey.recommend.HasValue && searchKey.recommend.Value) { orderData = orderData.ThenByDescending(p => p.praise_num); } orderData = orderData.ThenByDescending(p => p.update_time); return(orderData); }
/// <summary> /// 获取信息列表返回数据 /// </summary> /// <returns></returns> public static Model.Model.PageResult <ht_news> GetNewsListPageResult(int page, int rows, ht_news searchKey, int curUserid) { Model.Model.PageResult <ht_news> pageModel = new Model.Model.PageResult <ht_news>(); using (Entities db = new Entities()) { pageModel.total = GetNewsData(db, searchKey).Count(); pageModel.list = GetNewsData(db, searchKey, true).Skip((page - 1) * rows).Take(rows).ToList(); if (searchKey.add_userid == 0 && curUserid > 0) { foreach (var item in pageModel.list) { item.is_praise = db.ht_comm_relation.FirstOrDefault(p => p.main_id == item.id.ToString() && p.relation_id == curUserid.ToString() && p.relation_type == "praise") != null; } } } pageModel.totalpage = (int)Math.Ceiling((decimal)pageModel.total / (decimal)rows);//总页数 return(pageModel); }
/// <summary> /// 构造查询IQueryable /// </summary> /// <param name="db">查询条件</param> /// <param name="searchKey">查询条件</param> /// <param name="searchKey">查询条件</param> /// <param name="searchKey">查询条件</param> /// <returns></returns> private static IQueryable <ht_news> GetNewsData(Entities db, ht_news searchKey, bool isOrder = false, bool isRecommend = false) { db.Configuration.ProxyCreationEnabled = false; var data = db.ht_news.Where(p => true); if (searchKey.cateid != 0) { data = data.Where(p => p.cateid == searchKey.cateid); } if (!string.IsNullOrWhiteSpace(searchKey.start_province)) { data = data.Where(p => p.start_province == searchKey.start_province); } if (!string.IsNullOrWhiteSpace(searchKey.start_city)) { data = data.Where(p => p.start_city == searchKey.start_city); } if (!string.IsNullOrWhiteSpace(searchKey.start_district)) { data = data.Where(p => p.start_district == searchKey.start_district); } if (!string.IsNullOrWhiteSpace(searchKey.stop_province)) { data = data.Where(p => p.stop_province == searchKey.stop_province); } if (!string.IsNullOrWhiteSpace(searchKey.stop_city)) { data = data.Where(p => p.stop_city == searchKey.stop_city); } if (!string.IsNullOrWhiteSpace(searchKey.stop_district)) { data = data.Where(p => p.stop_district == searchKey.stop_district); } if (!string.IsNullOrWhiteSpace(searchKey.use_type)) { data = data.Where(p => p.use_type == searchKey.use_type); } if (!string.IsNullOrWhiteSpace(searchKey.car_length)) { data = data.Where(p => p.car_length == searchKey.car_length); } if (!string.IsNullOrWhiteSpace(searchKey.car_style)) { data = data.Where(p => p.car_style == searchKey.car_style); } if (!string.IsNullOrWhiteSpace(searchKey.goods_type)) { data = data.Where(p => p.goods_type == searchKey.goods_type); } if (isOrder == false) { return(data); } var orderData = data.OrderByDescending(p => p.set_top); if (isRecommend) { orderData = orderData.ThenByDescending(p => p.praise_num); } orderData = orderData.ThenByDescending(p => p.update_time); return(orderData); }
/// <summary> /// 热门推荐(猜你喜欢) /// </summary> /// <param name="page"></param> /// <param name="rows"></param> /// <param name="id">排除当前记录</param> /// <param name="min">最少返回数</param> /// <returns></returns> public static List <ht_news> GetRecommendNewsList(int page, int rows, int id, int min = 1) { using (Entities db = new Entities()) { db.Configuration.ProxyCreationEnabled = false; ht_news searchKey = db.ht_news.FirstOrDefault(p => p.id == id); var data = db.ht_news.Where(p => true); if (searchKey == null) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } //排除id if (searchKey.id != 0) { data = data.Where(p => p.id != searchKey.id); } //分类一致 if (searchKey.cateid != 0) { data = data.Where(p => p.cateid == searchKey.cateid); } if (!string.IsNullOrWhiteSpace(searchKey.use_type)) { if (data.Where(p => p.use_type == searchKey.use_type).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.use_type == searchKey.use_type); } if (!string.IsNullOrWhiteSpace(searchKey.car_style)) { if (data.Where(p => p.car_style == searchKey.car_style).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.car_style == searchKey.car_style); } if (!string.IsNullOrWhiteSpace(searchKey.car_length)) { if (data.Where(p => p.car_length == searchKey.car_length).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.car_length == searchKey.car_length); } if (!string.IsNullOrWhiteSpace(searchKey.goods_type)) { if (data.Where(p => p.goods_type == searchKey.goods_type).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.goods_type == searchKey.goods_type); } if (!string.IsNullOrWhiteSpace(searchKey.start_province)) { if (data.Where(p => p.start_province == searchKey.start_province).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.start_province == searchKey.start_province); } if (!string.IsNullOrWhiteSpace(searchKey.start_city)) { if (data.Where(p => p.start_city == searchKey.start_city).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.start_city == searchKey.start_city); } if (!string.IsNullOrWhiteSpace(searchKey.start_district)) { if (data.Where(p => p.start_district == searchKey.start_district).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.start_district == searchKey.start_district); } if (!string.IsNullOrWhiteSpace(searchKey.stop_province)) { if (data.Where(p => p.stop_province == searchKey.stop_province).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.stop_province == searchKey.stop_province); } if (!string.IsNullOrWhiteSpace(searchKey.stop_city)) { if (data.Where(p => p.stop_city == searchKey.stop_city).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.stop_city == searchKey.stop_city); } if (!string.IsNullOrWhiteSpace(searchKey.stop_district)) { if (data.Where(p => p.stop_district == searchKey.stop_district).Count() < min) { return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } data = data.Where(p => p.stop_district == searchKey.stop_district); } return(data.OrderByDescending(p => p.set_top) .ThenByDescending(p => p.praise_num) .ThenByDescending(p => p.update_time).ToList()); } }
/// <summary> /// 获取信息列表返回数据 /// </summary> /// <returns></returns> public static Model.Model.PageResult <ht_news> GetNewsListPageResult(int page, int rows, ht_news searchKey, bool isRecommend) { Model.Model.PageResult <ht_news> pageModel = new Model.Model.PageResult <ht_news>(); using (Entities db = new Entities()) { pageModel.total = GetNewsData(db, searchKey).Count(); pageModel.list = GetNewsData(db, searchKey, true, isRecommend).Skip((page - 1) * rows).Take(rows).ToList(); } pageModel.totalpage = (int)Math.Ceiling((decimal)pageModel.total / (decimal)rows);//总页数 return(pageModel); }