Example #1
0
        public object JTable([FromBody] JTableModelOrganizationCustom jTablePara)
        {
            ////_logger.LogInformation(LoggingEvents.LogDb, "Get list Organization");
            //_actionLog.InsertActionLog("VIB_ORGANIZATION", "Get list Organization", null, null, "JTable");
            int intBeginFor = (jTablePara.CurrentPage - 1) * jTablePara.Length;
            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 (jTablePara.TypeOrganizationId == null || x.OrgGroup == jTablePara.TypeOrganizationId) &&
                              (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       = x.OrgName,
                OrgParentCode = x.Division == null ? null : string.Format("d_{0}", x.Division),
                OrgGroup      = x.OrgGroup,
                Ord           = x.Company == "HO" ? 2 : x.Company == "DIV" ? 3 : x.Company == "BRA" ? 4 : 5,
                Company       = x.Company,
                Division      = vd == null ? "" : vd.DivisionDesc,
                DisabledCheck = false,
            };

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

            var data             = query.Union(queryDivision).OrderBy(x => x.Ord).AsNoTracking();
            var listOrganization = data as IList <OrganizationModel> ?? data.ToList();

            var result = new List <OrganizationModel>();

            foreach (var ognzt in listOrganization.Where(x => x.OrgParentCode == null))
            {
                var listChild = GetOrganizationChild(listOrganization, ognzt.OrgAddonCode, ". . . ");

                var organization = new OrganizationModel();
                organization.OrgId         = ognzt.OrgId;
                organization.OrgAddonCode  = ognzt.OrgAddonCode;
                organization.OrgCode       = ognzt.OrgCode;
                organization.OrgName       = (listChild.Count > 0 ? "<i class='fa fa-folder-open font-green-sharp'></i> " : "<i class='fa fa-folder text-info'></i> ") + ognzt.OrgName;
                organization.OrgGroup      = ognzt.OrgGroup;
                organization.Ord           = ognzt.Ord;
                organization.OrgParentCode = ognzt.OrgParentCode;
                organization.Company       = ognzt.Company;
                organization.Division      = ognzt.Division;
                organization.DisabledCheck = ognzt.DisabledCheck;
                result.Add(organization);

                if (listChild.Count > 0)
                {
                    result = result.Concat(listChild).ToList();
                }
            }
            var count = result.Count();
            var res   = result.Skip(intBeginFor).Take(jTablePara.Length).ToList();
            var jdata = JTableHelper.JObjectTable(res, jTablePara.Draw, count, "OrgId", "OrgAddonCode", "OrgCode", "OrgName", "OrgParentCode", "Ord", "Company", "Division");

            return(Json(jdata));
        }
Example #2
0
        public async Task <IActionResult> GetAllBranch([FromBody] SearchBranchModel search)
        {
            if (search.OnlySelected)
            {
                var listRef = new List <string>();
                //var user = await _context.Users.Include(i => i.Branch).FirstOrDefaultAsync(x => x.Id == search.UserId);
                //if (user != null && !string.IsNullOrEmpty(user.OrgReference))
                //{
                //    listRef = user.OrgReference.Split(',').ToList();
                //}
                var userInGroup = await _context.AdUserInGroups.FirstOrDefaultAsync(x => x.ApplicationCode == search.AppCode && x.UserId == search.UserId);

                if (!string.IsNullOrEmpty(userInGroup?.BranchReference))
                {
                    listRef = userInGroup.BranchReference.Split(',').ToList();
                }

                return(Json(listRef));
            }
            else
            {
                var listRef = new List <string>();
                var user    = await _context.Users.Include(i => i.Branch).FirstOrDefaultAsync(x => x.Id == search.UserId);

                if (user != null && !string.IsNullOrEmpty(user.OrgReference))
                {
                    listRef = user.OrgReference.Split(',').ToList();
                }

                //var data = _context.VIBOrganizations
                //                   .Where(x => x.OrgGroup.HasValue && x.OrgGroup.Value == 2)//&& (string.IsNullOrEmpty(search.Name) || x.OrgCode.ToLower().Contains(search.Name) || x.OrgName.ToLower().Contains(search.Name)))
                //                                                                            //.OrderBy(x => x.OrgName)
                //                   .Select(x => new
                //                   {
                //                       OrgAddonCode = x.OrgAddonCode,
                //                       OrgCode = x.OrgCode,
                //                       OrgName = x.OrgName,
                //                       BranchName = string.Format("{0} - {1}", x.OrgCode, x.OrgName),
                //                       IsChecked = listRef.Any(y => y == x.OrgAddonCode)
                //                   });

                var allBranch = new OrganizationModel
                {
                    OrgId         = 0,
                    OrgAddonCode  = "b_000",
                    OrgCode       = "b_000",
                    OrgName       = "All Branch",
                    OrgParentCode = null,
                    OrgGroup      = 4,
                    Ord           = 0,
                    Company       = "HO",
                    Division      = null,
                    DisabledCheck = false,
                    IsMain        = false,
                };

                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 && x.IsEnabled)
                            //&& (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,
                    Company       = x.Company,
                    Division      = vd == null ? "" : vd.DivisionDesc,
                    DisabledCheck = false,
                    IsMain        = false,
                };

                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 = "b_000",
                    OrgGroup      = 2,
                    Ord           = 1,
                    Company       = "DIV",
                    Division      = vd.Division,
                    DisabledCheck = true,
                    IsMain        = false,
                };

                var data = query.Union(queryDivision).OrderBy(x => x.Ord).ThenBy(o => o.OrgAddonCode).AsNoTracking().ToList();
                data.Insert(0, allBranch);

                var result = data.Select(x => new
                {
                    OrgAddonCode  = x.OrgAddonCode,
                    OrgCode       = x.OrgCode,
                    OrgName       = x.OrgName,
                    OrgParentCode = x.OrgParentCode,
                    Ord           = x.Ord,
                    DisabledCheck = x.DisabledCheck,
                    IsMain        = x.IsMain,
                    IsChecked     = listRef.Any(y => y == x.OrgAddonCode) || (listRef.Count > 0 && listRef[0] == "b_000")
                }).ToList();

                return(Json(result));
            }
        }