/// <summary> /// convert container to view model /// </summary> /// <param name="container"></param> /// <returns></returns> public ContainerViewModel ConvertToView(Container container) { ContainerViewModel model = new ContainerViewModel(); var _containerRepository = new ContainerRepository(); var containerParts = _containerRepository.GetContainerParts().Where(x => x.ContainerId == container.ContainerId).ToList(); model.ContainerId = container.ContainerId; model.BillOfLadingId = container.BillOfLadingId; model.ContainerNumber = (!string.IsNullOrEmpty(container.Number)) ? container.Number : "N/A"; if (containerParts != null && containerParts.Count > 0) { model.ContainerParts = new List <ContainerPartViewModel>(); foreach (var containerPart in containerParts) { ContainerPartViewModel convertedModel = new ContainerPartConverter().ConvertToView(containerPart); model.ContainerParts.Add(convertedModel); } } if (_containerRepository != null) { _containerRepository.Dispose(); _containerRepository = null; } return(model); }