public async Task <IActionResult> Add([FromBody] SpecieResponseViewModel specie) { var(Name, Classification, Designation, AverageHeight, SkinColors, EyeColors, HairColors, AverageLifespan, Homeworld, Language, People, Films) = specie; var newSpecie = new Specie { Name = Name, Classification = Classification, Designation = Designation, AverageHeight = AverageHeight, SkinColors = SkinColors, EyeColors = EyeColors, HairColors = HairColors, AverageLifespan = AverageLifespan, Language = Language }; if (Homeworld != null) { var specieHomeworld = new Planet { Id = Homeworld.Id }; _context.Planets.Attach(specieHomeworld); newSpecie.Homeworld = specieHomeworld; } ; if (Films != null) { var specieFilms = Films.Select(f => new FilmSpecie { FilmId = f.Id, SpecieId = newSpecie.Id }).ToList(); newSpecie.Films = specieFilms; } var specieAdded = await _speciesRepository.Add(newSpecie); if (specieAdded) { return(RedirectToAction(nameof(Get), new { Id = newSpecie.Id })); } return(Ok(new { status = "error", data = "error adding specie" })); }