public void AddUser(SocialPipelineUser user) { Contract.Requires(!string.IsNullOrEmpty(user.FirstName)); Contract.Requires(!string.IsNullOrEmpty(user.LastName)); Contract.Requires(!string.IsNullOrEmpty(user.Email)); Contract.Requires(!string.IsNullOrEmpty(user.Password)); }
/// <exception cref="UnableToAddUserException">Thrown when there is an issue adding a new user</exception> public void AddUser(SocialPipelineUser user) { try { //Create user var userDto = Mapper.Map<SocialPipelineUser, SocialPipelineUserDto>(user); userDto.Password = PasswordService.Md5Hash(userDto.Password); userRepository.AddUser(userDto); //Email user //TODO: Add ability to email using IEmailService } catch (UnableToAddUserException exception) { logger.LogException("AddUser: Unable to find users", exception); throw new UnableToAddUserException("AddUser: Users does not exist."); } catch (SocialPipelineDatabaseConnectionException exception) { logger.LogException("AddUser: Unable to find users due to database connection issue.", exception); throw new UnableToAddUserException("AddUser: Problems connecting to the database."); } catch (Exception exception) { logger.LogException("AddUser: Unhandled Exception", exception); throw new UnableToAddUserException("AddUser: Unknown issue."); } }
public int RegisterUser(SocialPipelineUser user, Company company) { Contract.Requires(!string.IsNullOrEmpty(user.FirstName)); Contract.Requires(!string.IsNullOrEmpty(user.Email)); Contract.Requires(!string.IsNullOrEmpty(user.Password)); Contract.Requires(!string.IsNullOrEmpty(company.Name)); return default(int); }
/// <exception cref="UnableToRegisterUserException">Thrown when there are issues registering a new user.</exception> public int RegisterUser(SocialPipelineUser user, Company company) { try { var userDto = Mapper.Map<SocialPipelineUser, SocialPipelineUserDto>(user); var companyDto = Mapper.Map<Company, CompanyDto>(company); userDto.Password = PasswordService.Md5Hash(userDto.Password); EnsureUserIsNotAlreadyRegistered(user); EnsureCompanyIsNotAlreadyRegistered(company); return registrationRepository.RegisterUser(userDto, companyDto); } catch (RegistrationException exception) { logger.LogException("RegisterUser: Unable to register new user", exception); throw new UnableToRegisterUserException("RegisterUser: Unable to register new user", exception); } catch (SocialPipelineDatabaseConnectionException exception) { logger.LogException("RegisterUser: Unable to register new user due to database connection issue", exception); throw new UnableToRegisterUserException("RegisterUser: Unable to register new user due to database connection issue", exception); } catch (UserAlreadyRegisteredException exception) { logger.LogException(string.Format("RegisterUser: User already exists and registered with this email {0}", user.Email)); throw; } catch (CompanyAlreadyExistsException exception) { logger.LogException(string.Format("RegisterUser: Company already exists and registered with this name {0}", company.Name)); throw; } catch (Exception exception) { logger.LogException("RegisterUser: Unhandled Exception", exception); throw new UnableToRegisterUserException("RegisterUser: Unhandled Exception", exception); } }
private void EnsureUserIsNotAlreadyRegistered(SocialPipelineUser user) { try { var registeredUser = userService.FindByEmailAddress(user.Email); if (registeredUser != null) throw new UserAlreadyRegisteredException("RegisterUser: This user already exists"); } catch (FindUserException) { //If the user doesn't exist that's good. We can continue! } }