Exemple #1
0
        public object QrPayment(BranchesDateRangeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Response.RenderError(ModelState));
            }

            List <DailyRevenueReconcileQrPayment> dailyRevenueReconcile = DB.DailyRevenueReconcileQrPayment
                                                                          .FromSql(
                "EXEC sp_PDC_Report_DailyRevenueReconcileQrPayment_Get {0}, {1}, {2}, {3}, {4}",
                model.DateFrom.ToShortDateString(),
                model.DateTo.ToShortDateString(),
                JsonConvert.SerializeObject(model.BranchIdList),
                model.Page,
                model.PerPage
                ).ToList();

            Response.Success    = true;
            Response.Result     = dailyRevenueReconcile;
            Response.ResultInfo = new
            {
                page       = model.Page,
                perPage    = model.PerPage,
                count      = dailyRevenueReconcile.Count(),
                totalCount = DB.DailyRevenue.Join(DB.Branch, d => d.BranchId, b => b.BranchId, (d, b) => new { d = d })
                             .Where(
                    x => model.BranchIdList.Contains(x.d.BranchId) && x.d.ReportDate >= model.DateFrom && x.d.ReportDate <= model.DateTo
                    ).Count()
            };

            DB.Dispose();

            return(Response.Render());
        }
        public async Task <object> Get([FromBody] BranchesDateRangeViewModel model)
        {
            IQueryable <DailyRevenue> queryable = DB.DailyRevenue.AsQueryable();

            var orderBy = model.OrderBy;

            if (model.Branches != null && model.Branches.Count() > 0)
            {
                queryable = queryable.Where(x => model.Branches.Contains(x.BranchId));
            }

            if (QueryHelper.PropertyExists <DailyRevenue>(orderBy))
            {
                if (model.OrderDirection.Equals("desc"))
                {
                    queryable = queryable.OrderByPropertyDescending(orderBy);
                }
                else
                {
                    queryable = queryable.OrderByProperty(orderBy);
                }
            }

            //var dbSetx = dbSet.Join(DB.Branch, d => d.BranchId, b => b.BranchId, (d, b) => new {
            //    b.ErpId,
            //    d
            //});

            PaginatedList <object> dailyRevenues = await PaginatedList <object> .CreateAsync(queryable.AsNoTracking(), model.Page, model.PerPage);

            return(new {
                dailyRevenues.CurrentPage,
                Data = dailyRevenues.ToList(),
                dailyRevenues.From,
                dailyRevenues.To,
                dailyRevenues.PerPage,
                dailyRevenues.TotalPages,
                dailyRevenues.Total
            });
        }