示例#1
0
        public async Task <ApiResult> Addusers(APIProUserViewModel p)
        {
            // 以接口的形式返回数据
            var res = new ApiResult();
            List <ProjectUserInfo> projectUserInfos  = projectUserdb.GetWhere(o => o.ProjectID == p.ProjectID && o.ProjectNodeID == p.ProjectNodeID && o.IsEnable == true && o.UserID == p.UserID);
            List <ProjectUserInfo> projectUserInfos2 = projectUserdb.GetWhere(o => o.ProjectID == p.ProjectID && o.ProjectNodeID == p.ProjectNodeID && o.IsEnable == true && o.Role == 1);

            if (projectUserInfos.Count > 0)
            {
                res.msg     = "已有此人";
                res.success = false;
            }
            else if (projectUserInfos2.Count > 0 && p.Role == 1 && p.IsEnable == true)
            {
                res.msg     = "已有组长,请修改";
                res.success = false;
            }
            else
            {
                try
                {
                    ProjectUserInfo m = new ProjectUserInfo()
                    {
                        ProjectID     = p.ProjectID,
                        ProjectNodeID = p.ProjectNodeID,
                        UserID        = p.UserID,
                        Role          = p.Role,
                        Proportion    = p.Proportion,
                        Sorting       = p.Sorting,
                        AddDate       = DateTime.Now,
                        IsEnable      = p.IsEnable
                    };
                    res.success = projectUserdb.Add(m) > 0;
                }
                catch (Exception ex)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.msg        = ApiEnum.Error.GetEnumText() + ex.Message;
                }
            }
            // {"success":true,"message":null,"statusCode":200,"data":null}
            return(await Task.Run(() => res));
        }
        public async Task <ApiResult <IEnumerable <ProjectNodeViewModel> > > GetList(int pageIndex, string?ProjectTypeID, string?ProjectID, bool?IsEnable, int?State, string?Title)
        {
            var res = new ApiResult <IEnumerable <ProjectNodeViewModel> >()
            {
                statusCode = (int)ApiEnum.Status
            };
            int UserID = GetUserID();

            if (UserID > 0)
            {
                if (pageIndex == 0)
                {
                    pageIndex = 1;
                }
                var parm = Expressionable.Create <ProjectNodeInfo>();
                PagedInfo <ProjectNodeInfo> list = null;
                UserInfo userInfo = userdb.GetId(UserID);
                if (userInfo != null)
                {
                    var parm2 = Expressionable.Create <ProjectUserInfo>()
                                .AndIF(userInfo.RoleID != 1, o => o.UserID == UserID)
                                .And(o => o.IsEnable == true);
                    List <ProjectUserInfo> projectUserInfo = projectUserdb.GetWhere(parm2.ToExpression());
                    int[] nodes;
                    if (projectUserInfo != null && projectUserInfo.Count > 0)
                    {
                        if (userInfo.RoleID != 1)
                        {
                            nodes = new int[projectUserInfo.Count];
                            int i = 0;
                            foreach (var item in projectUserInfo)
                            {
                                nodes[i] = item.ProjectNodeID;
                                i++;
                            }
                            parm.AndIF(nodes.Length > 0, o => nodes.Contains(o.ID));
                        }
                        parm.AndIF(!string.IsNullOrWhiteSpace(ProjectID), m => m.ProjectID == ProjectID);
                        parm.AndIF(IsEnable != null, m => m.IsEnable == IsEnable);
                        parm.AndIF(State != null, m => m.State == State);
                        parm.AndIF(!string.IsNullOrWhiteSpace(Title), m => m.Title.Contains(Title));
                        parm.And(m => m.TypeID == 1);
                        if (!string.IsNullOrWhiteSpace(ProjectTypeID))
                        {
                            List <ProjectInfo> projects = Projectdb.GetList("Projects", Builders <ProjectInfo> .Filter.Where(o => o.ProjectTypeID == ProjectTypeID), null, null);
                            string[]           x        = new string[projects.Count];
                            int a = 0;
                            foreach (var item in projects)
                            {
                                x[a] = item.ID;
                                a++;
                            }
                            parm.And(m => x.Contains(m.ProjectID));
                        }
                        list = PNdb.GetPages(parm.ToExpression(), new PageParm(pageIndex), "ID DESC");
                    }
                    List <ProjectNodeViewModel> list2 = new List <ProjectNodeViewModel>();
                    if (list != null)
                    {
                        foreach (var item in list.DataSource)
                        {
                            ProjectNodeViewModel projectNodeViewModel = IMapper.Map <ProjectNodeViewModel>(item);
                            projectNodeViewModel.PlanCount = plandb.GetCount(o => o.ProjectNodeID == item.ID && o.ProjectID == item.ProjectID);
                            ProjectInfo     projectInfo = Projectdb.Get("Projects", item.ProjectID);
                            List <UserInfo> userInfos   = userdb.GetWhere(a => SqlFunc.Subqueryable <ProjectUserInfo>().Where(b => b.UserID == a.ID && b.ProjectNodeID == item.ID && b.Role == 1 && b.IsEnable == true).Any());
                            if (userInfos != null)
                            {
                                List <APITeamMembersViewModel> ats = new List <APITeamMembersViewModel>();
                                foreach (var item2 in userInfos)
                                {
                                    ats.Add(new APITeamMembersViewModel()
                                    {
                                        ID   = item2.ID,
                                        Name = userdb.GetNames(item2)
                                    });
                                }
                                projectNodeViewModel.Teamleades = ats;
                            }
                            List <UserInfo> userInfos2 = userdb.GetWhere(a => SqlFunc.Subqueryable <ProjectUserInfo>().Where(b => b.UserID == a.ID && b.ProjectNodeID == item.ID && b.Role == 2 && b.IsEnable == true).Any());
                            if (userInfos2 != null)
                            {
                                List <APITeamMembersViewModel> ats = new List <APITeamMembersViewModel>();
                                foreach (var item2 in userInfos2)
                                {
                                    ats.Add(new APITeamMembersViewModel()
                                    {
                                        ID   = item2.ID,
                                        Name = userdb.GetNames(item2)
                                    });
                                }
                                projectNodeViewModel.Teammembers = ats;
                            }
                            if (projectInfo != null)
                            {
                                projectNodeViewModel.ProjectName   = projectInfo.Names;
                                projectNodeViewModel.ProjectTypeID = projectInfo.ProjectTypeID;
                            }
                            list2.Add(projectNodeViewModel);
                        }
                        res.success = true;
                        res.data    = list2;
                        res.index   = pageIndex;
                        res.count   = list.TotalCount;
                        res.size    = list.PageSize;
                        res.pages   = list.TotalPages;
                    }
                    else
                    {
                        res.success    = true;
                        res.statusCode = (int)ApiEnum.Status;
                    }
                }
                else
                {
                    res.msg = "无该用户信息";
                }
            }
            else
            {
                res.msg = "请重新登陆";
            }
            return(await Task.Run(() => res));
        }
示例#3
0
        public async Task <ApiResult <APIProNodesListWelViewModel> > WelcomeNodesList()
        {
            var res = new ApiResult <APIProNodesListWelViewModel>()
            {
                statusCode = (int)ApiEnum.Status
            };
            int UserID = GetUserID();

            if (UserID > 0)
            {
                var parm = Expressionable.Create <ProjectNodeInfo>();
                parm.And(o => o.IsEnable == true);
                List <ProjectNodeInfo> list            = null;
                UserInfo userInfo                      = db.GetId(UserID);
                List <ProjectUserInfo> projectUserInfo = projectUserdb.GetWhere(o => o.UserID == UserID && o.IsEnable == true);
                int[] nodes;
                if (projectUserInfo != null && projectUserInfo.Count > 0)
                {
                    if (userInfo.RoleID != 1)
                    {
                        nodes = new int[projectUserInfo.Count];
                        int i = 0;
                        foreach (var item in projectUserInfo)
                        {
                            nodes[i] = item.ProjectNodeID;
                            i++;
                        }
                        parm.AndIF(nodes.Length > 0, o => nodes.Contains(o.ID));
                    }
                }
                list = PNdb.GetNopage(parm.ToExpression(), "ID DESC");
                APIProNodesListWelViewModel aPIProNodesListWelViewModel = new APIProNodesListWelViewModel();
                if (list != null && list.Count > 0)
                {
                    IEnumerable <ProjectNodeInfo>  list2          = list.Where(o => o.State == 1 || o.State == 2);
                    List <APIProNodesWelViewModel> CompleteList   = new List <APIProNodesWelViewModel>();
                    List <APIProNodesWelViewModel> UnfinishedList = new List <APIProNodesWelViewModel>();
                    List <APIProNodesWelViewModel> DelayList      = new List <APIProNodesWelViewModel>();
                    foreach (var item in list2)
                    {
                        ProjectInfo projectInfo = Projectdb.Get("Projects", item.ProjectID);
                        if (projectInfo != null)
                        {
                            //APIProNodesWelViewModel aPIProNodesWelViewModel = new APIProNodesWelViewModel();
                            //aPIProNodesWelViewModel.ProName = projectInfo.Names;
                            //aPIProNodesWelViewModel.ProNodeTitle = item.Title;
                            //aPIProNodesListWelViewModel.CompleteList.Add(aPIProNodesWelViewModel);
                            CompleteList.Add(new APIProNodesWelViewModel
                            {
                                ProName      = projectInfo.Names,
                                ProNodeTitle = item.Title
                            });
                        }
                    }
                    aPIProNodesListWelViewModel.CompleteList = CompleteList;
                    IEnumerable <ProjectNodeInfo> list3 = list.Where(o => o.State == 0);
                    foreach (var item in list3)
                    {
                        ProjectInfo projectInfo = Projectdb.Get("Projects", item.ProjectID);
                        if (projectInfo != null)
                        {
                            UnfinishedList.Add(new APIProNodesWelViewModel
                            {
                                ProName      = projectInfo.Names,
                                ProNodeTitle = item.Title
                            });
                        }
                    }
                    aPIProNodesListWelViewModel.UnfinishedList = UnfinishedList;
                    IEnumerable <ProjectNodeInfo> list4 = list.Where(o => o.State == 3 || o.State == 4);
                    foreach (var item in list4)
                    {
                        ProjectInfo projectInfo = Projectdb.Get("Projects", item.ProjectID);
                        if (projectInfo != null)
                        {
                            DelayList.Add(new APIProNodesWelViewModel
                            {
                                ProName      = projectInfo.Names,
                                ProNodeTitle = item.Title
                            });
                        }
                    }
                    aPIProNodesListWelViewModel.DelayList = DelayList;
                }
                res.data    = aPIProNodesListWelViewModel;
                res.success = true;
            }
            else
            {
                res.msg = "请重新登陆";
            }
            return(await Task.Run(() => res));
        }