public Movie ChangeMovieRuntime(UpdateRuntimeRequestModel userUpdateRequest) { //1.In your program, provide a way to change a movie’s runtime found by title. //New title to be obtained via user input. Change must be reflected in the DB. MovieDatabaseserverRespnse movieResposne = new MovieDatabaseserverRespnse(); string query1 = "UPDATE MOVIE " + "SET RUNTIME = @userRuntime " + "where LOWER m.title like LOWER @title " + "LIMIT 1"; // create connection and command SqlConnection connecting = new SqlConnection(connectionString); using (SqlCommand changeRuntime = new SqlCommand(query1, connecting)) { changeRuntime.Parameters.Add("@userRuntime", SqlDbType.VarChar, 50).Value = userUpdateRequest.RunTime; changeRuntime.Parameters.Add("@title", SqlDbType.VarChar, 50).Value = userUpdateRequest.Title; try { connecting.Open(); using (SqlDataReader reader = changeRuntime.ExecuteReader()) { while (reader.Read()) { // ORM - Object Relation Mapping movieResposne.Movies.Add( // pushing the mapped object intot a new object and pushing to the list. new Movie() { MovieNum = Convert.ToInt32(reader[0]), Title = reader[1].ToString(), ReleaseYear = Convert.ToInt16(reader[2]), RunTime = Convert.ToInt16(reader[3]) }); } reader.Close(); } connecting.Close(); } catch (SqlException ex) { throw new ApplicationException($"Some sql error happened + {ex}"); } return(movieResposne.Movies[0]); } }
public ActionResult <Movie> ChangeMovieRuntime([FromBody] UpdateRuntimeRequestModel userUpdateRequest) { var output = _DatabaseLayer.ChangeMovieRuntime(userUpdateRequest); return(Ok(output)); }