Пример #1
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 }));
        }