Esempio n. 1
0
        /// <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);
        }
        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>
        /// <param name="data">
        /// {
        ///   "notice_id": 若大于零则为修改,小于零则为新增,
        ///   "title": 通知标题,
        ///   "content": 通知内容,
        ///   "logo": 通知的 logo,
        ///   "is_top": 0 不置顶,1 置顶,
        ///   "publish_time": 发布时间,在该时间后才能查询到该通知,若不设置,则为当前时间
        /// }
        /// </param>
        /// <returns></returns>
        public ApiResult AddNotice(dynamic data)
        {
            ApiResult apiResult = new ApiResult();

            if (Util.isNotNull(data))
            {
                string json               = Newtonsoft.Json.JsonConvert.SerializeObject(data);
                var    notice             = Newtonsoft.Json.JsonConvert.DeserializeObject <user_notice>(json);
                BaseBLL <user_notice> bll = new BaseBLL <user_notice>();
                if (notice?.notice_id > 0)
                {
                    //如果是置顶,应先将之前置顶的数据取消
                    if (notice.is_top == 1)
                    {
                        var is_top_notices = bll.FindList <int>(o => o.is_top == 1);
                        List <user_notice> is_top_notice_list = new List <user_notice>();
                        foreach (var _notice in is_top_notices)
                        {
                            _notice.is_top      = 0;
                            _notice.update_time = DateTime.Now;
                            is_top_notice_list.Add(_notice);
                        }
                        bll.UpdateMore(is_top_notice_list);
                    }
                    // 修改
                    var findNotice = bll.Find(n => n.notice_id == notice.notice_id);
                    if (findNotice == null)
                    {
                        apiResult.success = false;
                        apiResult.message = "不存在该通知";
                        return(apiResult);
                    }
                    notice.create_time = findNotice.create_time;
                    notice.update_time = DateTime.Now;
                    bll.Update(notice);
                }
                else if (Util.isNotNull(notice))
                {
                    //如果是置顶,应先将之前置顶的数据取消
                    if (notice.is_top == 1)
                    {
                        var is_top_notices = bll.FindList <int>(o => o.is_top == 1);
                        List <user_notice> is_top_notice_list = new List <user_notice>();
                        foreach (var _notice in is_top_notices)
                        {
                            _notice.is_top      = 0;
                            _notice.update_time = DateTime.Now;
                            is_top_notice_list.Add(_notice);
                        }
                        bll.UpdateMore(is_top_notice_list);
                    }
                    // 新增
                    if (!notice.publish_time.HasValue)
                    {
                        notice.publish_time = DateTime.Now;
                    }
                    notice.create_time = DateTime.Now;
                    notice.update_time = DateTime.Now;
                    bll.Add(notice);
                }
                else
                {
                    apiResult.success = false;
                    apiResult.message = "参数错误";
                    return(apiResult);
                }
            }
            else
            {
                apiResult.success = false;
                apiResult.message = "参数错误";
            }

            apiResult.success = true;
            apiResult.message = "成功";
            return(apiResult);
        }
Esempio n. 4
0
        /// <summary>
        /// 审核/退回
        /// formdata
        /// state:1退回,2审核
        /// return_tag(退回标签):xxxx,xxxx,xxxx
        /// return_remark(退回理由备注):xxxxxxxxxxx
        /// ids:1,2,3,4,5,6,7,8,9,10
        /// </summary>
        /// <returns></returns>
        public ApiResult SubmitArticle()
        {
            ApiResult apiResult     = new ApiResult();
            string    _state        = HttpContext.Current.Request.Form["state"];
            string    return_tag    = HttpContext.Current.Request.Form["return_tag"];
            string    return_remark = HttpContext.Current.Request.Form["return_remark"];
            string    _article_id   = HttpContext.Current.Request.Form["ids"];
            var       checkResult   = Util.CheckParameters(
                new Parameter {
                Value = _state, Msg = "state 不能为空值"
            },
                new Parameter {
                Value = _state, Msg = "state 必须是数字类型", Regex = @"^[1-9]\d*$"
            },
                new Parameter {
                Value = _article_id, Msg = "ids 不能为空值"
            }
                );

            if (!checkResult.OK)
            {
                apiResult.success = false;
                apiResult.status  = ApiStatusCode.InvalidParam;
                apiResult.message = checkResult.Msg;
                return(apiResult);
            }
            int        state   = int.Parse(_state);
            List <int> id_list = new List <int>();

            string[] article_ids = _article_id.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var id in article_ids)
            {
                int _id = 0;
                int.TryParse(id, out _id);
                if (_id > 0)
                {
                    id_list.Add(_id);
                }
            }
            BaseBLL <article_states> state_bll = new BaseBLL <article_states>();
            var article_states = state_bll.FindList <int>(o => id_list.Contains(o.article_id));

            if (state == 1)
            {
                List <article_states> back_list = new List <article_states>();
                foreach (var article_state in article_states)
                {
                    article_state.article_state = 1;
                    article_state.update_time   = DateTime.Now;
                    article_state.return_tag    = return_tag;
                    article_state.return_remark = return_remark;
                    back_list.Add(article_state);
                }
                state_bll.UpdateMore(back_list);
            }
            else if (state == 2)
            {
                List <article_states> sumbit_list = new List <article_states>();
                foreach (var article_state in article_states)
                {
                    article_state.article_state = 2;
                    article_state.update_time   = DateTime.Now;
                    article_state.return_remark = "";
                    article_state.return_tag    = "";
                    sumbit_list.Add(article_state);
                }
                state_bll.UpdateMore(sumbit_list);
            }
            else
            {
                return(new ApiResult()
                {
                    success = false,
                    message = "参数错误"
                });
            }
            apiResult.success = true;
            apiResult.message = state == 1 ? "退回成功" : "审核成功";
            return(apiResult);
        }