Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }