public async Task <IActionResult> PutShowtimeGroupAsync(int id, [FromBody] ShowtimeGroup UpdatedGroup) { if (id != UpdatedGroup.ShowtimeGroupID) { return(BadRequest()); } Dictionary <string, string> errors = UpdatedGroup.Validate(_context); if (errors.Count == 0) { ShowtimeGroup group = await _context.ShowtimeGroups .Where(g => g.ShowtimeGroupID == id) .Include(g => g.ShowtimeGroupEntries) .ThenInclude(e => e.Showtimes) .Include(g => g.Movie) .SingleAsync(); group.UpdateEntries(UpdatedGroup); await _context.SaveChangesAsync(); group.Movie = null; foreach (ShowtimeGroupEntry entry in group.ShowtimeGroupEntries) { entry.Showtimes = null; } return(Created($"api/movie/showtimegroups/{id}", group)); } return(BadRequest(errors)); }
public async Task <IActionResult> PostMovieShowtimesAsync(int id, [FromBody] ShowtimeGroup showtimeGroup) { if (showtimeGroup == null) { return(BadRequest(new { general = "There was an unexpected error. Try again later." })); } Dictionary <string, string> errors = showtimeGroup.Validate(_context); if (errors.Count == 0) { showtimeGroup.GenerateShowtimes(_context); _context.ShowtimeGroups.Add(showtimeGroup); await _context.SaveChangesAsync(); showtimeGroup.Movie = null; foreach (ShowtimeGroupEntry entry in showtimeGroup.ShowtimeGroupEntries) { entry.Showtimes = null; } return(CreatedAtRoute("GetShowtimeGroup", new { id = showtimeGroup.ShowtimeGroupID }, showtimeGroup)); } return(BadRequest(errors)); }