コード例 #1
0
ファイル: UserController.cs プロジェクト: m13oas/DevSchool
 public Guid Create(Users user)
 {
     if (!ur.Exist(user.email)) {
         user.idUser = Guid.NewGuid();
         ur.Create(user);
         return user.idUser;
     }
     throw new ArgumentException("данные не уникальны");
 }
コード例 #2
0
ファイル: UserRepository.cs プロジェクト: m13oas/DevSchool
 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>();
     }
 }
コード例 #3
0
ファイル: UserRepository.cs プロジェクト: m13oas/DevSchool
 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}");
         }
     }
 }
コード例 #4
0
ファイル: UserRepository.cs プロジェクト: m13oas/DevSchool
 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}");
         }
     }
 }
コード例 #5
0
ファイル: UserRepository.cs プロジェクト: m13oas/DevSchool
 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}");
         }
     }
 }
コード例 #6
0
ファイル: UserController.cs プロジェクト: m13oas/DevSchool
 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("данные не верно введены");
 }
コード例 #7
0
ファイル: UserController.cs プロジェクト: m13oas/DevSchool
 public void Delete(Users user)
 {
     if(ur.Exist(user.idUser))
         ur.Delete(user);
 }
コード例 #8
0
ファイル: UserController.cs プロジェクト: m13oas/DevSchool
 public void ChangeNumber(Users user, string number)
 {
     ur.ChangeNumber(user, number);
 }
コード例 #9
0
ファイル: UserRepository.cs プロジェクト: m13oas/DevSchool
 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")),
                 };
             }
         }
     }
 }