public IActionResult AllOrderIndividualInfo(int id) { List <DeliveryVM> deliveryVMs = new List <DeliveryVM>(); var detailsfromDelivery = deliveryService.AllOrderListforIndividualInfofromDelivery(id); var detailsfromOrder = orderService.AllOrderListforIndividualInfofromOrder(id); if (detailsfromDelivery.Count != 0) { var pass1 = from a in detailsfromDelivery group a by a.Order.CustomerId into b let c = (from d in b select new { orderId = d.OrderId, deliveryId = d.DeliveryId, hiddenPkId = d.Order.HiddenPKId, customerId = b.Key, customerName = d.Order.Customer.CustomerName, district = d.Order.Customer.District, subdistrict = d.Order.Customer.SubDistrict, area = d.Order.Customer.Area, roadNo = d.Order.Customer.RoadNo, houseNo = d.Order.Customer.HouseNo, contact = d.Order.Customer.ContactNo, shippingId = d.Order.ShippingId, shipping = d.Order.Shipping.ShippingMethod, payementId = d.Order.PaymentId, payement = d.Order.Payment.PaymentMethod, productId = d.Order.ProductInventoryId, product = d.Order.ProductInventory.Name, quantity = d.Order.Quantity, totalPrice = d.Order.ProductInventory.SellPrice, status = d.Status, orderPlacedDate = d.Order.OrderDate, orderDeliveredDate = d.DeliveredDate, complaintDescription = d.ComplaintDescription }) select c; ProductInventory_VM productInventory_VM = new ProductInventory_VM(); List <ProductInventoryVM> productInventoryVMs = new List <ProductInventoryVM>(); foreach (var item in pass1) { var deliveryVM = new DeliveryVM(); foreach (var i in item) { ProductInventoryVM productInventoryVM = new ProductInventoryVM(); productInventoryVM.NameVM = i.product; productInventoryVM.QuantityVM = i.quantity; productInventoryVM.EachPriceVM = i.totalPrice * i.quantity; deliveryVM.TotalPriceVM += productInventoryVM.EachPriceVM; productInventoryVM.StatusVM = i.status; deliveryVM.OrderVMId = i.orderId; deliveryVM.HiddenPKVMId = i.hiddenPkId; deliveryVM.CustomerVMId = i.customerId; deliveryVM.CustomerVMName = i.customerName; deliveryVM.CustomerVMArea = i.area; deliveryVM.CustomerVMDistrict = i.district; deliveryVM.CustomerVMSubDistrict = i.subdistrict; deliveryVM.CustomerVMHouseNo = i.houseNo; deliveryVM.CustomerVMRoadNo = i.roadNo; deliveryVM.CustomerVMContactNo = i.contact; deliveryVM.ShippingVMId = i.shippingId; deliveryVM.ShippingVMMethod = i.shipping; deliveryVM.PaymentVMId = i.payementId; deliveryVM.PaymentVMMethod = i.payement; deliveryVM.ProductVMId = i.productId; deliveryVM.OrderPlacedVMDate = i.orderPlacedDate; deliveryVM.DeliveredVMDate = i.orderDeliveredDate; deliveryVM.productInventory_VM.productInventoryVMs.Add(productInventoryVM); } deliveryVMs.Add(deliveryVM); } } else if (detailsfromOrder.Count != 0) { var pass2 = from a in detailsfromOrder group a by a.CustomerId into b let c = (from d in b select new { orderId = d.OrderId, // deliveryId = d.DeliveryId, hiddenPkId = d.HiddenPKId, customerId = b.Key, customerName = d.Customer.CustomerName, district = d.Customer.District, subdistrict = d.Customer.SubDistrict, area = d.Customer.Area, roadNo = d.Customer.RoadNo, houseNo = d.Customer.HouseNo, contact = d.Customer.ContactNo, shippingId = d.ShippingId, shipping = d.Shipping.ShippingMethod, payementId = d.PaymentId, payement = d.Payment.PaymentMethod, productId = d.ProductInventoryId, product = d.ProductInventory.Name, quantity = d.Quantity, totalPrice = d.ProductInventory.SellPrice, status = d.Status, orderPlacedDate = d.OrderDate, //orderDeliveredDate = default(DateTime ?), }) select c; ProductInventory_VM productInventory_VM = new ProductInventory_VM(); List <ProductInventoryVM> productInventoryVMs = new List <ProductInventoryVM>(); foreach (var item in pass2) { var deliveryVM = new DeliveryVM(); foreach (var i in item) { ProductInventoryVM productInventoryVM = new ProductInventoryVM(); //DateTime date1 = new DateTime(1855, 1, 1, 0, 0, 0, 0); productInventoryVM.NameVM = i.product; productInventoryVM.QuantityVM = i.quantity; productInventoryVM.EachPriceVM = i.totalPrice * i.quantity; deliveryVM.TotalPriceVM += productInventoryVM.EachPriceVM; productInventoryVM.StatusVM = i.status; deliveryVM.OrderVMId = i.orderId; deliveryVM.HiddenPKVMId = i.hiddenPkId; deliveryVM.CustomerVMId = i.customerId; deliveryVM.CustomerVMName = i.customerName; deliveryVM.CustomerVMArea = i.area; deliveryVM.CustomerVMDistrict = i.district; deliveryVM.CustomerVMSubDistrict = i.subdistrict; deliveryVM.CustomerVMHouseNo = i.houseNo; deliveryVM.CustomerVMRoadNo = i.roadNo; deliveryVM.CustomerVMContactNo = i.contact; deliveryVM.ShippingVMId = i.shippingId; deliveryVM.ShippingVMMethod = i.shipping; deliveryVM.PaymentVMId = i.payementId; deliveryVM.PaymentVMMethod = i.payement; deliveryVM.ProductVMId = i.productId; deliveryVM.OrderPlacedVMDate = i.orderPlacedDate; deliveryVM.DeliveredVMDate = new DateTime(1900, 1, 1, 0, 0, 0, 0); deliveryVM.productInventory_VM.productInventoryVMs.Add(productInventoryVM); } deliveryVMs.Add(deliveryVM); } } return(View(deliveryVMs)); }