示例#1
0
        public IHttpActionResult Create(Item item)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Context.Items.Add(item);
            Context.SaveChanges();

            return Ok();
        }
示例#2
0
        public IHttpActionResult Update(int id, Item item)
        {
            item.Id = id;

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

            Context.Items.Attach(item);
            var entry = Context.Entry(item);
            entry.State = EntityState.Modified;

            Context.SaveChanges();

            return Ok();
        }