Exemplo n.º 1
0
        public IHttpActionResult PutRelationship(int id, Relationship relationship)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != relationship.userone_id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutMovies(int id, Movies movies)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != movies.movie_id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult DeleteUser(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid student id"));
            }
            using (var entities = new yndlingsfilmDBEntities())
            {
                //DATABASE QUERY. CHECKS THE DATABASE FOR THE USER WITH THE GIVEN USERID. THEN IT CREATES A NEW USER VARIABLE THAT WE DECLARE ALL OF THE GIVEN VARIBLES FROM THE HTTP PUT REQUEST
                var existingUser = entities.Users
                                   .FirstOrDefault(s => s.user_id == id);

                if (existingUser != null)
                {
                    entities.Entry(existingUser).State = System.Data.Entity.EntityState.Deleted;
                    entities.SaveChanges();
                }
                return(Ok());
            }
        }