public async Task <AddEntityResponse <Vehicle> > Add(VehicleViewModel vehicle) { var( Id, Name, Model, Manufacturer, CostInCredits, Length, MaxAtmosphericSpeed, Crew, Passengers, CargoCapacity, Consumables, VehicleClass, Pilots, Films) = vehicle; var newVehicle = new Vehicle { Name = Name, Model = Model, Manufacturer = Manufacturer, CostInCredits = CostInCredits, Length = Length, MaxAtmosphericSpeed = MaxAtmosphericSpeed, Crew = Crew, Passengers = Passengers, CargoCapacity = CargoCapacity, Consumables = Consumables, VehicleClass = VehicleClass }; if (Films != null) { var vehicleFilms = Films.Select(f => new VehicleFilm { FilmId = f.Id, VehicleId = newVehicle.Id }).ToList(); newVehicle.Films = vehicleFilms; } if (Pilots != null) { var vehiclePilots = Pilots.Select(p => new VehiclePilot { VehicleId = newVehicle.Id, PeopleId = (Guid)p.Id }).ToList(); } var result = new AddEntityResponse <Vehicle> { Entity = newVehicle }; try { await _context.Vehicles.AddAsync(newVehicle); await _context.SaveChangesAsync(); result.EntitySuccessfullyAdded = true; return(result); } catch (Exception err) { _logger.LogError(err.Message); result.EntitySuccessfullyAdded = false; return(result); } }