public ServiceResponse <HeadstoneUserRole> Create(HeadstoneUserRole model) { using (var bo = new UserRoleDAO()) { int result = bo.Insert(model as HeadstoneUserRole); if (result > 0) { return(new ServiceResponse <HeadstoneUserRole>() { Type = ServiceResponseTypes.Success, Source = ServiceResponseSources.MsSQL, Result = new List <HeadstoneUserRole>() { model } }); } else { return(new ServiceResponse <HeadstoneUserRole>() { Type = ServiceResponseTypes.Error, Source = ServiceResponseSources.MsSQL, Result = new List <HeadstoneUserRole>() { model } }); } } }
public void Save(Connection connection, MySqlTransaction transaction = null) { using (var dao = new UserRoleDAO(connection)) { if (Id == 0) { dao.Insert(this, transaction); } else { dao.Update(this, transaction); } } }
public RegisterUserResponse Register(string Email, string UserName, string Password, string ConfirmPassword) { if (CheckIfUserExists(Email, UserName)) { return(new RegisterUserResponse() { Success = false, FailReason = UserInsertFailReason.UserOrEmailExists }); } if (!Password.Equals(ConfirmPassword)) { return(new RegisterUserResponse() { Success = false, FailReason = UserInsertFailReason.PasswordsDontMatch }); } // Hash the password string passwordHash = BCrypt.Net.BCrypt.HashPassword(Password); User newUser = new User() { Email = Email, UserName = UserName, PasswordHash = passwordHash }; try { // Insert the user UserDAO userDao = new UserDAO(); ulong userId = userDao.Insert(newUser); // Connect the user to a role UserRole userRole = new UserRole() { UserID = (int)userId, RoleID = 3 // Role of ordinary user is 3 }; UserRoleDAO dao = new UserRoleDAO(); dao.Insert(userRole); } catch (Exception e) { return(new RegisterUserResponse() { Success = false, FailReason = UserInsertFailReason.DatabaseInsertionError, ErrorMessage = e.Message }); } return(new RegisterUserResponse() { Success = true, FailReason = UserInsertFailReason.Success, ErrorMessage = null }); }