// GET: Movie/{name} public async Task <ActionResult> Details(string id) { var query = this._graphClient.Cypher .Match("(m:Movie)") .Where("m.title = {title}") .OptionalMatch("(m)<-[:ACTED_IN]-(a:Person)") .WithParams(new { title = id }) .Return((m, a) => new { Movie = m.As <Movie>(), Actors = a.CollectAsDistinct <Actor>() }); var model = (await query.ResultsAsync).SingleOrDefault(); if (model == null) { throw new KeyNotFoundException(); } var movie = new MovieWithActors { Movie = model.Movie, Actors = model.Actors.OrderBy(x => x.name) }; return(base.View(movie)); }
public IActionResult Post([FromBody] MovieWithActors mov) { if (mov == null) { return(BadRequest()); } else if (mov.Id == 0) { Movie newMov = new Movie { Title = mov.Title, Director = mov.Director }; _db.Movies.Add(newMov); _db.SaveChanges(); foreach (Actor actor in mov.Actors) { _db.MovieActors.Add(new MovieActor { MovieId = newMov.Id, ActorId = actor.Id }); _db.SaveChanges(); } return(Ok()); } else { //edit stuff return(BadRequest()); } }
public MovieWithActors Get(int id) { MovieWithActors mov = (from m in _db.Movies where m.Id == id select new MovieWithActors { Id = m.Id, Title = m.Title, Director = m.Director, Actors = (from ma in _db.MovieActors where ma.MovieId == m.Id select ma.Actor).ToList() }).FirstOrDefault(); return(mov); }