Exemplo n.º 1
0
        public IHttpActionResult PutList(int id, ListsModel list)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != list.ListID)
            {
                return BadRequest();
            }
            //
            var dbList = db.Lists.Find(id);
            dbList.Update(list);
            db.Entry(dbList).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ListExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
        public IHttpActionResult PostList(ListsModel list)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var addlist = new List(list);

            db.Lists.Add(addlist);
            db.SaveChanges();

            list.ListID = addlist.ListID;
            list.CreatedDate = addlist.CreatedDate;

            return CreatedAtRoute("DefaultApi", new { id = list.ListID }, list);
        }