Beispiel #1
0
        private IQueryable <api_rent> IQApiRent(List <SortingInfo> sortings = null, FilterInfo filters = null)
        {
            //kamus
            IQueryable <api_rent> list = context.api_rent;
            string     dateParam       = null;
            FilterInfo copyFilters     = null;

            //algoritma
            if (filters != null)
            {
                copyFilters = filters.Clone();
            }

            if (copyFilters != null && (copyFilters.Field != null || copyFilters.Filters != null))
            {
                copyFilters.FormatFieldToUnderscore();

                GridHelper.ProcessFilters <api_rent>(copyFilters, ref list);
            }

            if (sortings != null && sortings.Count > 0)
            {
                foreach (var s in sortings)
                {
                    s.FormatSortOnToUnderscore();
                    list = list.OrderBy <api_rent>(s.SortOn + " " + s.SortOrder);
                }
            }
            else
            {
                list = list.OrderBy <api_rent>("id desc"); //default, wajib ada atau EF error
            }

            return(list);
        }
Beispiel #2
0
        private IQueryable <rent_position> IQRentPos(List <SortingInfo> sortings = null, FilterInfo filters = null)
        {
            //kamus
            IQueryable <rent_position> list = context.rent_position;
            string     dateParam            = null;
            FilterInfo copyFilters          = null;

            //algoritma
            if (filters != null)
            {
                copyFilters = filters.Clone();
            }

            if (copyFilters != null)
            {
                copyFilters.FormatFieldToUnderscore();

                dateParam = copyFilters.RemoveFilterField("filter_date");

                GridHelper.ProcessFilters <rent_position>(copyFilters, ref list);
            }

            //menangani date filter
            if (dateParam != null)
            {
                DateTime dt = DateTime.Parse(dateParam);
                dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
                DateTimeOffset dto = dt;

                int diffHours = TimeZoneInfo.Local.BaseUtcOffset.Hours;
                int minutes   = diffHours * 60;


                //list = list.Where(m =>
                //    dto >= DbFunctions.TruncateTime(DbFunctions.AddMinutes(m.start_rent, minutes)) &&
                //    DbFunctions.TruncateTime(DbFunctions.AddMinutes(m.finish_rent, minutes)) >= dto);
            }

            if (sortings != null && sortings.Count > 0)
            {
                foreach (var s in sortings)
                {
                    s.FormatSortOnToUnderscore();
                    list = list.OrderBy <rent_position>(s.SortOn + " " + s.SortOrder);
                }
            }
            else
            {
                list = list.OrderBy <rent_position>("id desc"); //default, wajib ada atau EF error
            }

            return(list);
        }
Beispiel #3
0
        private IQueryable <User> IQUser(List <SortingInfo> sortings = null, FilterInfo filters = null)
        {
            //kamus
            IQueryable <User> list        = context.Users;
            FilterInfo        copyFilters = null;
            string            sort        = "";
            List <string>     sortArr     = new List <string>();

            //algoritma
            if (filters != null)
            {
                copyFilters = filters.Clone();
            }

            if (copyFilters != null && (copyFilters.Field != null || copyFilters.Filters != null))
            {
                // copyFilters.FormatFieldToUnderscore();

                GridHelper.ProcessFilters <User>(copyFilters, ref list);
            }


            if (sortings != null && sortings.Count > 0)
            {
                foreach (var s in sortings)
                {
                    // s.FormatSortOnToUnderscore();
                    sortArr.Add(s.SortOn + " " + s.SortOrder);
                }

                sort = string.Join(",", sortArr);
                list = list.OrderBy <User>(sort);
            }
            else
            {
                list = list.OrderBy <User>("UserId desc"); //default, wajib ada atau EF error
            }

            return(list);
        }
Beispiel #4
0
        /// <summary>
        /// ada kemungkinan penanganan datetime with offset disamakan dengan fungsi find all yang 1 lagi
        /// filter khusus
        ///     filter_date: mengambil data rent dengan start <= filter_date <= end
        ///     without_invoice: mengambil data rent yang belum memiliki invoice
        ///     include_id: mengambil data rent dengan id = ...
        /// </summary>
        /// <param name="sortings"></param>
        /// <param name="filters"></param>
        /// <returns></returns>
        private IQueryable <rent> IQRent(List <SortingInfo> sortings = null, FilterInfo filters = null)
        {
            //kamus
            IQueryable <rent> list                = context.rents;
            string            dateParam           = null;
            string            withoutInvoiceParam = null;
            string            withoutExpenseParam = null;
            string            idParam             = null;
            FilterInfo        copyFilters         = null;

            //algoritma
            if (filters != null)
            {
                copyFilters = filters.Clone();
            }

            if (copyFilters != null && (copyFilters.Field != null || copyFilters.Filters != null))
            {
                copyFilters.FormatFieldToUnderscore();

                dateParam           = copyFilters.RemoveFilterField("filter_date");
                withoutInvoiceParam = copyFilters.RemoveFilterField("without_invoice");
                withoutExpenseParam = copyFilters.RemoveFilterField("without_expense");
                idParam             = copyFilters.RemoveFilterField("include_id");

                GridHelper.ProcessFilters <rent>(copyFilters, ref list);
            }

            //menangani date filter
            if (dateParam != null)
            {
                DateTime dt = DateTime.Parse(dateParam);
                dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
                DateTimeOffset dto = dt;

                int diffHours = TimeZoneInfo.Local.BaseUtcOffset.Hours;
                int minutes   = diffHours * 60;

                list = list.Where(m =>
                                  dto >= DbFunctions.TruncateTime(DbFunctions.AddMinutes(m.start_rent, minutes)) &&
                                  DbFunctions.TruncateTime(DbFunctions.AddMinutes(m.finish_rent, minutes)) >= dto);
            }

            //menangani without invoice
            if (withoutInvoiceParam != null)
            {
                if (idParam == null)
                {
                    list = list.Where(m => m.invoices.Count() == 0);
                }
                else
                {
                    list = list.Where(m => m.id == new Guid(idParam) || m.invoices.Count() == 0);
                }
            }

            //menangani without expense
            if (withoutExpenseParam != null)
            {
                if (idParam == null)
                {
                    list = list.Where(m => m.expenses.Count() == 0);
                }
                else
                {
                    list = list.Where(m => m.id == new Guid(idParam) || m.expenses.Count() == 0);
                }
            }

            if (sortings != null && sortings.Count > 0)
            {
                foreach (var s in sortings)
                {
                    s.FormatSortOnToUnderscore();
                    list = list.OrderBy <rent>(s.SortOn + " " + s.SortOrder);
                }
            }
            else
            {
                list = list.OrderBy <rent>("id desc"); //default, wajib ada atau EF error
            }

            return(list);
        }