Ejemplo n.º 1
0
        public async Task <ActionResult <IEnumerable <VB_QT_Buoc> > > r1GetListUserNhanViec(BuocLenhGroupForUser options)
        {
            try
            {
                var userId = Convert.ToInt32(User.Claims.First(c => c.Type == "UserId").Value);
                var user   = await _context.Sys_Dm_User.FindAsync(userId);

                var buoc             = _context.VB_QT_Buoc.FirstOrDefault(x => x.MenuId == options.MenuId);
                var LenhTuongTac     = _context.VB_QT_LenhTuongTac.FirstOrDefault(x => x.Code == options.MaLenh);
                var buocLenhTuongTac = _context.VB_QT_BuocLenhTuongTac.FirstOrDefault(x => x.BuocId == buoc.Id && x.LenhTuongTacId == LenhTuongTac.Id);
                int hienNguoiNhan    = 0;
                if (buocLenhTuongTac != null)
                {
                    var buocLenhGroup = _context.VB_QT_BuocLenhGroupRole.FirstOrDefault(x => x.GroupRoleId == options.GroupRoleId && x.BuocLenhTuongTacId == buocLenhTuongTac.Id);
                    hienNguoiNhan = CheckNguoiNhan.DuocHienThiNguoiNhan(_context, options.GroupRoleId, buocLenhGroup.Id);
                }

                switch (hienNguoiNhan)
                {
                    #region Toàn công ty
                case 0:
                    var listNsAll = await _context.Sys_Dm_User.Select(a => new
                    {
                        UserId = a.Id,
                        a.FullName
                    }).ToListAsync();

                    return(new ObjectResult(new { error = 0, data = listNsAll }));

                    #endregion
                    #region Công ty mẹ
                case 1:
                    var listNsCTM = await _context.Sys_Dm_User.Where(x => x.CompanyId == 1).Select(a => new
                    {
                        UserId = a.Id,
                        a.FullName
                    }).ToListAsync();

                    return(new ObjectResult(new { error = 0, data = listNsCTM }));

                    #endregion
                    #region Công ty hiện tại
                case 2:

                    var listNsCurrent = await _context.Sys_Dm_User.Where(x => x.CompanyId == user.CompanyId).Select(a => new
                    {
                        UserId = a.Id,
                        a.FullName
                    }).ToListAsync();

                    return(new ObjectResult(new { error = 0, data = listNsCurrent }));

                    #endregion
                    #region Phòng ban
                case 3:
                    int DepId = 0;
                    var room  = await _context.Sys_Dm_Department.FindAsync(user.DepartmentId);

                    if (room.ParentId == null)
                    {
                        DepId = room.Id;
                    }
                    else
                    {
                        DepId = room.ParentId ?? 0;
                    }
                    var listPb   = _context.Sys_Dm_Department.Where(x => x.ParentId == DepId).Select(c => c.Id);
                    var listNsPB = await _context.Sys_Dm_User.Where(x => listPb.Contains(x.DepartmentId ?? 0) || x.DepartmentId == DepId).Select(a => new
                    {
                        UserId = a.Id,
                        a.FullName
                    }).ToListAsync();

                    return(new ObjectResult(new { error = 0, data = listNsPB }));

                    #endregion
                    #region Tổ
                case 4:
                    var listNsTo = await _context.Sys_Dm_User.Where(x => x.DepartmentId == user.DepartmentId).Select(a => new
                    {
                        UserId = a.Id,
                        a.FullName
                    }).ToListAsync();

                    return(new ObjectResult(new { error = 0, data = listNsTo }));

                    #endregion
                    #region Chỉ trưởng phòng
                case 7:
                    var listNsInPB = await _context.Sys_Dm_User.Where(x => x.ParentDepartId == user.ParentDepartId).Select(a => a.Id).ToListAsync();

                    var tps = await(from b in _context.Sys_Cog_UsersGroup
                                    join c in _context.Sys_Dm_GroupRole on b.GroupRoleId equals c.Id
                                    join a in _context.Sys_Dm_User on b.UserId equals a.Id
                                    where listNsInPB.Contains(b.UserId) && c.IsAdminDep == true
                                    select new
                    {
                        b.UserId,
                        a.FullName
                    }).ToListAsync();

                    return(new ObjectResult(new { error = 0, data = tps }));

                    #endregion
                default:
                    var listNsDef = await _context.Sys_Dm_User.Where(x => x.DepartmentId == user.DepartmentId).Select(a => new
                    {
                        UserId = a.Id,
                        a.FullName
                    }).ToListAsync();

                    return(new ObjectResult(new { error = 0, data = listNsDef }));
                }
            }
            catch (Exception ex)
            {
                return(new ObjectResult(new { error = 1 }));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <IEnumerable <VB_QT_Buoc> > > r1GetListDataMohinhToChuc(BuocLenhGroupForUser options)
        {
            try
            {
                var userId = Convert.ToInt32(User.Claims.First(c => c.Type == "UserId").Value);
                var user   = await _context.Sys_Dm_User.FindAsync(userId);

                int hienNguoiNhan = CheckNguoiNhan.DuocHienThiNguoiNhan(_context, options.GroupRoleId, options.BuocLenhGroupId);
                switch (hienNguoiNhan)
                {
                    #region Toàn công ty
                case 0:
                    var _listUniOn = await _context.Sys_Dm_Department.Where(x => x.ParentId == null && x.CompanyId == 1).Select(a => new
                    {
                        a.Id,
                        a.Name,
                        ParentId = a.CompanyId,
                        Loai     = 1
                    }).Union(
                        _context.Sys_Dm_Company.Where(x => x.ParentId == 1).Select(c => new
                    {
                        c.Id,
                        c.Name,
                        ParentId = 1,
                        Loai     = 0
                    })).ToListAsync();

                    var _listDepartMenttct = _context.Sys_Dm_Department.Where(x => x.ParentId == null).Select(a => new
                    {
                        a.Id,
                        a.Name,
                        a.CompanyId,
                        Loai     = 1,
                        children = _context.Sys_Dm_Department.Where(x => x.ParentId == a.Id).Select(v => new
                        {
                            v.Id,
                            v.Name,
                            Loai = 2
                        }).ToList()
                    });
                    var s = _listUniOn.Select(x => new
                    {
                        x.Id,
                        x.Name,
                        x.ParentId,
                        x.Loai,
                        children = x.Loai == 0 ? _listDepartMenttct.Where(b => b.CompanyId == x.Id).Select(k => new
                        {
                            k.Id,
                            k.Name,
                            k.Loai,
                            k.children
                        }).ToList() : _listDepartMenttct.Where(b => b.CompanyId == 0).Select(k => new
                        {
                            k.Id,
                            k.Name,
                            k.Loai,
                            k.children
                        }).ToList()
                    });
                    var tables = (from a in _context.Sys_Dm_Company
                                  where a.ParentId == null
                                  select new
                    {
                        a.Id,
                        a.Name,
                        Loai = 0,
                        a.IsOrder,
                        children = s.ToList()
                    }).ToList();
                    return(new ObjectResult(new { error = 0, data = tables.OrderBy(x => x.IsOrder) }));

                    #endregion
                    #region Công ty mẹ
                case 1:

                    var _listDepartMentctm = _context.Sys_Dm_Department.Where(x => x.ParentId == null).Select(a => new
                    {
                        a.Id,
                        a.Name,
                        a.CompanyId,
                        Loai     = 1,
                        children = _context.Sys_Dm_Department.Where(x => x.ParentId == a.Id).Select(v => new
                        {
                            v.Id,
                            v.Name,
                            Loai = 2
                        }).ToList()
                    });

                    var tables2 = (from a in _context.Sys_Dm_Company
                                   where a.ParentId == null
                                   select new
                    {
                        a.Id,
                        a.Name,
                        Loai = 0,
                        children = _listDepartMentctm.Where(x => x.CompanyId == a.Id).Select(c => new
                        {
                            c.Id,
                            c.Name,
                            c.Loai,
                            c.children
                        }).ToList()
                    }).ToList();
                    return(new ObjectResult(new { error = 0, data = tables2 }));

                    #endregion
                    #region Công ty hiện tại
                case 2:

                    var _listDepartMentctc = _context.Sys_Dm_Department.Where(x => x.ParentId == null).Select(a => new
                    {
                        a.Id,
                        a.Name,
                        a.CompanyId,
                        Loai     = 1,
                        children = _context.Sys_Dm_Department.Where(x => x.ParentId == a.Id).Select(v => new
                        {
                            v.Id,
                            v.Name,
                            Loai = 2
                        }).ToList()
                    });

                    var tables3 = (from a in _context.Sys_Dm_Company
                                   where a.Id == user.CompanyId
                                   select new
                    {
                        a.Id,
                        a.Name,
                        Loai = 0,
                        children = _listDepartMentctc.Where(x => x.CompanyId == user.CompanyId).Select(c => new
                        {
                            c.Id,
                            c.Name,
                            c.Loai,
                            c.children
                        }).ToList()
                    }).ToList();
                    return(new ObjectResult(new { error = 0, data = tables3 }));

                    #endregion
                    #region Phòng ban
                case 3:
                    int DepId = 0;
                    var room  = await _context.Sys_Dm_Department.FindAsync(user.DepartmentId);

                    if (room.ParentId == null)
                    {
                        DepId = room.Id;
                    }
                    else
                    {
                        DepId = room.ParentId ?? 0;
                    }
                    var _listDepartMents = _context.Sys_Dm_Department.Where(x => x.CompanyId == user.CompanyId && x.Id == DepId).Select(a => new
                    {
                        a.Id,
                        a.Name,
                        a.CompanyId,
                        Loai     = 1,
                        children = _context.Sys_Dm_Department.Where(x => x.ParentId == a.Id).Select(v => new
                        {
                            v.Id,
                            v.Name,
                            Loai = 2
                        }).ToList()
                    });
                    return(new ObjectResult(new { error = 0, data = _listDepartMents }));

                    #endregion
                    #region Tổ
                case 4:
                    var _listDepartMentTo = (_context.Sys_Dm_Department.Where(x => x.CompanyId == user.CompanyId && x.Id == user.DepartmentId).Select(a => new
                    {
                        a.Id,
                        a.Name,
                        a.CompanyId,
                        Loai = 2,
                        children = _context.Sys_Dm_Department.Where(x => x.ParentId == a.Id).Select(v => new
                        {
                            v.Id,
                            v.Name,
                            Loai = 2
                        }).ToList()
                    })).ToList();
                    return(new ObjectResult(new { error = 0, data = _listDepartMentTo }));

                    #endregion
                default:
                    var _listDepartMentToe = (_context.Sys_Dm_Department.Where(x => x.CompanyId == user.CompanyId && x.Id == user.DepartmentId).Select(a => new
                    {
                        a.Id,
                        a.Name,
                        a.CompanyId,
                        Loai = 2,
                        children = _context.Sys_Dm_Department.Where(x => x.ParentId == a.Id).Select(v => new
                        {
                            v.Id,
                            v.Name,
                            Loai = 2
                        }).ToList()
                    })).ToList();
                    return(new ObjectResult(new { error = 0, data = _listDepartMentToe }));
                }
            }
            catch (Exception ex)
            {
                return(new ObjectResult(new { error = 1 }));
            }
        }