public async Task <IHttpActionResult> Post(CustomerPricingSearchParams search)
        {
            var datatable = await Task.Run(() => _customerPricingService.GetCustomerPricingForTable(search));

            if (datatable == null)
            {
                return(NotFound());
            }
            return(Ok(datatable));
        }
Exemplo n.º 2
0
        public CustomerPricingDataTable GetCustomerPricingForTable(CustomerPricingSearchParams search)
        {
            var pricing = (from l in _customerPricingRepository.GetAllQueryable()
                           join c in _customerRepository.GetAllQueryable() on new { l.CustomerMainC, l.CustomerSubC } equals new { c.CustomerMainC, c.CustomerSubC }
                           into t1
                           from c in t1.DefaultIfEmpty()
                           join l1 in _locationRepository.GetAllQueryable() on l.Location1C equals l1.LocationC
                           join l2 in _locationRepository.GetAllQueryable() on l.Location2C equals l2.LocationC
                           join o in _containerTypeRepository.GetAllQueryable() on l.ContainerTypeC equals o.ContainerTypeC
                           where ((search.CustomerMainC == "" || l.CustomerMainC.Equals(search.CustomerMainC)) &&
                                  (search.CustomerSubC == "" || l.CustomerSubC.Equals(search.CustomerSubC)) &&
                                  (search.ContainerSizeI == "" || l.ContainerSizeI.Equals(search.ContainerSizeI)) &&
                                  (search.ContainerTypeC == "" || l.ContainerTypeC.Equals(search.ContainerTypeC)) &&
                                  (search.Location1C == "" || l.Location1C.Equals(search.Location1C)) &&
                                  (search.Location2C == "" || l.Location2C.Equals(search.Location2C)))
                           select new CustomerPricingViewModel()
            {
                CustomerPricingId = l.CustomerPricingId,
                CustomerMainC = l.CustomerMainC,
                CustomerSubC = l.CustomerSubC,
                CustomerN = c.CustomerN,
                ContainerSizeI = l.ContainerSizeI,
                ContainerTypeC = l.ContainerTypeC,
                ContainerTypeN = o.ContainerTypeN,
                Location1C = l.Location1C,
                Location1N = l1.LocationN,
                Location2C = l.Location2C,
                Location2N = l2.LocationN,
                TotalExpense = l.TotalExpense,
                EstimatedPrice = l.EstimatedPrice,
                EstimatedD = l.EstimatedD,
            })
                          .OrderBy(search.SortBy + (search.Reverse ? " descending" : ""))
                          .Skip((search.Page - 1) * search.ItemsPerPage).Take(search.ItemsPerPage)
                          .ToList();

            var datatable = new CustomerPricingDataTable()
            {
                Data  = pricing,
                Total = _customerPricingRepository.GetAllQueryable().Count()
            };

            return(datatable);
        }