Exemple #1
0
        public async Task <IActionResult> GetBusVerificationReport([FromQuery] BusOrderVerificationParams busVerificationParams)
        {
            var busVerification = await busOrderVerificationRepository.GetPagedBusOrderVerification(busVerificationParams);

            var bustime = await busTimeRepository.GetAll();

            var dormitoryblock = await dormitoryBlockRepository.GetAll();

            var busVerificationResult = mapper.Map <IEnumerable <ViewBusOrderVerificationResource> >(busVerification);
            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
            {
                busVerificationResult,
                bustimeResult,
                direction,
                dormitoryblockResult
            }
                      ));
        }
        public async Task <IActionResult> GetPagedBusOrderVerification([FromQuery] BusOrderVerificationParams busOrderVerificationParams)
        {
            var busOrderVerifications = await busOrderVerificationRepository.GetPagedBusOrderVerification(busOrderVerificationParams);

            var result = mapper.Map <IEnumerable <ViewBusOrderVerificationResource> >(busOrderVerifications);

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

            return(Ok(result));
        }
        public async Task <PagedList <BusOrderVerification> > GetPagedBusOrderVerification(BusOrderVerificationParams busOrderVerificationParams)
        {
            var busOrderVerifications = context.BusOrderVerification
                                        .Include(b => b.BusOrderVerificationDetails)
                                        .AsQueryable();

            // auth by user
            if (!string.IsNullOrEmpty(busOrderVerificationParams.OrderNo))
            {
                busOrderVerifications = busOrderVerifications.Where(b => b.OrderNo.Contains(busOrderVerificationParams.OrderNo, StringComparison.OrdinalIgnoreCase));
            }

            if (DateTime.Compare(busOrderVerificationParams.OrderDate, new DateTime(01, 1, 1)) != 0)
            {
                busOrderVerifications = busOrderVerifications.Where(b => b.Orderdate.Date == busOrderVerificationParams.OrderDate.Date);
            }

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

            if (!string.IsNullOrEmpty(busOrderVerificationParams.OrderStatus))
            {
                switch (busOrderVerificationParams.OrderStatus.ToLower())
                {
                //            case "locked":
                //                break;
                case "closed":
                    busOrderVerifications = busOrderVerifications.Where(b => b.IsClosed == true);
                    break;

                default:
                    break;
                }
            }

            // Sort
            if (busOrderVerificationParams.isDescending)
            {
                if (!string.IsNullOrEmpty(busOrderVerificationParams.OrderBy))
                {
                    switch (busOrderVerificationParams.OrderBy.ToLower())
                    {
                    case "orderno":
                        busOrderVerifications = busOrderVerifications.OrderByDescending(b => b.OrderNo);
                        break;

                    case "orderdate":
                        busOrderVerifications = busOrderVerifications.OrderByDescending(b => b.Orderdate);
                        break;

                    //            case "orderstatus":
                    //              busOrderVerifications = busOrderVerifications.OrderBy(b => b.OrderStatus);
                    // TODO - order status adalah string, harus handle isClosed,isLocked -> ambil dari helper
                    default:
                        busOrderVerifications = busOrderVerifications.OrderByDescending(b => b.Orderdate);
                        break;
                    }
                }
                else
                {
                    busOrderVerifications = busOrderVerifications.OrderByDescending(b => b.Orderdate);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(busOrderVerificationParams.OrderBy))
                {
                    switch (busOrderVerificationParams.OrderBy.ToLower())
                    {
                    case "orderno":
                        busOrderVerifications = busOrderVerifications.OrderBy(b => b.OrderNo);
                        break;

                    case "orderdate":
                        busOrderVerifications = busOrderVerifications.OrderBy(b => b.Orderdate);
                        break;

                    //            case "orderstatus":
                    //              busOrderVerifications = busOrderVerifications.OrderBy(b => b.OrderStatus);
                    // TODO - order status adalah string, harus handle isClosed,isLocked -> ambil dari helper
                    // sebaiknya isLocked dihilangkan, diganti dgn Open, dicegah waktu save saja jika sudah locked
                    //              break;
                    default:
                        busOrderVerifications = busOrderVerifications.OrderBy(b => b.Orderdate);
                        break;
                    }
                }
                else
                {
                    busOrderVerifications = busOrderVerifications.OrderBy(b => b.Orderdate);
                }
            }
            var busOrderVerificationToReturn = busOrderVerifications.Include(b => b.BusOrderVerificationDetails);

            return(await PagedList <BusOrderVerification> .CreateAsync(busOrderVerificationToReturn, busOrderVerificationParams.PageNumber, busOrderVerificationParams.PageSize));
        }