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 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 PutUser([FromBody] Users user) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } 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 == user.user_id); if (existingUser != null) { existingUser.Username = user.Username; existingUser.Email = user.Email; existingUser.Password = user.Password; entities.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult PostRelationship(Relationship relationship) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (yndlingsfilmDBEntities entities = new yndlingsfilmDBEntities()) { entities.Relationship.Add(new Relationship() { userone_id = relationship.userone_id, usertwo_id = relationship.usertwo_id });; entities.SaveChanges(); } return(Ok()); }
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()); } }
public IHttpActionResult PostUser([FromBody] Users user) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (yndlingsfilmDBEntities entities = new yndlingsfilmDBEntities()) { entities.Users.Add(new Users() { Username = user.Username, Password = BCrypt.Net.BCrypt.HashPassword(user.Password), Email = user.Email, });; entities.SaveChanges(); Console.WriteLine("User was created with following information:" + user.Username + user.Password + user.Email); } return(Ok()); }