public void SaveOrder(OrderViewModel order) { var newOrder = OrderViewModel.ToOrder(order); if (newOrder.Genus == null) { newOrder.Genus = u_repo.GetGenus(newOrder.GenusId); } if (newOrder.Location == null && newOrder.LocationId.HasValue) { newOrder.Location = u_repo.GetLocation(newOrder.LocationId.Value); } if (newOrder.Location != null && newOrder.Location.PrimaryContactId.HasValue) { newOrder.Grower = u_repo.GetGrower(newOrder.Location.PrimaryContactId.Value); } else if (newOrder.Grower == null) { newOrder.Grower = u_repo.GetGrower(newOrder.GrowerId); } u_repo.SaveOrder(newOrder); var newOrderVm = OrderViewModel.Create(newOrder); newOrderVm.CopyTo(order); }