/// <summary> /// 获取作品内容并获取上一篇,下一篇的id /// </summary> /// <param name="state">2初赛,3半决赛,4决赛</param> /// <param name="article_id"></param> /// <returns></returns> public ApiResult GetArticleInfoByAdmin(int state, int article_id) { ApiPageResult apiResult = new ApiPageResult(); var checkResult = Util.CheckParameters( new Parameter { Value = state.ToString(), Msg = "state 不能为空值" }, new Parameter { Value = state.ToString(), Msg = "state 必须是数字类型", Regex = @"^[1-9]\d*$" }, new Parameter { Value = article_id.ToString(), Msg = "article_id 不能为空值" }, new Parameter { Value = article_id.ToString(), Msg = "article_id 必须是数字类型", Regex = @"^[1-9]\d*$" } ); if (!checkResult.OK) { apiResult.success = false; apiResult.status = ApiStatusCode.InvalidParam; apiResult.message = checkResult.Msg; return(apiResult); } ArticleBLL bll = new ArticleBLL(); return(bll.GetArticleInfoByAdmin(state, article_id)); }
public async Task <ApiPageResult> GetUsers([FromBody] UserSearchCriteria criteria) { var result = new ApiPageResult(); var page = await _userService.GetPageAsync(criteria); result.Code = 200; result.Message = "获取用户列表成功"; result.Page = page; return(result); }
public async Task <ApiPageResult> GetNotificationsForManager([FromBody] NotificationSearchCriteria criteria) { var page = await _notificationService.GetPageAsync(criteria); var result = new ApiPageResult { Code = 200, Message = "获取通知列表成功", Page = page, }; return(result); }
public async Task <ApiPageResult <NotificationUser> > GetNotifications([FromBody] NotificationPageSearchCriteria criteria) { criteria.ToUserId = HttpContext.User.GetUserId(); var page = await _notificationService.GetPageAsync(criteria); var result = new ApiPageResult <NotificationUser> { Code = 200, Message = "获取通知列表成功", Page = page, }; return(result); }
/// <summary> /// 获取作品列表 /// </summary> /// <param name="zone_id">赛区id</param> /// <param name="keyword">作品编号/标题/作者</param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ApiPageResult GetArticleList(int uid, int zone_id, int competiontion_season_id, string keyword = null, int pageIndex = GloabManager.PAGEINDEX, int pageSize = GloabManager.PAGESIZE) { ApiPageResult apiResult = new ApiPageResult(); apiResult.pageIndex = pageIndex; apiResult.pageSize = pageSize; //作品列表(必须是审核通过了的) var article_list = from a in db.Set <articles>() join b in db.Set <article_competition_season>() on a.article_id equals b.article_id into ab1 from ab in ab1.DefaultIfEmpty() where ab.competiontion_season_id == competiontion_season_id join c in db.Set <author_info>() on a.uid equals c.uid join d in db.Set <article_states>() on a.article_id equals d.article_id where d.article_state >= 2 select new { a.article_id, ab.zone_id, a.article_no, a.article_pic, a.article_title, a.uid, c.user_name }; if (!string.IsNullOrEmpty(keyword)) { article_list = article_list.Where(o => o.article_no.Contains(keyword) || o.article_title.Contains(keyword) || o.user_name.Contains(keyword)); } if (zone_id > 0) { article_list = article_list.Where(o => o.zone_id == zone_id); } //票数计算 var vote_count = from a in db.Set <vote_record>() group a by a.article_id into b select new { b.Key, vote_count = (int?)b.Count() }; int count = article_list.Count(); var _data = article_list.OrderByDescending(o => o.article_id).Skip((pageIndex - 1) * pageSize).Take(pageSize); var data = from a in _data join b in vote_count on a.article_id equals b.Key into ab1 from ab in ab1.DefaultIfEmpty() select new { article = a, vote_count = ab.vote_count ?? 0 }; //我的票数 DateTime start = DateTime.Now.Date; DateTime end = DateTime.Now.AddDays(1).Date; //我的投票数 var my_vote_count = from a in db.Set <vote_record>() where a.create_time >= start && a.create_time < end group a by a.uid into b where b.Key == uid select new { vote_count = (int?)b.Count() }; //我对哪些作品投票了,投了多少票 var my_vote_article_count = from a in db.Set <vote_record>() where a.create_time >= start && a.create_time < end && a.uid == uid group a by a.article_id into b select new { article_id = b.Key, vote_count = (int?)b.Count() }; var list = from a in data join b in my_vote_article_count on a.article.article_id equals b.article_id into ab1 from ab in ab1.DefaultIfEmpty() select new { data = a, my_vote_article_count = ab.vote_count }; apiResult.success = true; apiResult.message = "获取作品列表"; apiResult.data = new { list, my_vote_count }; apiResult.totalCount = count; return(apiResult); }
/// <summary> /// 获取所有开启大赛公告 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ApiPageResult GetAllNotices(int pageIndex = GloabManager.PAGEINDEX, int pageSize = GloabManager.PAGESIZE) { ApiPageResult apiResult = new ApiPageResult(); apiResult.pageIndex = pageIndex; apiResult.pageSize = pageSize; BaseBLL <competition_notice> bll = new BaseBLL <competition_notice>(); var list = bll.FindList <int>(o => o.is_delete == 0 && o.is_open == 1); int count = list.Count(); list = list.OrderBy(o => new { o.topsize, o.competition_season_id }).Skip((pageIndex - 1) * pageSize).Take(pageSize); apiResult.success = true; apiResult.message = "获取所有大赛公告"; apiResult.data = list; apiResult.totalCount = count; return(apiResult); }
/// <summary> /// 获取作品列表(小程序,必须是审核过的) /// </summary> /// <param name="uid">赛区id</param> /// <param name="zone_id">赛区id</param> /// <param name="keyword">作品编号/标题/作者</param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ApiPageResult GetArticleList(int uid, int zone_id = 0, string keyword = null, int pageIndex = GloabManager.PAGEINDEX, int pageSize = GloabManager.PAGESIZE) { ApiPageResult apiResult = new ApiPageResult(); var checkResult = Util.CheckParameters( new Parameter { Value = uid.ToString(), Msg = "uid 不能为空值" }, new Parameter { Value = uid.ToString(), Msg = "uid 必须是数字类型", Regex = @"^[1-9]\d*$" }, new Parameter { Value = zone_id.ToString(), Msg = "zone_id 不能为空值" }, new Parameter { Value = zone_id.ToString(), Msg = "zone_id 必须是数字类型", Regex = @"^[0-9]\d*$" } ); if (!checkResult.OK) { apiResult.success = false; apiResult.status = ApiStatusCode.InvalidParam; apiResult.message = checkResult.Msg; return(apiResult); } //查到当前默认开启的赛季 BaseBLL <competition_notice> notice_bll = new BaseBLL <competition_notice>(); var competion_season = notice_bll.Find(o => o.is_delete == 0 && o.is_open == 1); int competiontion_season_id = competion_season?.competition_season_id ?? 0; if (competiontion_season_id == 0) { return(new ApiPageResult() { success = false, message = "当前没有开启任何赛季" }); } ArticleBLL bll = new ArticleBLL(); return(bll.GetArticleList(uid, zone_id, competiontion_season_id, keyword, pageIndex, pageSize)); }
/// <summary> /// 作品管理查询 /// </summary> /// <param name="keyword">查询的关键字:作品编号/标题/作者</param> /// <param name="state">-1全部,0初始,1审核不通过,2审核通过,3半决赛,4决赛</param> /// <param name="zone_id">0全部</param> /// <param name="start">开始时间</param> /// <param name="end">结束时间</param> /// <param name="orderby">排序字段:vote按票数顺序排,votedesc按票数倒叙排,date按投稿时间顺序排,datedesc按投稿时间倒叙排</param> /// <param name="pageIndex">1</param> /// <param name="pageSize">10</param> /// <returns></returns> public ApiPageResult GetArticleList(string keyword = null, int state = -1, int zone_id = 0, DateTime?start = null, DateTime?end = null, string orderby = null, int pageIndex = GloabManager.PAGEINDEX, int pageSize = GloabManager.PAGESIZE) { ApiPageResult apiResult = new ApiPageResult(); //赛季 BaseBLL <competition_notice> notice_bll = new BaseBLL <competition_notice>(); var notice = notice_bll.Find(o => o.is_delete == 0 && o.is_open == 1); if (notice?.competition_season_id > 0) { CompetitionBLL bll = new CompetitionBLL(); return(bll.GetArticleList(keyword, state, notice.competition_season_id, zone_id, start, end, orderby, pageIndex, pageSize)); } else { return(new ApiPageResult() { success = false, message = "当前没有开启的赛季" }); } }
/// <summary> /// 我的投票记录 /// </summary> /// <param name="uid"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ApiPageResult GetMyVoteRecord(int uid, int pageIndex = GloabManager.PAGEINDEX, int pageSize = GloabManager.PAGESIZE) { ApiPageResult apiResult = new ApiPageResult(); var checkResult = Util.CheckParameters( new Parameter { Value = uid.ToString(), Msg = "zone_id 不能为空值" }, new Parameter { Value = uid.ToString(), Msg = "zone_id 必须是数字类型", Regex = @"^[1-9]\d*$" } ); if (!checkResult.OK) { apiResult.success = false; apiResult.status = ApiStatusCode.InvalidParam; apiResult.message = checkResult.Msg; return(apiResult); } UsersBLL bll = new UsersBLL(); return(bll.GetMyVoteRecord(uid, pageIndex, pageSize)); }
/// <summary> /// 我的投票记录 /// </summary> /// <param name="uid"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ApiPageResult GetMyVoteRecord(int uid, int pageIndex = GloabManager.PAGEINDEX, int pageSize = GloabManager.PAGESIZE) { ApiPageResult apiResult = new ApiPageResult(); apiResult.pageIndex = pageIndex; apiResult.pageSize = pageSize; var article = from a in db.Set <vote_record>() join b in db.Set <articles>() on a.article_id equals b.article_id join c in db.Set <author_info>() on b.uid equals c.uid into ac1 from ac in ac1.DefaultIfEmpty() where a.uid == uid select new { b.article_id, b.article_pic, b.article_title, b.article_content, ac.user_name }; int count = article.Distinct().Count(); var _data = article.Distinct().OrderBy(o => o.article_id).Skip((pageIndex - 1) * pageSize).Take(pageSize); var vote_count = from a in db.Set <vote_record>() group a by a.article_id into b select new { b.Key, vote_count = (int?)b.Count() }; var data = from a in _data join b in vote_count on a.article_id equals b.Key into ab1 from ab in ab1.DefaultIfEmpty() select new { article = a, vote_count = ab.vote_count ?? 0 }; apiResult.data = data; apiResult.success = true; apiResult.message = "我的投票记录"; apiResult.totalCount = count; return(apiResult); }
public ApiPageResult GetAllNotices(DateTime?start = null, DateTime?end = null, int is_show = 1, int pageIndex = GloabManager.PAGEINDEX, int pageSize = GloabManager.PAGESIZE) { ApiPageResult apiPageResult = new ApiPageResult(); apiPageResult.pageIndex = pageIndex; apiPageResult.pageSize = pageSize; BaseBLL <user_notice> bll = new BaseBLL <user_notice>(); var list = bll.FindList <int>(notice => true); if (is_show == 0) { list = list.Where(o => o.publish_time <= DateTime.Now); } if (start.HasValue) { list = list.Where(notice => notice.update_time > start.Value && notice.update_time < (end ?? DateTime.Now)); } int count = list.Count(); var top_notice = list.Where(o => o.is_top == 1); list = list.OrderByDescending(notice => notice.update_time).Skip((pageIndex - 1) * pageSize).Take(pageSize); var result = list.Select(notice => new { notice.notice_id, notice.title, notice.content, notice.is_top, notice.publish_time, }); apiPageResult.success = true; apiPageResult.message = "获取所有通知"; apiPageResult.data = new { result, top_notice }; apiPageResult.totalCount = count; return(apiPageResult); }
/// <summary> /// 生成一个标准返回对象(返回分页) /// </summary> /// <typeparam name="TResult">返回类型,基于ApiResult</typeparam> /// <param name="request">请求对象</param> /// <param name="statusCode">HTTP状态码</param> /// <param name="result">返回内容</param> /// <returns>HttpResponseMessage对象</returns> /// <returns></returns> public static ApiResponseMessage <ApiPageResult <TResult> > ToResponse <TResult>(this HttpRequestMessage request, ApiPageResult <TResult> result, HttpStatusCode statusCode = HttpStatusCode.OK) { if (result == null) { return(new ApiResponseMessage <ApiPageResult <TResult> >(statusCode) { RequestMessage = request }); } return(new ApiResponseMessage <ApiPageResult <TResult> >(result, statusCode) { RequestMessage = request }); }
/// <summary> /// 作品管理查询 /// </summary> /// <param name="keyword">查询的关键字:作品编号/标题/作者</param> /// <param name="state">-1全部,0初始,1审核不通过,2审核通过,3半决赛,4决赛</param> /// <param name="zone_id">0全部</param> /// <param name="start">开始时间</param> /// <param name="end">结束时间</param> /// <param name="orderby">排序字段:vote 按票数顺序排,votedesc 按票数倒叙排,date 按投稿时间顺序排,datedesc 按投稿时间倒叙排</param> /// <param name="pageIndex">1</param> /// <param name="pageSize">10</param> /// <returns></returns> public ApiPageResult GetArticleList(string keyword = null, int state = -1, int competition_season_id = 0, int zone_id = 0, DateTime?start = null, DateTime?end = null, string orderby = null, int pageIndex = GloabManager.PAGEINDEX, int pageSize = GloabManager.PAGESIZE) { ApiPageResult apiResult = new ApiPageResult(); apiResult.pageIndex = pageIndex; apiResult.pageSize = pageSize; var article_list = from a in db.Set <articles>() join b in db.Set <author_info>() on a.uid equals b.uid join c in db.Set <article_states>() on a.article_id equals c.article_id join d in db.Set <article_competition_season>() on a.article_id equals d.article_id where d.competiontion_season_id == competition_season_id select new { a.article_id, d.zone_id, a.article_no, a.article_title, b.user_name, a.create_time, c.article_state, c.adviser_score, c.expert_score, c.expert_name, c.return_tag, c.return_remark }; if (state >= 0) { article_list = article_list.Where(o => o.article_state == state); } else { article_list = article_list.Where(o => o.article_state <= 2); } if (!string.IsNullOrEmpty(keyword)) { article_list = article_list.Where(o => o.article_no.Contains(keyword) || o.user_name.Contains(keyword) || o.article_title.Contains(keyword)); } if (zone_id > 0) { article_list = article_list.Where(o => o.zone_id == zone_id); } if (start != null) { article_list = article_list.Where(o => o.create_time >= start); } if (end != null) { end = end.Value.AddDays(1); article_list = article_list.Where(o => o.create_time < end); } var vote_count = from a in db.Set <vote_record>() group a by a.article_id into b select new { article_id = b.Key, vote_count = (int?)b.Count() }; var data = from a in article_list join b in vote_count on a.article_id equals b.article_id into ab1 from ab in ab1.DefaultIfEmpty() select new { article = a, vote_count = ab.vote_count ?? 0, banjuesai = a.adviser_score * 0.6 + ab.vote_count ?? 0 * 0.4 }; int count = data.Count(); //初赛作品 if (state <= 2) { if (orderby == "vote") { data = data.OrderBy(o => o.vote_count).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "votedesc") { data = data.OrderByDescending(o => o.vote_count).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "date") { data = data.OrderBy(o => o.article.create_time).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "datedesc") { data = data.OrderByDescending(o => o.article.create_time).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else { data = data.OrderBy(o => o.article.article_id).Skip((pageIndex - 1) * pageSize).Take(pageSize); } apiResult.success = true; apiResult.message = "作品管理查询"; apiResult.data = data; apiResult.totalCount = count; } //半决赛 else if (state == 3) { var _data = data.AsEnumerable().OrderByDescending(o => o.banjuesai).Select((o, index) => new { row = index + 1, data = o }); if (orderby == "vote") { _data = _data.OrderBy(o => o.data.vote_count).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "votedesc") { _data = _data.OrderByDescending(o => o.data.vote_count).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "date") { _data = _data.OrderBy(o => o.data.article.create_time).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "datedesc") { _data = _data.OrderByDescending(o => o.data.article.create_time).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else { _data = _data.Skip((pageIndex - 1) * pageSize).Take(pageSize); } apiResult.success = true; apiResult.message = "作品管理查询"; apiResult.data = _data; apiResult.totalCount = count; } //决赛 else if (state == 4) { var _data = data.AsEnumerable().OrderByDescending(o => o.article.expert_score).Select((o, index) => new { row = index + 1, data = o }); if (orderby == "vote") { _data = _data.OrderBy(o => o.data.vote_count).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "votedesc") { _data = _data.OrderByDescending(o => o.data.vote_count).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "date") { _data = _data.OrderBy(o => o.data.article.create_time).Skip((pageIndex - 1) * pageSize).Take(pageSize); } else if (orderby == "datedesc") { _data = _data.Skip((pageIndex - 1) * pageSize).Take(pageSize); } apiResult.success = true; apiResult.message = "作品管理查询"; apiResult.data = _data; apiResult.totalCount = count; } else { return(new ApiPageResult() { success = false, message = "参数错误" }); } return(apiResult); }