private SqlCommand buildCommand(SqlCommand command, DataLayer.Models.UserDTO user) { command.Parameters.AddWithValue("ID", user.ID); command.Parameters.AddWithValue("Username", user.Username); command.Parameters.AddWithValue("Password", user.Password); command.Parameters.AddWithValue("Title", user.Title); return(command); }
public DataLayer.Models.UserDTO map(ServicesLayer.Models.UserModel model) { DataLayer.Models.UserDTO dto = new DataLayer.Models.UserDTO(); dto.ID = model.ID; dto.Username = model.Username; dto.Title = model.Title; dto.Password = model.Password; return(dto); }
public ServicesLayer.Models.UserModel map(DataLayer.Models.UserDTO dto) { ServicesLayer.Models.UserModel model = new ServicesLayer.Models.UserModel(); model.Username = dto.Username; model.Title = dto.Title; model.Password = dto.Password; model.ID = dto.ID; return(model); }
public bool create(DataLayer.Models.UserDTO user) { try { SqlCommand command = buildCommand(new SqlCommand(), user); command.Connection = new SqlConnection("Data Source=198.38.83.33;Initial Catalog=geluvac_assignment1;User ID=geluvac_andreitudorica;Password=Andrei1234"); command.Connection.Open(); command.CommandText = "INSERT INTO Users (Username,Password,Title) VALUES (@Username,@Password,@Title)"; command.ExecuteNonQuery(); command.Connection.Close(); //to be optimized inMemoryUsers = new List <Models.UserDTO>(); getAllFromDB(); return(true); } catch { } return(false); }
public bool update(DataLayer.Models.UserDTO user) { try { SqlCommand command = buildCommand(new SqlCommand(), user); command.Connection = new SqlConnection("Data Source=198.38.83.33;Initial Catalog=geluvac_assignment1;User ID=geluvac_andreitudorica;Password=Andrei1234"); command.Connection.Open(); command.CommandText = "UPDATE Users Set Username= @Username,Password=@Password,Title=@Title where ID=@ID"; command.ExecuteNonQuery(); command.Connection.Close(); //update DTO //DataLayer.Models.UserDTO userOld = inMemoryUsers.Find(x => x.ID == user.ID); // userOld = user; //to be checked inMemoryUsers = new List <Models.UserDTO>(); getAllFromDB(); return(true); } catch { } return(false); }