public static void CreateLazyLoad()
 {
     if (_lazyLoad == null)
     {
         _lazyLoad = new LazyLoadViewModel();
     }
 }
        public IActionResult GetWithLazyLoad([FromBody] LazyLoadViewModel LazyLoad)
        {
            // Relate

            // Filter
            var filters = string.IsNullOrEmpty(LazyLoad.Filter) ? new string[] { "" }
                    : LazyLoad.Filter.ToLower().Split(null);

            Expression <Func <TblTrainingLevel, bool> > condition = e =>
                                                                    filters.Any(x => (e.TrainingLevel + e.Detail).ToLower().Contains(x));
            // Order
            Expression <Func <TblTrainingLevel, string> > Order     = null;
            Expression <Func <TblTrainingLevel, string> > OrderDesc = null;

            switch (LazyLoad.SortField)
            {
            case "TrainingLevelId":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingLevelId.ToString("00");
                }
                else
                {
                    Order = e => e.TrainingLevelId.ToString("00");
                }
                break;

            case "TrainingLevel":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingLevel;
                }
                else
                {
                    Order = e => e.TrainingLevel;
                }
                break;

            case "Detail":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.Detail;
                }
                else
                {
                    Order = e => e.Detail;
                }
                break;

            default:
                Order = e => e.TrainingLevelId.ToString("00");
                break;
            }

            return(new JsonResult(new
            {
                Data = this.repository.FindAllWithLazyLoadAsync(condition, null, LazyLoad.First ?? 0, LazyLoad.Rows ?? 25, Order, OrderDesc).Result,
                TotalRow = this.repository.CountWithMatch(condition)
            }, this.DefaultJsonSettings));
        }
        public async Task <IActionResult> GetWithLazyLoad([FromBody] LazyLoadViewModel LazyLoad)
        {
            var Query = this.repository.GetAllAsQueryable();
            // Filter
            var filters = string.IsNullOrEmpty(LazyLoad.Filter) ? new string[] { "" }
                                : LazyLoad.Filter.ToLower().Split(null);

            foreach (var keyword in filters)
            {
                Query = Query.Where(x => x.GroupCode.ToLower().Contains(keyword) ||
                                    x.GroupDesc.ToLower().Contains(keyword) ||
                                    x.GroupRemark.ToLower().Contains(keyword) ||
                                    x.GroupEdesc.ToLower().Contains(keyword));
            }

            // Order
            switch (LazyLoad.SortField)
            {
            case "GroupCode":
                if (LazyLoad.SortOrder == -1)
                {
                    Query = Query.OrderByDescending(e => e.GroupCode);
                }
                else
                {
                    Query = Query.OrderBy(e => e.GroupCode);
                }
                break;

            case "GroupDesc":
                if (LazyLoad.SortOrder == -1)
                {
                    Query = Query.OrderByDescending(e => e.GroupDesc);
                }
                else
                {
                    Query = Query.OrderBy(e => e.GroupDesc);
                }
                break;

            default:
                Query = Query.OrderBy(e => e.GroupCode);
                break;
            }
            int count = Query.Count();

            // Skip and Take
            Query = Query.Skip(LazyLoad.First ?? 0).Take(LazyLoad.Rows ?? 25);
            // Get Data
            return(new JsonResult(new
            {
                Data = await Query.AsNoTracking().ToListAsync(),
                TotalRow = count
            }, this.DefaultJsonSettings));
        }
        public IActionResult GetWithLazyLoad2([FromBody] LazyLoadViewModel LazyLoad)
        {
            var hasData = this.repositoryEmployee.GetEmployeeWithLazy(LazyLoad);

            if (hasData != null)
            {
                return(new JsonResult(new
                {
                    Data = hasData.Item1,
                    TotalRow = hasData.Item2
                }, this.DefaultJsonSettings));
            }
            else
            {
                return(NotFound(new { Error = "employee not found " }));
            }
        }
        public Tuple <IEnumerable <EmployeeLazyViewModel2>, int> GetEmployeeWithLazy(LazyLoadViewModel LazyLoad)
        {
            try
            {
                if (LazyLoad != null)
                {
                    var Query = this.Context.TblEmployee
                                .Include(x => x.GroupCodeNavigation)
                                .Include(x => x.SectionCodeNavigation)
                                .Include(x => x.Locate).AsQueryable();

                    string filter   = "";
                    string location = "";

                    if (LazyLoad.Filter.IndexOf("|") > -1)
                    {
                        var splie = LazyLoad.Filter.Split('|');
                        filter   = splie.Length > 0 ? splie[0] : LazyLoad.Filter;
                        location = splie.Length > 1 ? splie[1] : "";
                    }
                    else
                    {
                        filter = LazyLoad.Filter;
                    }

                    //var filters = string.IsNullOrEmpty(filter) ? new string[] { "" }
                    //        : filter.ToLower().Split(null);

                    if (string.IsNullOrEmpty(location))
                    {
                        // Too Slow
                        //Query = Query.Where(e => filters.Any(x => (e.NameThai + e.NameEng +
                        //                        e.NickName + e.EmpCard +
                        //                        e.EmpCode + e.GroupCodeNavigation.GroupDesc +
                        //                        e.SectionCodeNavigation.SectionName).ToLower().Contains(x)));

                        foreach (var keyword in filter.Trim().ToLower().Split(null))
                        {
                            Query = Query.Where(e => e.NameThai.ToLower().Contains(keyword) || e.NameEng.ToLower().Contains(keyword) ||
                                                e.NickName.ToLower().Contains(keyword) || e.EmpCard.ToLower().Contains(keyword) ||
                                                e.EmpCode.ToLower().Contains(keyword) || e.GroupCodeNavigation.GroupDesc.ToLower().Contains(keyword) ||
                                                e.SectionCodeNavigation.SectionName.ToLower().Contains(keyword));
                        }
                    }
                    else
                    {
                        Query = Query.Where(e => e.LocateId == location);
                        foreach (var keyword in filter.Trim().ToLower().Split(null))
                        {
                            Query = Query.Where(e => e.NameThai.ToLower().Contains(keyword) || e.NameEng.ToLower().Contains(keyword) ||
                                                e.NickName.ToLower().Contains(keyword) || e.EmpCard.ToLower().Contains(keyword) ||
                                                e.EmpCode.ToLower().Contains(keyword) || e.GroupCodeNavigation.GroupDesc.ToLower().Contains(keyword) ||
                                                e.SectionCodeNavigation.SectionName.ToLower().Contains(keyword));
                        }
                    }

                    switch (LazyLoad.SortField)
                    {
                    case "EmpCode":
                        if (LazyLoad.SortOrder == -1)
                        {
                            Query = Query.OrderByDescending(x => x.EmpCode.Length).ThenByDescending(x => x.EmpCode);
                        }
                        else
                        {
                            Query = Query.OrderBy(x => x.EmpCode.Length).ThenBy(x => x.EmpCode);
                        }
                        break;

                    case "NameThai":
                        if (LazyLoad.SortOrder == -1)
                        {
                            Query = Query.OrderByDescending(x => x.NameThai);
                        }
                        else
                        {
                            Query = Query.OrderBy(x => x.NameThai);
                        }
                        break;

                    case "SectionString":
                        if (LazyLoad.SortOrder == -1)
                        {
                            Query = Query.OrderByDescending(x => x.SectionCodeNavigation.SectionName);
                        }
                        else
                        {
                            Query = Query.OrderBy(x => x.SectionCodeNavigation.SectionName);
                        }
                        break;

                    case "GroupString":
                        if (LazyLoad.SortOrder == -1)
                        {
                            Query = Query.OrderByDescending(x => x.GroupCodeNavigation.GroupDesc);
                        }
                        else
                        {
                            Query = Query.OrderBy(x => x.GroupCodeNavigation.GroupDesc);
                        }
                        break;

                    default:
                        Query = Query.OrderByDescending(x => x.EmpCode.Length).ThenByDescending(x => x.EmpCode);
                        break;
                    }

                    int TotalRow = Query.Count();
                    Query = Query.Skip(LazyLoad.First ?? 0).Take(LazyLoad.Rows ?? 25);

                    return(new Tuple <IEnumerable <EmployeeLazyViewModel2>, int>
                           (
                               Query.AsEnumerable <TblEmployee>().Select(x => new EmployeeLazyViewModel2()
                    {
                        EmpCode = x.EmpCode,
                        NameThai = x.NameThai,
                        GroupString = x.GroupCodeNavigation.GroupDesc,
                        SectionString = x.SectionCodeNavigation.SectionName,
                    }).AsEnumerable(), TotalRow
                           ));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Has error {ex.ToString()}");
            }
            return(null);
        }
        public IActionResult GetWithLazyLoad([FromBody] LazyLoadViewModel LazyLoad)
        {
            // Relate
            // Expression<Func<TblEmployee, object>> depRelate = a => a.DeptCodeNavigation;
            Expression <Func <TblEmployee, object> > secRelate = s => s.SectionCodeNavigation;
            //Expression<Func<TblEmployee, object>> divRelate = d => d.DivisionCodeNavigation;
            Expression <Func <TblEmployee, object> > groRelate = g => g.GroupCodeNavigation;
            //Expression<Func<TblEmployee, object>> typRelate = t => t.EmptypeCodeNavigation;
            //Expression<Func<TblEmployee, object>> locRelate = l => l.Locate;
            //groRelate, typRelate, depRelate, locRelate

            var relates = new List <Expression <Func <TblEmployee, object> > >
            {
                groRelate, secRelate
            };
            // Filter
            Expression <Func <TblEmployee, bool> > condition = null;
            string filter   = "";
            string location = "";

            if (LazyLoad.Filter.IndexOf("|") > -1)
            {
                var splie = LazyLoad.Filter.Split('|');
                filter   = splie.Length > 0 ? splie[0] : LazyLoad.Filter;
                location = splie.Length > 1 ? splie[1] : "";
            }
            else
            {
                filter = LazyLoad.Filter;
            }

            var filters = string.IsNullOrEmpty(filter) ? new string[] { "" }
                    : filter.ToLower().Split(null);

            if (string.IsNullOrEmpty(location))
            {
                condition = e =>
                            filters.Any(x => (e.NameThai + e.NameEng +
                                              e.NickName + e.EmpCard +
                                              e.EmpCode + e.GroupCodeNavigation.GroupDesc +
                                              e.SectionCodeNavigation.SectionName).ToLower().Contains(x));
            }
            else
            {
                condition = e => e.LocateId == location &&
                            filters.Any(x => (e.NameThai + e.NameEng +
                                              e.NickName + e.EmpCard +
                                              e.EmpCode + e.GroupCodeNavigation.GroupDesc +
                                              e.SectionCodeNavigation.SectionName).ToLower().Contains(x));
            }


            // Order
            Expression <Func <TblEmployee, string> > Order     = null;
            Expression <Func <TblEmployee, string> > OrderDesc = null;

            switch (LazyLoad.SortField)
            {
            case "EmpCode":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.EmpCode;
                }
                else
                {
                    Order = e => e.EmpCode;
                }
                break;

            case "NameThai":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.NameThai;
                }
                else
                {
                    Order = e => e.NameThai;
                }
                break;

            case "SectionString":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.SectionCodeNavigation.SectionName;
                }
                else
                {
                    Order = e => e.SectionCodeNavigation.SectionName;
                }
                break;

            case "GroupString":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.GroupCodeNavigation.GroupDesc;
                }
                else
                {
                    Order = e => e.GroupCodeNavigation.GroupDesc;
                }
                break;

            default:
                OrderDesc = e => e.EmpCode;
                break;
            }

            var Data = new List <EmployeeLazyViewModel>();

            this.repository.FindAllWithLazyLoadAsync(condition, relates, LazyLoad.First ?? 0, LazyLoad.Rows ?? 25,
                                                     Order, OrderDesc).Result.ToList().ForEach(item => Data.Add(new EmployeeLazyViewModel(item)));
            //this.ConverterTableToViewModel<EmployeeViewModel, TblEmployee>(this.repository.FindAllWithLazyLoadAsync(condition, relates, LazyLoad.First ?? 0, LazyLoad.Rows ?? 25,
            // Order, OrderDesc).Result)

            //var hasData = this.repository.FindAllWithLazyLoadAsync(condition, relates, LazyLoad.First ?? 0, LazyLoad.Rows ?? 25,
            //            Order, OrderDesc).Result;

            return(new JsonResult(new
            {
                Data = Data,
                TotalRow = this.repository.CountWithMatch(condition)
            }, this.DefaultJsonSettings));
        }
        public IActionResult GetWithLazyLoad2([FromBody] LazyLoadViewModel LazyLoad)
        {
            // Relate
            Expression <Func <TblTrainingCousre, object> > typeRelate  = t => t.TrainingType;
            Expression <Func <TblTrainingCousre, object> > levelRelate = l => l.TrainingLevel;
            Expression <Func <TblTrainingCousre, object> > eduRelate   = e => e.EducationRequirement;
            var relates = new List <Expression <Func <TblTrainingCousre, object> > >
            {
                typeRelate, levelRelate, eduRelate
            };
            // Filter
            var filters = string.IsNullOrEmpty(LazyLoad.Filter) ? new string[] { "" }
                    : LazyLoad.Filter.ToLower().Split(null);

            Expression <Func <TblTrainingCousre, bool> > condition = e =>
                                                                     filters.Any(x => (e.Detail + e.EducationRequirement.EducationName +
                                                                                       e.Remark + e.TrainingCousreCode + e.TrainingCousreName +
                                                                                       e.TrainingLevel.TrainingLevel + e.TrainingType.TrainingTypeName).ToLower().Contains(x));
            // Order
            Expression <Func <TblTrainingCousre, string> > Order     = null;
            Expression <Func <TblTrainingCousre, string> > OrderDesc = null;

            switch (LazyLoad.SortField)
            {
            case "TrainingCousreCode":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingCousreCode;
                }
                else
                {
                    Order = e => e.TrainingCousreCode;
                }
                break;

            case "TrainingCousreName":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingCousreName;
                }
                else
                {
                    Order = e => e.TrainingCousreName;
                }
                break;

            case "TrainingLevelString":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingLevel.TrainingLevel;
                }
                else
                {
                    Order = e => e.TrainingLevel.TrainingLevel;
                }
                break;

            case "EducationRequirementString":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.EducationRequirement.EducationName;
                }
                else
                {
                    Order = e => e.EducationRequirement.EducationName;
                }
                break;

            case "TrainingTypeString":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingType.TrainingTypeName;
                }
                else
                {
                    Order = e => e.TrainingType.TrainingTypeName;
                }
                break;

            default:
                Order = e => e.TrainingCousreCode;
                break;
            }

            return(new JsonResult(new
            {
                Data = this.ConverterTableToViewModel <TrainingCourseViewModel, TblTrainingCousre>(
                    this.repository.FindAllWithLazyLoadAsync(condition, relates, LazyLoad.First ?? 0, LazyLoad.Rows ?? 25,
                                                             Order, OrderDesc).Result),
                TotalRow = this.repository.CountWithMatch(condition)
            }, this.DefaultJsonSettings));
        }
        public async Task <IActionResult> GetWithLazyLoad([FromBody] LazyLoadViewModel LazyLoad)
        {
            string ErrorMessage = "";

            try
            {
                var Query = this.repository.GetAllAsQueryable()
                            .Include(x => x.TrainingType)
                            .Include(x => x.TrainingLevel)
                            .Include(x => x.EducationRequirement)
                            .AsNoTracking()
                            .AsQueryable();

                // Filter
                var filters = string.IsNullOrEmpty(LazyLoad.Filter) ? new string[] { "" }
                                    : LazyLoad.Filter.ToLower().Split(null);

                foreach (var keyword in filters)
                {
                    Query = Query.Where(x => x.Detail.ToLower().Contains(keyword) ||
                                        x.EducationRequirement.EducationName.ToLower().Contains(keyword) ||
                                        x.Remark.ToLower().Contains(keyword) ||
                                        x.TrainingCousreCode.ToLower().Contains(keyword) ||
                                        x.TrainingCousreName.ToLower().Contains(keyword) ||
                                        x.TrainingLevel.TrainingLevel.ToLower().Contains(keyword) ||
                                        x.TrainingType.TrainingTypeName.ToLower().Contains(keyword));
                }

                // Order
                switch (LazyLoad.SortField)
                {
                case "TrainingCousreCode":
                    if (LazyLoad.SortOrder == -1)
                    {
                        Query = Query.OrderByDescending(e => e.TrainingCousreCode);
                    }
                    else
                    {
                        Query = Query.OrderBy(e => e.TrainingCousreCode);
                    }
                    break;

                case "TrainingCousreName":
                    if (LazyLoad.SortOrder == -1)
                    {
                        Query = Query.OrderByDescending(e => e.TrainingCousreName);
                    }
                    else
                    {
                        Query = Query.OrderBy(e => e.TrainingCousreName);
                    }
                    break;

                case "TrainingLevelString":
                    if (LazyLoad.SortOrder == -1)
                    {
                        Query = Query.OrderByDescending(e => e.TrainingLevel.TrainingLevel);
                    }
                    else
                    {
                        Query = Query.OrderBy(e => e.TrainingLevel.TrainingLevel);
                    }
                    break;

                case "EducationRequirementString":
                    if (LazyLoad.SortOrder == -1)
                    {
                        Query = Query.OrderByDescending(e => e.EducationRequirement.EducationName);
                    }
                    else
                    {
                        Query = Query.OrderBy(e => e.EducationRequirement.EducationName);
                    }
                    break;

                case "TrainingTypeString":
                    if (LazyLoad.SortOrder == -1)
                    {
                        Query = Query.OrderByDescending(e => e.TrainingType.TrainingTypeName);
                    }
                    else
                    {
                        Query = Query.OrderBy(e => e.TrainingType.TrainingTypeName);
                    }
                    break;

                default:
                    Query = Query.OrderByDescending(e => e.TrainingCousreCode);
                    break;
                }
                int count = Query.Count();
                // Skip and Take
                Query = Query.Skip(LazyLoad.First ?? 0).Take(LazyLoad.Rows ?? 25);

                return(new JsonResult(new
                {
                    Data = this.ConverterTableToViewModel <TrainingCourseViewModel, TblTrainingCousre>(await Query.AsNoTracking().ToListAsync()),
                    TotalRow = count
                }, this.DefaultJsonSettings));
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.ToString();
            }

            return(new JsonResult(ErrorMessage, this.DefaultJsonSettings));
        }
Пример #9
0
        private void dowloadTopTitlesAppBarBtn_Click(object sender, System.EventArgs e)
        {
            LazyLoadViewModel vm = this.DataContext as LazyLoadViewModel;

            vm.DownloadNetflixTopTitles();
        }
Пример #10
0
 public static void ClearLazyLoad()
 {
     _lazyLoad.Cleanup();
     _lazyLoad = null;
 }
Пример #11
0
        public IActionResult GetWithLazyLoad([FromBody] LazyLoadViewModel LazyLoad)
        {
            // Relate
            // Filter
            var filters = string.IsNullOrEmpty(LazyLoad.Filter) ? new string[] { "" }
                    : LazyLoad.Filter.ToLower().Split(null);

            Expression <Func <TblTrainingMaster, bool> > condition = e =>
                                                                     filters.Any(x => (e.Detail + e.TrainingCode +
                                                                                       e.Remark + e.TrainingName + e.LecturerName).ToLower().Contains(x));
            // Order
            Expression <Func <TblTrainingMaster, string> > Order     = null;
            Expression <Func <TblTrainingMaster, string> > OrderDesc = null;

            switch (LazyLoad.SortField)
            {
            case "TrainingCode":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingCode;
                }
                else
                {
                    Order = e => e.TrainingCode;
                }
                break;

            case "TrainingName":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingName;
                }
                else
                {
                    Order = e => e.TrainingName;
                }
                break;

            case "TrainingDate":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.TrainingDate.ToString();
                }
                else
                {
                    Order = e => e.TrainingDate.ToString();
                }
                break;

            case "LecturerName":
                if (LazyLoad.SortOrder == -1)
                {
                    OrderDesc = e => e.LecturerName;
                }
                else
                {
                    Order = e => e.LecturerName;
                }
                break;

            default:
                OrderDesc = e => e.TrainingDate.ToString();
                break;
            }

            return(new JsonResult(new
            {
                Data = this.ConverterTableToViewModel <TrainingMasterViewModel, TblTrainingMaster>(this.repository.FindAllWithLazyLoadAsync(condition, null, LazyLoad.First ?? 0, LazyLoad.Rows ?? 25,
                                                                                                                                            Order, OrderDesc).Result),
                TotalRow = this.repository.CountWithMatch(condition)
            }, this.DefaultJsonSettings));
        }
Пример #12
0
        public async Task <IActionResult> GetWithLazyLoadV2([FromBody] LazyLoadViewModel LazyLoad)
        {
            var Query = this.repository.GetAllAsQueryable();
            // Filter
            var filters = string.IsNullOrEmpty(LazyLoad.Filter) ? new string[] { "" }
                                : LazyLoad.Filter.ToLower().Split(null);

            foreach (var keyword in filters)
            {
                Query = Query.Where(x => x.Detail.ToLower().Contains(keyword) ||
                                    x.TrainingCode.ToLower().Contains(keyword) ||
                                    x.Remark.ToLower().Contains(keyword) ||
                                    x.TrainingName.ToLower().Contains(keyword) ||
                                    x.LecturerName.ToLower().Contains(keyword));
            }

            // Order
            switch (LazyLoad.SortField)
            {
            case "TrainingCode":
                if (LazyLoad.SortOrder == -1)
                {
                    Query = Query.OrderByDescending(e => e.TrainingCode);
                }
                else
                {
                    Query = Query.OrderBy(e => e.TrainingCode);
                }
                break;

            case "TrainingName":
                if (LazyLoad.SortOrder == -1)
                {
                    Query = Query.OrderByDescending(e => e.TrainingName);
                }
                else
                {
                    Query = Query.OrderBy(e => e.TrainingName);
                }
                break;

            case "TrainingDateString":
                if (LazyLoad.SortOrder == -1)
                {
                    Query = Query.OrderByDescending(e => e.TrainingDate);
                }
                else
                {
                    Query = Query.OrderBy(e => e.TrainingDate);
                }
                break;

            case "LecturerName":
                if (LazyLoad.SortOrder == -1)
                {
                    Query = Query.OrderByDescending(e => e.LecturerName);
                }
                else
                {
                    Query = Query.OrderBy(e => e.LecturerName);
                }
                break;

            default:
                Query = Query.OrderByDescending(e => e.TrainingDate);
                break;
            }
            int count = Query.Count();

            // Skip and Take
            Query = Query.Skip(LazyLoad.First ?? 0).Take(LazyLoad.Rows ?? 25);

            //this.ConverterTableToViewModel<TrainingMasterViewModel, TblTrainingMaster>(await Query.AsNoTracking().ToListAsync());
            // Get Data
            return(new JsonResult(new
            {
                Data = this.ConverterTableToViewModel
                       <TrainingMasterViewModel, TblTrainingMaster>
                           (await Query.AsNoTracking().ToListAsync()),//await Query.AsNoTracking().ToListAsync(),
                TotalRow = count
            }, this.DefaultJsonSettings));
        }