public SelectedPickListDTO GetPickListById(int id) { var justOne = db.Picklists.FirstOrDefault(q => q.PicklistId == id); var plantsForPicklist = justOne.PlantsForPicklists.Select(item => new PickListDetailDTO { PlantForPicklistId = item.PlantForPickListId, PicklistId = item.PlantForPickListId, PlantForQuoteId = item.PlantForQuoteId, BatchId = item.BatchId, Location = db.Batches.Any(x => x.Id == item.BatchId && x.Active == true) ? db.Batches.SingleOrDefault(x => x.Id == item.BatchId).Location : "No Location", PlantName = item.PlantName, FormSize = item.FormSize, QuantityToPick = item.QuantityToPick, QuantityPicked = item.QuantityPicked, IsSubbed = item.IsSubbed, DispatchLocation = item.DispatchLocation, Active = item.Active, }); var dto = new DTO.SelectedPickListDTO { PicklistId = justOne.PicklistId, QuoteId = justOne.QuoteId, DispatchDate = justOne.DispatchDate.ToString(), DeliveryAddress = justOne.DeliveryAddress, DeliveryNeeded = justOne.DeliveryNeeded, CustomerRef = db.CustomerInformations.FirstOrDefault(x => x.CustomerReference == db.Quotes.FirstOrDefault(z => z.QuoteId == justOne.QuoteId).CustomerReference).CustomerReference ?? "No Customer Ref", CustomerTel = db.CustomerInformations.FirstOrDefault(x => x.CustomerReference == db.Quotes.FirstOrDefault(z => z.QuoteId == justOne.QuoteId).CustomerReference).CustomerTel ?? "No Customer Tel", IsPicked = justOne.IsPicked, IsAllocated = justOne.IsAllocated, IsDelivered = justOne.IsDelivered, Active = justOne.Active, Comment = justOne.Comment, EstimatedDelivery = justOne.EstimatedDelivery, //Boolean because its either Estimated Or Exact Delivery Date PickListItemQty = db.PlantsForPicklists.Where(x => x.PicklistId == justOne.PicklistId).Sum(x => x.QuantityToPick), TotalAmountPicked = db.PlantsForPicklists.Where(x => x.PicklistId == justOne.PicklistId).Sum(x => x.QuantityPicked), PickListPlants = plantsForPicklist, }; return(dto); }
public SelectedPickListDTO GetPickListById(int id) { var justOne = db.Picklists.SingleOrDefault(q => q.PicklistId == id); var plantsForPicklist = justOne.PlantsForPicklists.Select(item => new PickListDetailDTO { PlantForPicklistId = item.PlantForPickListId, PicklistId = item.PlantForPickListId, PlantForQuoteId = item.PlantForQuoteId, PlantName = item.PlantName, FormSize = item.FormSize, QuantityToPick = item.QuantityToPick, SubbedFor = item.SubbedFor, IsSubbed = item.isSubbed, DispatchLocation = item.DispatchLocation, Active = item.Active, }); var dto = new DTO.SelectedPickListDTO { PicklistId = justOne.PicklistId, QuoteId = justOne.QuoteId, DipatchDate = justOne.DispatchDate, DeliveryAddress = justOne.DeliveryAddress, DeliveryNeeded = justOne.DeliveryNeeded, IsPicked = justOne.IsPicked, IsPacked = justOne.IsPacked, IsDelivered = justOne.IsDelivered, Active = justOne.Active, Comment = justOne.Comment, EsimatedDelivery = justOne.EstimatedDelivery, //Boolean because its either Estimated Or Exact Delivery Date PickListPlants = plantsForPicklist, }; return(dto); }