Ejemplo n.º 1
0
        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public IHttpActionResult ToggleRequest(Friend friendRequest)
        {
            var request = db.Friends.SingleOrDefault(r =>
                                                     (r.FriendRecevierID == friendRequest.FriendRecevierID && r.FriendSenderID == friendRequest.FriendSenderID) ||
                                                     (r.FriendRecevierID == friendRequest.FriendSenderID && r.FriendSenderID == friendRequest.FriendRecevierID));

            if (request != null)
            {
                request.FriendState = !request.FriendState;

                db.Entry(request).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                    return(StatusCode(HttpStatusCode.NoContent));
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(NotFound());
                }
            }
            else
            {
                db.Friends.Add(friendRequest);
                return(StatusCode(HttpStatusCode.NoContent));
            }
        }