public async Task <IActionResult> GetPagedBusOrder([FromQuery] BusOrderParams busOrderParams)
        {
            var userId    = getUserId();
            var busOrders = await busOrderRepository.GetPagedBusOrder(busOrderParams, userId);

            var result = mapper.Map <IEnumerable <ViewBusOrderResource> >(busOrders);

            Response.AddPagination(busOrders.CurrentPage, busOrders.PageSize, busOrders.TotalCount, busOrders.TotalPages);

            return(Ok(result));
        }
Exemple #2
0
        public async Task <IActionResult> GetBusOrderReport([FromQuery] BusOrderParams busOrderParams)
        {
            var busOrder = await busOrderRepository.GetPagedBusOrder(busOrderParams);

            var departments = await departmentRepository.GetAll();

            var bustime = await busTimeRepository.GetAll();

            var dormitoryblock = await dormitoryBlockRepository.GetAll();

            var busOrderResult       = mapper.Map <IEnumerable <ViewBusOrderResource> >(busOrder);
            var departmentResult     = mapper.Map <IEnumerable <ViewDepartmentResource> >(departments);
            var bustimeResult        = mapper.Map <IEnumerable <ViewBusTimeResource> >(bustime);
            var dormitoryblockResult = mapper.Map <IEnumerable <ViewDormitoryBlockResource> >(dormitoryblock);

            object[] direction = new object[3];
            direction[0] = new Direction {
                id = 1, name = "Dormitory to Alcon 204"
            };
            direction[1] = new Direction {
                id = 2, name = "Alcon 204 to Dormitory"
            };
            direction[2] = new Direction {
                id = 3, name = "Night Bus"
            };

            return(Ok(new
            {
                busOrderResult,
                departmentResult,
                bustimeResult,
                direction,
                dormitoryblockResult
            }
                      ));
        }
        public async Task <PagedList <BusOrder> > GetPagedBusOrder(BusOrderParams busOrderParams, int?userId = null)
        {
            var busOrders = context.BusOrder.Include(b => b.BusOrderDetails).AsQueryable();

            if (userId != null)
            {
                var user = context.User.FirstOrDefault(u => u.Id == userId);
                if (user.AdminStatus != true)
                {
                    busOrders = busOrders.Where(bo => bo.UserId == userId);
                }
            }

            if (DateTime.Compare(busOrderParams.StartDate, new DateTime(01, 1, 1)) != 0 && DateTime.Compare(busOrderParams.EndDate, new DateTime(01, 1, 1)) != 0)
            {
                busOrders = busOrders.Where(m => m.OrderEntryDate.Date >= busOrderParams.StartDate.Date && m.OrderEntryDate.Date <= busOrderParams.EndDate.Date);
            }

            if (DateTime.Compare(busOrderParams.OrderEntryDate, new DateTime(01, 1, 1)) != 0)
            {
                busOrders = busOrders.Where(b => b.OrderEntryDate.Date == busOrderParams.OrderEntryDate.Date);
            }

            if (busOrderParams.isReadyToCollect == true)
            {
                busOrders = busOrders.Where(b => b.IsReadyToCollect == true);
            }

            // FIXME : seharusnya bukan departmentId tetapi departementcode atau departmentName

            if (busOrderParams.DepartmentId > 0)
            {
                busOrders = busOrders.Where(b => b.DepartmentId == busOrderParams.DepartmentId);
            }

            if (busOrderParams.DormitoryBlockId > 0)
            {
                busOrders = busOrders.Where(b => b.DormitoryBlockId == busOrderParams.DormitoryBlockId);
            }

            // TODO  : Filter by Status ? Locked, Closed --> sebaiknya Locked dihilangkan, dan diganti dgn Open

            // Sort
            if (busOrderParams.isDescending)
            {
                if (!string.IsNullOrEmpty(busOrderParams.OrderBy))
                {
                    switch (busOrderParams.OrderBy.ToLower())
                    {
                    case "orderentrydate":
                        busOrders = busOrders.OrderByDescending(b => b.OrderEntryDate);
                        break;

                    // FIXME : seharusnya bukan departmentId tetapi departementcode atau departmentName , kecuali di FE pakai combobox
                    case "departmentid":
                        busOrders = busOrders.OrderByDescending(b => b.DepartmentId);
                        break;
                    // FIXME : seharusnya bukan BlockId tetapi dormitoryBlockcname, kecuali di FE pakai combobox

                    case "dormitoryblockid":
                        busOrders = busOrders.OrderByDescending(b => b.DormitoryBlockId);
                        break;

                    default:
                        busOrders = busOrders.OrderByDescending(b => b.OrderEntryDate);
                        break;
                        // TODO  : Filter by Status ? Locked, Closed --> sebaiknya Locked dihilangkan, dan diganti dgn Open
                    }
                }
                else
                {
                    busOrders = busOrders.OrderByDescending(b => b.OrderEntryDate);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(busOrderParams.OrderBy))
                {
                    switch (busOrderParams.OrderBy.ToLower())
                    {
                    case "orderentrydate":
                        busOrders = busOrders.OrderBy(b => b.OrderEntryDate);
                        break;

                    // FIXME : seharusnya bukan departmentId tetapi departementcode atau departmentName , kecuali di FE pakai combobox
                    case "departmentid":
                        busOrders = busOrders.OrderBy(b => b.DepartmentId);
                        break;
                    // FIXME : seharusnya bukan BlockId tetapi dormitoryBlockcname, kecuali di FE pakai combobox

                    case "dormitoryblockid":
                        busOrders = busOrders.OrderBy(b => b.DormitoryBlockId);
                        break;

                    default:
                        busOrders = busOrders.OrderBy(b => b.OrderEntryDate);
                        break;
                        // TODO  : Filter by Status ? Locked, Closed --> sebaiknya Locked dihilangkan, dan diganti dgn Open
                    }
                }
                else
                {
                    busOrders = busOrders.OrderBy(b => b.OrderEntryDate);
                }
            }

            var busOrderToReturn = busOrders.Include(b => b.BusOrderDetails);

            return(await PagedList <BusOrder> .CreateAsync(busOrderToReturn, busOrderParams.PageNumber, busOrderParams.PageSize));
        }