public ActionResult <List <Games> > GetJamEntries(int id) { using (GameJamDBContext context = new GameJamDBContext()) { Jams jam = context.Jams.Find(id); if (jam == null) { return(BadRequest("Jam was not found")); } else { var entries = context .Games .Include(u => u.FkUserNavigation) .Where((g) => g.FkJam == id) .Select(e => new JamEntry() { IdGame = e.IdGame, ThumbnailImageLink = e.ThumbnailImageLink, Title = e.Title, AuthorName = e.FkUserNavigation.Username }); return(Ok(entries.ToList())); } } }
public ActionResult <Jams> Get(int id) { using (GameJamDBContext context = new GameJamDBContext()) { Jams jam = context.Jams.Find(id); if (jam == null) { return(BadRequest("Jam was not found")); } return(Ok(jam)); } }
public ActionResult Patch(int id, [FromBody] Delta <Jams> editedJam) { using (GameJamDBContext context = new GameJamDBContext()) { Jams origJam = context.Jams.Find(id); if (origJam == null) { return(BadRequest("Jam was not found")); } editedJam.Patch(origJam); context.Entry(origJam).State = EntityState.Modified; context.SaveChanges(); return(Ok("Jam updated successfully")); } }
public ActionResult Delete(int id) { using (GameJamDBContext context = new GameJamDBContext()) { Jams jam = context.Jams.Find(id); if (jam == null) { return(BadRequest("Jam you're trying to delete was not found")); } //TODO: check if other related entities needs deleting context.Jams.Remove(jam); context.SaveChanges(); return(Ok("Jam deleted successfully")); } }
public ActionResult <int> Post([FromBody] Jams jam) { using (GameJamDBContext context = new GameJamDBContext()) { if (string.IsNullOrEmpty(jam.Title) || string.IsNullOrEmpty(jam.Description)) { return(BadRequest("Title and/or description can't be empty")); } context.Jams.Add(jam); int added = context.SaveChanges(); if (added < 1) { return(BadRequest("Could not create jam")); } return(Ok(jam.IdJam));//Ok("Jam created successfully"); } }