Exemplo n.º 1
0
        public IHttpActionResult PutTop5List(int id, Top5List top5List)
        {
            var strCurrentUserId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != top5List.Top5ListId)
            {
                return(BadRequest());
            }

            db.Entry(top5List).State = EntityState.Modified;

            try
            {
                /*List<Tag> tags = top5List.Tags.ToList();
                 * var top5ItemInDb = db.Top5List.Include(c => c.Tags)
                 *  .Single(c => c.Top5ListId == id);
                 *
                 * // Remove all tags from top5list in DB
                 * foreach (var deltag in top5List.Tags.Where(t => t.TagId != 0))
                 * {
                 *  db.Tags.Remove(deltag);
                 * }*/

                db.SaveChanges();

                // Add all tags from top5list to DB

                /*foreach (var newtag in tags)
                 *  top5ItemInDb.Tags.Add(new Tag { TagText = newtag.TagText});
                 *
                 * db.SaveChanges();*/
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Top5ListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public IHttpActionResult GetTop5List(int id)
        {
            Top5List top5List = db.Top5List.
                                Include(p => p.Items).
                                Include(p => p.Tags).
                                First(p => p.Top5ListId == id);

            if (top5List == null)
            {
                return(NotFound());
            }

            return(Ok(top5List));
        }
Exemplo n.º 3
0
        public IHttpActionResult DeleteTop5List(int id)
        {
            Top5List top5List = db.Top5List.Find(id);

            if (top5List == null)
            {
                return(NotFound());
            }

            db.Top5List.Remove(top5List);
            db.SaveChanges();

            return(Ok(top5List));
        }
Exemplo n.º 4
0
        public IActionResult Index()
        {
            List <string> top5list = new List <string>();

            foreach (Top5List top in Top5List.GetTop5List())
            {
                //Fills fav dish null values with a string
                string?favdish = top.FavDish ?? "It's all tasty!";

                //builds output
                top5list.Add("#" + top.RestRanking + " " + top.RestName + "<br> Favortie Dish: " + favdish + "<br> Address: " + top.RestAddress + "<br> Phone Number: " + top.RestPhone + "<br> Website: " + top.RestWebsite);
            }

            return(View(top5list));
        }
Exemplo n.º 5
0
        public IHttpActionResult PostTop5List(Top5List top5List)
        {
            var strCurrentUserId = User.Identity.GetUserId();

            top5List.UserId = strCurrentUserId;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Top5List.Add(top5List);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = top5List.Top5ListId }, top5List));
        }