public async Task <SearchingDCBooking> getItem() { var list = _containerRepository.Query(true).SelectAsync(x => x.ArriveOfDespatch.DestinationPort).Result.Distinct(); List <string> status = new List <string> { ContainerStatus.Arrived.GetDescription <ContainerStatus>(), ContainerStatus.DCBookingReceived.GetDescription <ContainerStatus>() }; SearchingDCBooking searchingDCBooking = new SearchingDCBooking() { DestinationPort = list, Status = status }; return(searchingDCBooking); }
public bool checkNameContainer(string name) { var check = _containerRepository.Query(x => x.Name == name, false).SelectAsync().Result.Count(); if (check > 0) { return(true); } return(false); }
public Result GetInfoFromTransportDistance(DateTime orderD, string orderNo, int detailNo, string location1C, string location2C, string operation1C, string operation2C, DateTime transportD, string waytype) { var loc1 = _locationRepository.Query(l => l.LocationC == location1C).FirstOrDefault(); location1C = loc1 != null ? (!string.IsNullOrEmpty(loc1.AreaC) ? loc1.AreaC : location1C) : location1C; var loc2 = _locationRepository.Query(l => l.LocationC == location2C).FirstOrDefault(); location2C = loc2 != null ? (!string.IsNullOrEmpty(loc2.AreaC) ? loc2.AreaC : location2C) : location2C; if (waytype == "4") { var obj = new Result(); var checkUnitPriceMethod = _driverAllowanceRepository.Query(p => DateTime.Compare(transportD, p.ApplyD) >= 0).ToList(); var maxApplyD = checkUnitPriceMethod.Max(p => p.ApplyD); var selectResult = _driverAllowanceRepository.Query(p => p.ApplyD == maxApplyD).FirstOrDefault(); if (selectResult != null) { var oD = _orderDRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo && p.DetailNo == detailNo) .FirstOrDefault(); var transport = _transportDistanceRepository.Query(p => p.FromAreaC == location1C && p.ToAreaC == location2C).FirstOrDefault(); if (selectResult.UnitPriceMethodI == "2") { if (transport != null) { if (oD != null) { var flagup = _driverAllowanceRepository.Query(p => DateTime.Compare(transportD, p.ApplyD) >= 0 && p.UnitPriceMethodI == "2") .ToList(); var maxflagup = flagup.Max(p => p.ApplyD); var selectmaxflagup = _driverAllowanceRepository.Query(p => p.ApplyD == maxflagup && p.ContainerSize == oD.ContainerSizeI) .FirstOrDefault(); if (selectmaxflagup != null) { switch (transport.WayType) { case "0": { obj = new Result() { Km = transport.Km ?? 0, EmptyCommodity = selectmaxflagup.Empty ?? 0, UnitPrice = selectmaxflagup.ShortRoad ?? 0, WayType = transport.WayType, IsDistance = "0" }; break; } case "1": { obj = new Result() { Km = transport.Km ?? 0, EmptyCommodity = selectmaxflagup.Empty ?? 0, UnitPrice = selectmaxflagup.LongRoad ?? 0, WayType = transport.WayType, IsDistance = "0" }; break; } case "2": { obj = new Result() { Km = transport.Km ?? 0, EmptyCommodity = selectmaxflagup.Empty ?? 0, UnitPrice = selectmaxflagup.GradientRoad ?? 0, WayType = transport.WayType, IsDistance = "0" }; break; } } } else { obj = new Result() { Km = transport.Km ?? 0, EmptyCommodity = 0, UnitPrice = 0, WayType = transport.WayType, IsDistance = "0" }; } } } } else if (selectResult.UnitPriceMethodI == "0") { var oH = _orderRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo).FirstOrDefault(); if (oH != null && oD != null) { decimal?empty = 0; decimal?commodity = 0; selectResult = _driverAllowanceRepository.Query( p => p.ApplyD == maxApplyD && p.DepartureC == location1C && p.DestinationC == location2C && p.ContainerSizeI == oD.ContainerSizeI).FirstOrDefault(); if (selectResult != null) { empty = (operation1C == "LR" || operation1C == "TR" || operation2C == "LR" || operation2C == "TR") ? selectResult.EmptyGoods : 0; commodity = (operation1C != "LR" && operation1C != "TR" && operation2C != "LR" && operation2C != "TR") ? selectResult.UnitPrice : 0; obj = new Result() { Km = transport != null ? (transport.Km ?? 0) : 0, EmptyCommodity = empty ?? 0, UnitPrice = commodity ?? 0, WayType = transport != null ? (transport.WayType ?? waytype) : waytype, IsDistance = "1" }; } } } if (obj.Km == null && obj.EmptyCommodity == null && obj.UnitPrice == null && obj.WayType == null) { obj = new Result() { Km = transport != null ? (transport.Km ?? 0) : 0, EmptyCommodity = 0, UnitPrice = 0, WayType = transport != null ? (transport.WayType ?? waytype) : waytype, IsDistance = "0" }; } } return(obj); } else { var obj = new Result(); var checkUnitPriceMethod = _driverAllowanceRepository.Query(p => DateTime.Compare(transportD, p.ApplyD) >= 0).ToList(); var maxApplyD = checkUnitPriceMethod.Max(p => p.ApplyD); var selectResult = _driverAllowanceRepository.Query(p => p.ApplyD == maxApplyD).FirstOrDefault(); if (selectResult != null) { var oD = _orderDRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo && p.DetailNo == detailNo) .FirstOrDefault(); var transport = _transportDistanceRepository.Query(p => p.FromAreaC == location1C && p.ToAreaC == location2C).FirstOrDefault(); if (selectResult.UnitPriceMethodI == "2") { if (transport != null) { if (oD != null) { var flagup = _driverAllowanceRepository.Query(p => DateTime.Compare(transportD, p.ApplyD) >= 0 && p.UnitPriceMethodI == "2") .ToList(); var maxflagup = flagup.Max(p => p.ApplyD); var selectmaxflagup = _driverAllowanceRepository.Query(p => p.ApplyD == maxflagup && p.ContainerSize == oD.ContainerSizeI) .FirstOrDefault(); if (selectmaxflagup != null) { switch (waytype) { case "0": { obj = new Result() { Km = transport.Km ?? 0, EmptyCommodity = selectmaxflagup.Empty ?? 0, UnitPrice = selectmaxflagup.ShortRoad ?? 0, WayType = waytype, IsDistance = "0" }; break; } case "1": { obj = new Result() { Km = transport.Km ?? 0, EmptyCommodity = selectmaxflagup.Empty ?? 0, UnitPrice = selectmaxflagup.LongRoad ?? 0, WayType = waytype, IsDistance = "0" }; break; } case "2": { obj = new Result() { Km = transport.Km ?? 0, EmptyCommodity = selectmaxflagup.Empty ?? 0, UnitPrice = selectmaxflagup.GradientRoad ?? 0, WayType = waytype, IsDistance = "0" }; break; } } } else { obj = new Result() { Km = transport.Km ?? 0, EmptyCommodity = 0, UnitPrice = 0, WayType = waytype, IsDistance = "0" }; } } } } else if (selectResult.UnitPriceMethodI == "0") { var oH = _orderRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo).FirstOrDefault(); if (oH != null && oD != null) { decimal?empty = 0; decimal?commodity = 0; selectResult = _driverAllowanceRepository.Query( p => p.ApplyD == maxApplyD && p.DepartureC == location1C && p.DestinationC == location2C && p.ContainerSizeI == oD.ContainerSizeI).FirstOrDefault(); if (selectResult != null) { empty = (operation1C == "LR" || operation1C == "TR" || operation2C == "LR" || operation2C == "TR") ? selectResult.EmptyGoods : 0; commodity = (operation1C != "LR" && operation1C != "TR" && operation2C != "LR" && operation2C != "TR") ? selectResult.UnitPrice : 0; obj = new Result() { Km = transport != null ? (transport.Km ?? 0) : 0, EmptyCommodity = empty ?? 0, UnitPrice = commodity ?? 0, WayType = waytype, IsDistance = "1" }; } } } if (obj.Km == null && obj.EmptyCommodity == null && obj.UnitPrice == null && obj.WayType == null) { selectResult = _driverAllowanceRepository.Query(p => p.ApplyD == maxApplyD && oD.ContainerSizeI == p.ContainerSize) .FirstOrDefault(); if (selectResult != null) { switch (waytype) { case "0": { obj = new Result() { Km = transport != null ? (transport.Km ?? 0) : 0, EmptyCommodity = selectResult.Empty ?? 0, UnitPrice = selectResult.ShortRoad ?? 0, WayType = waytype, IsDistance = "0" }; break; } case "1": { obj = new Result() { Km = transport != null ? (transport.Km ?? 0) : 0, EmptyCommodity = selectResult.Empty ?? 0, UnitPrice = selectResult.LongRoad ?? 0, WayType = waytype, IsDistance = "0" }; break; } case "2": { obj = new Result() { Km = transport != null ? (transport.Km ?? 0) : 0, EmptyCommodity = selectResult.Empty ?? 0, UnitPrice = selectResult.GradientRoad ?? 0, WayType = waytype, IsDistance = "0" }; break; } } } else { obj = new Result() { Km = transport != null ? (transport.Km ?? 0) : 0, EmptyCommodity = 0, UnitPrice = 0, WayType = waytype, IsDistance = "0" }; } } } return(obj); } }
public OrderDatatable GetOrdersForTable(int page, int itemsPerPage, string sortBy, bool reverse, string orderSearchValue, string orderTypeI, DateTime?fromDate, DateTime?toDate, string custMainC, string custSubC) { var orders = _orderRepository.Query( p => (orderTypeI == "-1" || p.OrderTypeI.Equals(orderTypeI)) && (string.IsNullOrEmpty(custMainC) || (p.CustomerMainC == custMainC & p.CustomerSubC == custSubC)) ); // searching for value if (!string.IsNullOrWhiteSpace(orderSearchValue)) { orderSearchValue = orderSearchValue.ToLower(); orders = orders.Where(or => or.OrderNo.ToLower().Contains(orderSearchValue) || or.ShippingCompanyN != null && or.ShippingCompanyN.ToLower().Contains(orderSearchValue) || or.BLBK != null && or.BLBK.ToLower().Contains(orderSearchValue) || or.LoadingPlaceN != null && or.LoadingPlaceN.ToLower().Contains(orderSearchValue) || or.StopoverPlaceN != null && or.StopoverPlaceN.ToLower().Contains(orderSearchValue) || or.DischargePlaceN != null && or.DischargePlaceN.ToLower().Contains(orderSearchValue) || or.Description.ToLower().Contains(orderSearchValue) || or.JobNo != null && or.JobNo.ToLower().Contains(orderSearchValue) || or.ContractNo != null && or.ContractNo.ToLower().Contains(orderSearchValue)); } //fromDate searching if (fromDate != null) { orders = orders.Where(or => or.OrderD >= fromDate); } if (toDate != null) { orders = orders.Where(or => or.OrderD <= toDate); } // sorting (done with the System.Linq.Dynamic library available on NuGet) //customers = customers.AsQueryable().OrderBy("\"" + sortBy + (reverse ? " desc\"" : " asc\"")).AsEnumerable(); var customersOrdered = orders.OrderBy(sortBy + (reverse ? " descending" : "")); // paging var ordersPaged = customersOrdered.Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToList(); var destination = Mapper.Map <List <Order_H>, List <OrderViewModel> >(ordersPaged); if (destination.Any()) { foreach (var order in destination) { var customer = _customerRepository.Query(p => p.CustomerMainC == order.CustomerMainC && p.CustomerSubC == order.CustomerSubC) .FirstOrDefault(); if (customer != null) { order.CustomerN = customer.CustomerN; order.CustomerShortN = customer.CustomerShortN; } var customerPay = _customerRepository.Query(p => p.CustomerMainC == order.CustomerPayLiftLoweredMainC && p.CustomerSubC == order.CustomerPayLiftLoweredSubC) .FirstOrDefault(); if (customerPay != null) { order.CustomerPayLiftLoweredN = customerPay.CustomerShortN; } DateTime oD = order.OrderD; string oNo = order.OrderNo; int cont20 = (_containerRepository.Query(p => p.OrderD == oD && p.OrderNo == oNo && p.ContainerSizeI == "0").ToList().Count()); order.ContSize20 = cont20 > 0 ? cont20.ToString() : ""; int cont40 = _containerRepository.Query(p => p.OrderD == oD && p.OrderNo == oNo && p.ContainerSizeI == "1").ToList().Count(); order.ContSize40 = cont40 > 0 ? cont40.ToString() : ""; int cont45 = _containerRepository.Query(p => p.OrderD == oD && p.OrderNo == oNo && p.ContainerSizeI == "2").ToList().Count(); order.ContSize45 = cont45 > 0 ? cont45.ToString() : ""; var oDLoad = _containerRepository.Query(p => p.OrderD == oD && p.OrderNo == oNo && p.ContainerSizeI == "3" && p.GrossWeight != null && p.GrossWeight > 0).ToList(); int contload = oDLoad.Count(); decimal?weight = oDLoad.Sum(p => p.GrossWeight); order.ContSizeLoad = contload > 0 ? (contload.ToString() + (weight > 0 ? ("(" + weight.Value.ToString("#,###.#") + ")") : "")) : ""; } } var orderDatatable = new OrderDatatable() { Data = destination, Total = orders.Count() }; return(orderDatatable); }