/// <summary> /// The get user on login. /// </summary> /// <param name="login"> /// The login. /// </param> /// <returns> /// The <see cref="User"/>. /// </returns> public User GetUserOnLogin(string login) { var user = new User(); // TODO return user from DB var sqlParameters = new SqlParameter[1]; sqlParameters[0] = new SqlParameter("@Login", SqlDbType.VarChar) { Value = login }; var dataTable = this.sqlDalManager.SelectProcedure("GetUserOnLogin", sqlParameters); if (dataTable.Rows.Count > 0) { foreach (DataRow dataRow in dataTable.Rows) { DateTime date; user.UserID = int.Parse(dataRow["UserId"].ToString()); user.Login = dataRow["Login"].ToString(); user.Password = dataRow["Password"].ToString(); DateTime.TryParse(dataRow["TimeCreated"].ToString(), out date); user.TimeCreated = date; } } else { return null; } return user; }
public void DeteleUserBasicTest() { User newUser = new User(); newUser.Login = "******"; newUser.Password = "******"; newUser.TimeCreated = DateTime.Now; User returnedUser = this.userDalManager.CreateUser(newUser); this.userDalManager.DeleteUser(returnedUser.Login); }
public void CreateUserBasicTest() { User newUser = new User(); newUser.Login = "******"; newUser.Password = "******"; newUser.TimeCreated = DateTime.Now; User returnedUser = this.userDalManager.CreateUser(newUser); Console.WriteLine("Create user with Login - " + returnedUser.Login); this.userDalManager.DeleteUser(newUser.Login); Console.WriteLine("Delete user with Login - " + newUser.Login + " on CreateUserBasicTest"); }
/// <summary> /// The create user. /// </summary> /// <param name="user"> /// The user. /// </param> /// <returns> /// The <see cref="User"/>. /// </returns> /// <exception cref="Exception"> /// </exception> public User CreateUser(User user) { var sqlParameters = new SqlParameter[3]; sqlParameters[0] = new SqlParameter("@Login", SqlDbType.VarChar) { Value = user.Login }; sqlParameters[1] = new SqlParameter("@Password", SqlDbType.VarChar) { Value = user.Password }; sqlParameters[2] = new SqlParameter("@TimeCreated", SqlDbType.DateTime) { Value = user.TimeCreated }; try { user.UserID = this.sqlDalManager.InsertProcedureWithOutputInsertedId("CreateUser", sqlParameters); } catch (Exception exception) { throw exception; } return user; }
/// <summary> /// The create user. /// </summary> /// <param name="registerInfo"> /// The register info. /// </param> /// <returns> /// The <see cref="User"/>. /// </returns> /// <exception cref="Exception"> /// </exception> public User CreateUser(RegisterInfo registerInfo) { User newUser = new User(); if (!this.IsAlreadyUserExist(registerInfo.Login)) { if (this.Validate(registerInfo)) { newUser.Login = registerInfo.Login; newUser.Password = registerInfo.Password; newUser.TimeCreated = DateTime.Now; newUser = this.userDalManager.CreateUser(newUser); } } else { throw new Exception("User " + registerInfo.Login + "already exist"); } return newUser; }