public beGreen.Model.Entity.User GetByID(string id) { beGreen.Model.Entity.User result = null; using (SqlConnection connection = new SqlConnection(Connection.String)) { SqlCommand command = connection.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "UserGetByID"; command.Parameters.Add(new SqlParameter("@Id", id)); connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { result = MapUser(reader); } } } return(result); }
private User MapUser(SqlDataReader data) { beGreen.Model.Entity.User result = new beGreen.Model.Entity.User(); result.Email = data["Email"].ToString(); result.Password = data["Password"].ToString(); result.PublicID = data["PublicID"].ToString(); return(result); }
private beGreen.Model.Entity.User MapEntity(SqlDataReader data) { beGreen.Model.Entity.User result = new beGreen.Model.Entity.User(); result.ID = int.Parse(data["Id"].ToString()); result.Email = data["Email"].ToString(); result.Password = data["Password"].ToString(); result.PublicID = data["PublicID"].ToString(); result.Role = data["Role"].ToString(); return(result); }
public User Update(beGreen.Model.Entity.User entity) { using (SqlConnection connection = new SqlConnection(Connection.String)) { SqlCommand command = connection.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "UserUpdate"; command.Parameters.Add(new SqlParameter("@Id", entity.PublicID)); command.Parameters.Add(new SqlParameter("@Password", entity.Password)); connection.Open(); int result = (int)command.ExecuteNonQuery(); if (result < 1) { throw new Exception("Error in UpdateManufacturer stored procedure."); } return(entity); } }
public User Create(beGreen.Model.Entity.User entity) { using (SqlConnection connection = new SqlConnection(Connection.String)) { SqlCommand command = connection.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "UserCreate"; command.Parameters.Add(new SqlParameter("@Password", entity.Password)); command.Parameters.Add(new SqlParameter("@Email", entity.Email)); command.Parameters.Add(new SqlParameter("@PublicID", entity.PublicID)); command.Parameters.Add(new SqlParameter("@Role", entity.Role)); connection.Open(); int result = (int)command.ExecuteScalar(); if (result < 1) { throw new Exception("Error in CreateUser stored procedure."); } entity.ID = (int)result; return(entity); } }