Example #1
0
        public VesselDatatables GetVesselForTable(int page, int itemsPerPage, string sortBy, bool reverse, string vesselSearchValue)
        {
            var vessel = from a in _vesselRepository.GetAllQueryable()
                         join b in _shippingCompanyRepository.GetAllQueryable() on a.ShippingCompanyC
                         equals b.ShippingCompanyC
                         where ((!string.IsNullOrEmpty(vesselSearchValue) &&
                                 (a.VesselC.ToLower().Contains(vesselSearchValue) ||
                                  a.VesselN.ToLower().Contains(vesselSearchValue) ||
                                  b.ShippingCompanyN.ToLower().Contains(vesselSearchValue))
                                 ) ||
                                (string.IsNullOrEmpty(vesselSearchValue) && 1 == 1)
                                )
                         select new VesselViewModel()
            {
                VesselC          = a.VesselC,
                VesselN          = a.VesselN,
                ShippingCompanyC = a.ShippingCompanyC,
                ShippingCompanyN = b.ShippingCompanyN,
                IsActive         = a.IsActive,
            };

            var vesselOrdered = vessel.OrderBy(sortBy + (reverse ? " descending" : ""));
            // paging
            var vesselPaged = vesselOrdered.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToList();

            // set final result
            var vesselDatatable = new VesselDatatables()
            {
                Data  = vesselPaged,
                Total = vessel.Count()
            };

            return(vesselDatatable);
        }
Example #2
0
        public OrderPatternDatatable GetOrderPatternsForTable(int page, int itemsPerPage, string sortBy, bool reverse, string searchValue)
        {
            //var orderpatterns = _orderPatternRepository.GetAllQueryable().Join();
            List <OrderPatternViewModel> result;

            var orderpatterns = (from p in _orderPatternRepository.GetAllQueryable()
                                 join sc in _shippingCompanyRepository.GetAllQueryable() on p.ShippingCompanyC equals sc.ShippingCompanyC into psc
                                 from sc in psc.DefaultIfEmpty()
                                 join c in _customerRepository.GetAllQueryable() on p.CustomerMainC equals c.CustomerMainC //and p.CustomerSubC equals c.CustomerSub
                                 join ve in _vesselRepository.GetAllQueryable() on p.VesselC equals ve.VesselC into pve
                                 from ve in pve.DefaultIfEmpty()
                                 join sh in _shipperRepository.GetAllQueryable() on p.ShipperC equals sh.ShipperC into psh
                                 from sh in psh.DefaultIfEmpty()
                                 join l1 in _locationRepository.GetAllQueryable() on p.LoadingPlaceC equals l1.LocationC into pl1
                                 from l1 in pl1.DefaultIfEmpty()
                                 join l2 in _locationRepository.GetAllQueryable() on p.StopoverPlaceC equals l2.LocationC into pl2
                                 from l2 in pl2.DefaultIfEmpty()
                                 join l3 in _locationRepository.GetAllQueryable() on p.DischargePlaceC equals l3.LocationC into pl3
                                 from l3 in pl3.DefaultIfEmpty()
                                 join cont in _containerTypeRepository.GetAllQueryable() on p.ContainerTypeC equals cont.ContainerTypeC into cont1
                                 from cont in cont1.DefaultIfEmpty()
                                 where p.CustomerSubC == c.CustomerSubC
                                 select new OrderPatternViewModel
            {
                CustomerMainC = p.CustomerMainC,
                CustomerSubC = p.CustomerSubC,
                CustomerN = c.CustomerN,
                OrderPatternC = p.OrderPatternC,
                OrderPatternN = p.OrderPatternN,
                OrderTypeI = p.OrderTypeI,
                ShippingCompanyC = p.ShippingCompanyC,
                ShippingCompanyN = sc.ShippingCompanyN,
                VesselC = p.VesselC,
                VesselN = ve.VesselN,
                ShipperC = p.ShipperC,
                ShipperN = sh.ShipperN,
                LoadingPlaceC = p.LoadingPlaceC,
                LoadingPlaceN = l1.LocationN,
                StopoverPlaceC = p.StopoverPlaceC,
                StopoverPlaceN = l2.LocationN,
                DischargePlaceC = p.DischargePlaceC,
                DischargePlaceN = l3.LocationN,
                ContainerSizeI = p.ContainerSizeI,
                ContainerTypeN = cont.ContainerTypeN,
                CommodityN = p.CommodityN,
                UnitPrice = p.UnitPrice,
                CalculateByTon = p.CalculateByTon
            }).AsQueryable();

            // searching
            if (!string.IsNullOrWhiteSpace(searchValue))
            {
                searchValue   = searchValue.ToLower();
                orderpatterns = orderpatterns.Where(i => i.OrderPatternC.ToLower().Contains(searchValue) ||
                                                    (i.CustomerN != null && i.CustomerN.ToLower().Contains(searchValue)) ||
                                                    (i.ShippingCompanyN != null && i.ShippingCompanyN.ToLower().Contains(searchValue)) ||
                                                    (i.ShipperN != null && i.ShipperN.ToLower().Contains(searchValue)) ||
                                                    (i.LoadingPlaceN != null && i.LoadingPlaceN.ToLower().Contains(searchValue)) ||
                                                    (i.StopoverPlaceN != null && i.StopoverPlaceN.ToLower().Contains(searchValue)) ||
                                                    (i.DischargePlaceN != null && i.DischargePlaceN.ToLower().Contains(searchValue)));
            }

            // sorting, paging
            result = orderpatterns.OrderBy(sortBy + (reverse ? " descending" : ""))
                     .Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToList();

            //var destination = Mapper.Map<List<OrderPattern_M>, List<OrderPatternViewModel>>(patternsPaged);
            var datatable = new OrderPatternDatatable()
            {
                Data  = result,
                Total = orderpatterns.Count()
            };

            return(datatable);
        }