Ejemplo n.º 1
0
        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()));
                }
            }
        }
Ejemplo n.º 2
0
 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));
     }
 }
Ejemplo n.º 3
0
        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"));
            }
        }
Ejemplo n.º 4
0
        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"));
            }
        }
Ejemplo n.º 5
0
        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");
            }
        }