Exemple #1
0
        public async Task <IActionResult> GetUserOutOrg([FromBody] SearchUserOrg search)
        {
            var listUserInGroup = _context.AdUserInGroups.Where(x => x.GroupUserCode == search.GroupUser).ToList();

            var query = await _context.Users
                        .Where(x => (search.Group == 2 && (x.BranchId == null || x.BranchId != search.Code)
                                     //|| search.Group == 1 && (x.DepartmentId == null || x.DepartmentId != search.Code)
                                     //|| search.Group == 3 && (x.ProfitCenterId == null || x.ProfitCenterId != search.Code)
                                     //|| search.Group == 4 && (x.AccountExecutiveId == null || x.AccountExecutiveId != search.Code)
                                     ) &&
                               (string.IsNullOrEmpty(search.Name) || x.UserName.ToLower().Contains(search.Name.ToLower()) || x.GivenName.ToLower().Contains(search.Name.ToLower())) &&
                               (string.IsNullOrEmpty(search.GroupUser) || (listUserInGroup.Count > 0 && listUserInGroup.Any(y => y.UserId == x.Id))) &&
                               x.UserType != 10 && x.Active)
                        .Select(x => new
            {
                UserId   = x.Id,
                UserName = x.UserName,
                FullName = x.GivenName,
                Email    = x.Email,
            })
                        .Skip((search.Page - 1) * search.Row).Take(search.Row)
                        .AsNoTracking().ToListAsync();

            return(Json(query));
        }
Exemple #2
0
        public IActionResult GetOrgByGroup([FromBody] SearchUserOrg search)
        {
            var query = _context.AdOrganizations
                        .Where(x => x.OrgGroup == search.Group)
                        .OrderBy(o => o.OrgName)
                        .Select(x => new
            {
                x.OrgId,
                x.OrgAddonCode,
                x.OrgCode,
                OrgName = string.Format("{0} - {1}", x.OrgCode, x.OrgName)
            });

            return(Json(query));
        }
Exemple #3
0
        public IActionResult GetUserInOrg([FromBody] SearchUserOrg search)
        {
            var query = _context.Users
                        .Where(x => ((search.Group == 2 && x.BranchId != null && x.BranchId == search.Code)
                                     //|| (search.Group == 1 && x.DepartmentId != null && x.DepartmentId == search.Code)
                                     //|| (search.Group == 3 && x.ProfitCenterId != null && x.ProfitCenterId == search.Code)
                                     || (search.Group == 4 && x.AccountExecutiveId != null && x.AccountExecutiveId == search.Code)) &&
                               (string.IsNullOrEmpty(search.Name) || x.UserName.ToLower().Contains(search.Name.ToLower()) || x.GivenName.ToLower().Contains(search.Name.ToLower())))
                        .Select(x => new
            {
                UserId   = x.Id,
                UserName = x.UserName,
                FullName = x.GivenName,
                Email    = x.Email,
            });

            return(Json(query));
        }
Exemple #4
0
        public IActionResult GetTreeBranch([FromBody] SearchUserOrg search)
        {
            var query = from x in _context.AdOrganizations
                        join gvd in _context.AdDivisions on x.Division equals gvd.Division into grp1
                        from vd in grp1.DefaultIfEmpty()
                        where (x.OrgGroup.HasValue && x.OrgGroup.Value == 2)
                        //&& (string.IsNullOrEmpty(jTablePara.Name) || x.OrgName.ToLower().Contains(jTablePara.Name.ToLower()) || x.OrgCode.ToLower().Contains(jTablePara.Name.ToLower()))
                        select new OrganizationModel
            {
                OrgId         = x.OrgId,
                OrgAddonCode  = x.OrgAddonCode,
                OrgCode       = x.OrgCode,
                OrgName       = string.Format("{0} - {1}", x.OrgCode, x.OrgName),
                OrgParentCode = x.Division == null ? null : string.Format("d_{0}", x.Division),
                OrgGroup      = x.OrgGroup,
                Ord           = x.Company == "HO" && x.Division == null ? 2 : x.Company == "DIV" ? 3 : x.Company == "BRA" ? 4 : 5,
                HierarchyCode = x.HierarchyCode,
                Company       = x.Company,
                Division      = vd == null ? "" : vd.DivisionDesc,
                DisabledCheck = false,
                IsEnabled     = x.IsEnabled,
            };

            var queryDivision = from vd in _context.AdDivisions
                                select new OrganizationModel
            {
                OrgId         = 0,
                OrgAddonCode  = string.Format("d_{0}", vd.Division),
                OrgCode       = vd.Division,
                OrgName       = string.Format("{0} - {1}", vd.Division, vd.DivisionDesc),
                OrgParentCode = null,
                OrgGroup      = 2,
                Ord           = 1,
                HierarchyCode = "00",
                Company       = "DIV",
                Division      = vd.Division,
                DisabledCheck = true,
                IsEnabled     = true,
            };

            var data = query.Union(queryDivision).OrderBy(x => x.Ord).ThenByDescending(o => o.OrgAddonCode).AsNoTracking();

            return(Json(data));
        }