Exemplo n.º 1
0
        public static List <Develop_Demand> PageList(DemandSearch demandSearch, int page, int pageSize, out long records)
        {
            var deptId = demandSearch.DeptId;
            var type   = demandSearch.DemandType;

            var where = new Where <Develop_Demand>();
            if (deptId > 0)
            {
                where.And(o => o.DeptId == deptId);
            }
            if (type > 0)
            {
                where.And(o => o.Type == type);
            }
            if (!demandSearch.IsAdmin && !demandSearch.IsShow)
            {
                where.And(o => o.CreateUserId == demandSearch.LoginUserId || o.ExecutorId == demandSearch.LoginUserId);
            }
            var p = Db.Context.From <Develop_Demand>()
                    .Where(where);

            records = p.Count();
            return(p.Page(pageSize, page).OrderByDescending(o => o.Id).ToList());
        }
Exemplo n.º 2
0
        public IHttpActionResult PageList(int deptId, int demandType, int page, int pageSize)
        {
            List <DemandModel> resultList = new List <DemandModel>();
            long         records          = 0;
            int          loginUserId      = MyInfo.Id;
            DemandSearch demandSearch     = new DemandSearch {
                DeptId = deptId, DemandType = demandType, LoginUserId = loginUserId
            };
            var adminList = DemandTypeHelper.GetDeamndAdminUserIdList("DemandAdminUserId");

            if (adminList.Contains(loginUserId.ToString()))
            {
                demandSearch.IsAdmin = true;
            }
            var showList = DemandTypeHelper.GetDeamndAdminUserIdList("DemandShowUserId");

            if (showList.Contains(loginUserId.ToString()))
            {
                demandSearch.IsShow = true;
            }
            var list = Bll.BllDevelop_Demand.PageList(demandSearch, page, pageSize, out records);

            try
            {
                if (list != null && list.Count > 0)
                {
                    var userIdList = new List <int>();
                    userIdList.AddRange(list.Where(p => p.CreateUserId > 0).Select(p => p.CreateUserId).Distinct());
                    userIdList.AddRange(list.Where(p => p.ExecutorId.HasValue && p.ExecutorId > 0).Select(p => p.ExecutorId.Value).Distinct());
                    var userList = Bll.BllMng_User.GetListByIds(userIdList);
                    resultList = list.MapperConvert <List <DemandModel> >();
                    var deptList = DepartmentData.GetList();
                    foreach (var item in resultList)
                    {
                        item.StatusStr = ((Demand_StatusEnum)item.Status).ToString();
                        item.TypeStr   = ((Demand_TypeEnum)item.Type).ToString();
                        if (userList != null)
                        {
                            var createUser = userList.Where(p => p.Id == item.CreateUserId).FirstOrDefault();
                            if (createUser != null)
                            {
                                item.CreateUser = createUser.RealName;
                            }
                            var executorUser = userList.Where(p => p.Id == item.ExecutorId).FirstOrDefault();
                            if (executorUser != null)
                            {
                                item.ExecutorUser = executorUser.RealName;
                            }
                        }
                        if (deptList != null)
                        {
                            var dept = deptList.Where(p => p.Id == item.DeptId).FirstOrDefault();
                            if (dept != null)
                            {
                                item.DeptName = dept.ClassName;
                            }
                        }

                        item.IsAdmin = demandSearch.IsAdmin;
                        item.IsShow  = demandSearch.IsShow;
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }


            return(Ok(new { rows = resultList, total = records }));
        }