示例#1
0
        // PUT: odata/Users(5)
        public IHttpActionResult Put([FromODataUri] Guid key, Delta <User> patch)
        {
            Validate(patch.GetEntity());

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

            User user = db.Users.Find(key);

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

            patch.Put(user);

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

            return(Updated(user));
        }
示例#2
0
 public bool Post(User user)
 {
     DB.Users.Add(user);
     return(DB.SaveChanges() > 0);
 }