private void PopulateConsignmentItemViewModel(JobItemDetailsViewModel jiViewmodel) { var pendingItem = _jobItemService.GetPendingConsignmentItem(jiViewmodel.Id); if (pendingItem == null) { var item = _jobItemService.GetLatestConsignmentItem(jiViewmodel.Id); if (item != null) { if (item.Consignment != null) { jiViewmodel.Consignment = new ConsignmentIndexViewModel() { Id = item.Consignment.Id, ConsignmentNo = item.Consignment.ConsignmentNo, CreatedBy = item.Consignment.CreatedBy.Name, DateCreated = item.Consignment.DateCreated.ToLongDateString() + ' ' + item.Consignment.DateCreated.ToShortTimeString(), SupplierName = item.Consignment.Supplier.Name, IsOrdered = item.Consignment.IsOrdered }; return; } jiViewmodel.ConsignmentItem = new ConsignmentItemIndexViewModel() { Id = item.Id, Instructions = item.Instructions, SupplierName = item.Consignment.Supplier.Name, IsOrdered = item.Consignment.IsOrdered }; return; } else { return; } } else { jiViewmodel.ConsignmentItem = new ConsignmentItemIndexViewModel() { Id = pendingItem.Id, Instructions = pendingItem.Instructions, SupplierName = pendingItem.Supplier.Name }; return; } }
public ActionResult Details(Guid Id) { var jobItem = _jobItemService.GetById(Id); var viewModel = new JobItemDetailsViewModel { Id = jobItem.Id, JobId = jobItem.Job.Id, UserRole = GetLoggedInUserRoles(), Accessories = jobItem.Accessories, AssetNo = jobItem.AssetNo, CalPeriod = jobItem.CalPeriod, Field = jobItem.Field.Name, Status = jobItem.Status.Name, SerialNo = jobItem.SerialNo, Comments = jobItem.Comments, Instructions = jobItem.Instructions, IsReturned = jobItem.IsReturned, ReturnReason = jobItem.ReturnReason, IsInvoiced = jobItem.IsInvoiced, IsMarkedForInvoicing = jobItem.IsMarkedForInvoicing, QuoteItem = PopulateQuoteItemViewModel(jobItem.Id), Delivery = PopulateDeliveryItemViewModel(jobItem.Id), Certificates = PopulateCertificateViewModel(jobItem.Id), InstrumentDetails = jobItem.Instrument.ToString(), WorkItems = jobItem.HistoryItems.Select(wi => new WorkItemDetailsViewModel { Id = wi.Id, JobItemId = wi.JobItem.Id, OverTime = wi.OverTime, Report = wi.Report, Status = wi.Status.Name.ToString(), WorkTime = wi.WorkTime, WorkType = wi.WorkType.Name.ToString(), WorkBy = wi.User.Name, DateCreated = wi.DateCreated.ToLongDateString() + ' ' + wi.DateCreated.ToShortTimeString() }).OrderByDescending(wi => wi.DateCreated).ToList() }; PopulateOrderItemViewModel(viewModel); var pendingItem = _jobItemService.GetPendingConsignmentItem(Id); if (pendingItem == null) { var item = _jobItemService.GetLatestConsignmentItem(Id); if (item != null) { if (item.Consignment != null) { viewModel.Consignment = new ConsignmentIndexViewModel { Id = item.Consignment.Id, ConsignmentNo = item.Consignment.ConsignmentNo, CreatedBy = item.Consignment.CreatedBy.Name, DateCreated = item.Consignment.DateCreated.ToLongDateString() + ' ' + item.Consignment.DateCreated.ToShortTimeString(), SupplierName = item.Consignment.Supplier.Name, IsOrdered = item.Consignment.IsOrdered }; } else { viewModel.ConsignmentItem = new ConsignmentItemIndexViewModel { Id = item.Id, Instructions = item.Instructions, SupplierName = item.Consignment.Supplier.Name, IsOrdered = item.Consignment.IsOrdered }; } } else { viewModel.ConsignmentItem = null; } } else { viewModel.ConsignmentItem = new ConsignmentItemIndexViewModel() { Id = pendingItem.Id, Instructions = pendingItem.Instructions, SupplierName = pendingItem.Supplier.Name }; } return(PartialView("_Details", viewModel)); }