Example #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);
        }
Example #2
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);
        }