public IHttpActionResult Put(Seller_user todo) { if (Seller_userDAO.Update(todo)) { return(Ok()); } return(BadRequest()); }
//Return seller by id public static Seller_user Get(int id) { Seller_user m = null; using (SqlConnection connection = DataBase.GetConnection()) { connection.Open(); SqlCommand command = new SqlCommand(GET, connection); command.Parameters.AddWithValue("@idSeller", id); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { m = new Seller_user(reader); } } return(m); }
//Add seller public static Seller_user Insert(Seller_user todo) { using (SqlConnection connection = DataBase.GetConnection()) { connection.Open(); SqlCommand command = new SqlCommand(INSERT, connection); command.Parameters.AddWithValue("@username", todo.username); command.Parameters.AddWithValue("@nbSales", todo.nbSales); command.Parameters.AddWithValue("@positiveVote", todo.positiveVote); command.Parameters.AddWithValue("@negativeVote", todo.negativeVote); command.Parameters.AddWithValue("@idUser", todo.idUser); todo.idSeller = (int)command.ExecuteScalar(); } return(todo); }
//Update a seller_user public static bool Update(Seller_user todo) { bool state = false; using (SqlConnection connection = DataBase.GetConnection()) { connection.Open(); SqlCommand command = new SqlCommand(UPDATE, connection); command.Parameters.AddWithValue("@username", todo.username); command.Parameters.AddWithValue("@nbSales", todo.nbSales); command.Parameters.AddWithValue("@positiveVote", todo.positiveVote); command.Parameters.AddWithValue("@negativeVote", todo.negativeVote); command.Parameters.AddWithValue("@idUser", todo.idUser); state = command.ExecuteNonQuery() != 0; } return(state); }
public Seller_user Post(Seller_user todo) { return(Seller_userDAO.Insert(todo)); }