Exemplo n.º 1
0
 public Guid Create(Users user)
 {
     if (!ur.Exist(user.email)) {
         user.idUser = Guid.NewGuid();
         ur.Create(user);
         return user.idUser;
     }
     throw new ArgumentException("данные не уникальны");
 }
Exemplo n.º 2
0
 public async Task<Users> LoginUser(Users user) {
     string usr = JsonConvert.SerializeObject(user);
     using(var client = new HttpClient {
         BaseAddress = new Uri(@"http://localhost:57239/")
     }) {
         var response = client.PostAsJsonAsync("api/users/login/", user).Result;
         //string a = JsonConvert.SerializeObject(user);
         return await response.Content.ReadAsAsync<Users>();
     }
 }
Exemplo n.º 3
0
 public void ChangeNumber(Users user, string number)
 {
     logger.Log(LogLevel.Info, $"Start Changing number user with id = {user.idUser} to number = {number}");
     if(user == null || !Exist(user.idUser)) {
         logger.Log(LogLevel.Error, $"User not exist");
         throw new ArgumentNullException();
     }
     using(var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DevSchoolDB"].ConnectionString)) {
         connection.Open();
         using(var command = connection.CreateCommand()) {
             command.CommandText = "update [dbo].[Users] set contactNumber = @contactNumber where idUser = @id";
             command.Parameters.AddWithValue("@id", user.idUser);
             command.Parameters.AddWithValue("@contactNumber", number);
             command.ExecuteNonQuery();
             logger.Log(LogLevel.Info, $"End Changing number user with id = {user.idUser} to number = {number}");
         }
     }
 }
Exemplo n.º 4
0
 public void Delete(Users user)
 {
     logger.Log(LogLevel.Info, $"Start deleting user with id = {user.idUser}");
     if(user == null) {
         logger.Log(LogLevel.Error, $"User not exist");
         throw new ArgumentNullException();
     }
     using(var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DevSchoolDB"].ConnectionString)) {
         connection.Open();
         //TODO parse email and contactNumber
         //TODO check for existing
         using(var command = connection.CreateCommand()) {
             command.CommandText = "delete from [dbo].[Users] where idUser = @id";
             command.Parameters.AddWithValue("@id", user.idUser);
             //command.Parameters.AddWithValue("@email", user.email);
             command.ExecuteNonQuery();
             logger.Log(LogLevel.Info, $"End deleting user with id = {user.idUser}");
         }
     }
 }
Exemplo n.º 5
0
 public void Create(Users user)
 {
     logger.Log(LogLevel.Info, $"Start creating user with id = {user.idUser}");
     if(user == null) {
         logger.Log(LogLevel.Error, $"User is null");
         throw new ArgumentNullException();
     }
     using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DevSchoolDB"].ConnectionString)) {
         connection.Open();
         //TODO parse email and contactNumber
         //TODO check for unique
         using (var command = connection.CreateCommand()) {
             command.CommandText = "insert into [dbo].[Users] (idUser,  firstName, lastName, contactNumber, email) values (@Id, @firstName, @lastName, @contactNumber, @email)";
             command.Parameters.AddWithValue("@id", user.idUser);
             command.Parameters.AddWithValue("@email", user.email);
             command.Parameters.AddWithValue("@firstName", user.firstName);
             command.Parameters.AddWithValue("@lastName", user.lastName);
             command.Parameters.AddWithValue("@contactNumber", user.contactNumber);
             command.ExecuteNonQuery();
             logger.Log(LogLevel.Info, $"Start creating user with id = {user.idUser}");
         }
     }
 }
Exemplo n.º 6
0
 public Users Login(Users user)
 {
     if (ur.Exist(user.email) && ur.Phone(user.email).Replace(" ", String.Empty) == user.contactNumber)
         return ur.GetUser(user.email);
     throw new ArgumentException("данные не верно введены");
 }
Exemplo n.º 7
0
 public void Delete(Users user)
 {
     if(ur.Exist(user.idUser))
         ur.Delete(user);
 }
Exemplo n.º 8
0
 public void ChangeNumber(Users user, string number)
 {
     ur.ChangeNumber(user, number);
 }
Exemplo n.º 9
0
 public Users GetUser(Users user)
 {
     logger.Log(LogLevel.Info, $"Start Getting user with id = {user.idUser}");
     if(user == null || !Exist(user.idUser)) {
         logger.Log(LogLevel.Error, $"User not exist");
         throw new ArgumentNullException($"User not exist");
     }
     using(var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DevSchoolDB"].ConnectionString)) {
         connection.Open();
         using(var command = connection.CreateCommand()) {
             command.CommandText = "select idUser, firstName, lastName, contactNumber from [dbo].[Users] where idUser = @id";
             command.Parameters.AddWithValue("@id", user.idUser);
             using (SqlDataReader reader = command.ExecuteReader()) {
                 reader.Read();
                 logger.Log(LogLevel.Info, $"End Getting user with id = {user.idUser}");
                 return new Users {
                     idUser = reader.GetGuid(reader.GetOrdinal("idUser")),
                     contactNumber = reader.GetString(reader.GetOrdinal("contactNumber")),
              //       email = reader.GetString(reader.GetOrdinal("email")),
                     firstName = reader.GetString(reader.GetOrdinal("firstName")),
                     lastName = reader.GetString(reader.GetOrdinal("lastName")),
                 };
             }
         }
     }
 }