Пример #1
0
        public IQueryable <SysUserViewModel> Paging(SysUserCriteria criteria, int page, int size, out int?rowsCount)
        {
            var users      = DataContext.Get();
            var employees  = employeeRepository.Get();
            var userLevels = userlevelRepository.Get();
            var companies  = sysCompanyRepository.Get();
            var offices    = sysCompanyRepository.Get();
            var datas      = from u in users
                             join e in employees on u.EmployeeId equals e.Id into em
                             from e in em.DefaultIfEmpty()
                             select new { u, e };

            if (criteria.All == null)
            {
                if (criteria.Active != null)
                {
                    datas = datas.Where(x => (x.u.Username ?? "").IndexOf(criteria.Username ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                        (x.e.EmployeeNameEn ?? "").IndexOf(criteria.EmployeeNameEn ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                        (x.e.EmployeeNameVn ?? "").IndexOf(criteria.EmployeeNameVn ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                        (x.u.UserType ?? "").IndexOf(criteria.UserType ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                        (x.u.Active == criteria.Active)
                                        );
                }
                else
                {
                    datas = datas.Where(x => (x.u.Username ?? "").IndexOf(criteria.Username ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                        (x.e.EmployeeNameEn ?? "").IndexOf(criteria.EmployeeNameEn ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                        (x.e.EmployeeNameVn ?? "").IndexOf(criteria.EmployeeNameVn ?? "", StringComparison.OrdinalIgnoreCase) > -1 &&
                                        (x.u.UserType ?? "").IndexOf(criteria.UserType ?? "", StringComparison.OrdinalIgnoreCase) > -1
                                        );
                }
            }
            else
            {
                if (criteria.All == "active")
                {
                    criteria.Active = true;
                }
                if (criteria.All == "inactive")
                {
                    criteria.Active = false;
                }
                if (criteria.Active == null)
                {
                    if (criteria.All == "status")
                    {
                        datas = null;
                    }
                    else
                    {
                        datas = datas.Where(x => (
                                                ((x.u.Username ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1) ||
                                                (x.e.EmployeeNameEn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                                                (x.e.EmployeeNameVn ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1 ||
                                                (x.u.UserType ?? "").IndexOf(criteria.All ?? "", StringComparison.OrdinalIgnoreCase) > -1
                                                ));
                    }
                }
                if (criteria.Active != null)
                {
                    datas = datas.Where(x => x.u.Active == criteria.Active);
                }
            }

            datas     = datas?.OrderByDescending(x => x.u.DatetimeModified);
            rowsCount = datas?.Count();
            if (size > 1)
            {
                if (page < 1)
                {
                    page = 1;
                }
                datas = datas?.Skip((page - 1) * size).Take(size);
            }
            List <SysUserViewModel> results = new List <SysUserViewModel>();

            if (datas != null)
            {
                foreach (var item in datas)
                {
                    var model = mapper.Map <SysUserViewModel>(item.u);
                    model.EmployeeNameEn = item.e?.EmployeeNameEn;
                    model.EmployeeNameVn = item.e?.EmployeeNameVn;
                    model.Title          = item.e?.Title;
                    results.Add(model);
                }
            }
            return(results.AsQueryable());
        }
Пример #2
0
        public IActionResult Get()
        {
            var response = sysCompanyService.Get();

            return(Ok(response));
        }