/// <summary> /// Создает новый профиль /// </summary> /// <param name="name">ФИО пользователя</param> /// <param name="gender">Пол</param> /// <param name="birthdate">День рождения</param> public void Create(string name, GenderTypes gender, DateTime birthdate) { Profile profileEntity = new Profile(); profileEntity.profileId = Guid.NewGuid(); profileEntity.name = name; profileEntity.nameVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.gender = (int)gender; profileEntity.genderVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.birthdate = DateTime.Now; profileEntity.birthdateVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.avatar = "/Resources/Images/Avatars/noavatar.png"; profileEntity.status = (int)ProfileTypes.Active; unitOfWork.RepositoryFor<Profile>().Add(profileEntity); unitOfWork.Commit(); }
/// <summary> /// Создает и добавляет в базу данных нового пользователя /// </summary> /// <param name="userId">Идентификатор пользователя</param> /// <param name="referrerId">Идентификатор пригласившего в систему реферера</param> /// <param name="username">Псевдоним пользователя</param> /// <param name="email">Адрес электронной почты</param> /// <param name="password">Пароль</param> /// <returns></returns> public void Create(Guid userId, Guid? referrerId, string username, string email, string password) { #region Role Role roleEntity = unitOfWork.RepositoryFor<Role>().Single(i => i.name == "guest"); #endregion #region Account Account accountEntity = new Account(); accountEntity.accountId = Guid.NewGuid(); accountEntity.balance = 0.00M; accountEntity.currency = 0; accountEntity.activePlan = (int)AccountTypes.Free; unitOfWork.RepositoryFor<Account>().Add(accountEntity); #endregion #region Profile Profile profileEntity = new Profile(); profileEntity.profileId = Guid.NewGuid(); profileEntity.name = string.Empty; profileEntity.nameVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.gender = (int)GenderTypes.Unspecified; profileEntity.genderVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.birthdate = DateTime.Now; profileEntity.birthdateVisibility = (int)FieldVisibilityTypes.Everyone; profileEntity.avatar = "/Assets/Images/noavatar.gif"; //profileEntity.Location = locationEntity; profileEntity.status = (int)ProfileTypes.Active; profileEntity.level = 0; profileEntity.karma = 0; unitOfWork.RepositoryFor<Profile>().Add(profileEntity); //m_unitOfWork.Commit(); #endregion #region User User userEntity = new User(); userEntity.userId = userId; userEntity.referrerId = referrerId; userEntity.userName = username; userEntity.email = email; userEntity.emailKey = Guid.NewGuid().ToString(); userEntity.passwordSalt = GetPasswordSalt(); userEntity.password = GetPasswordHash(password, userEntity.passwordSalt); userEntity.isLockedOut = false; userEntity.dateCreated = DateTime.Now; userEntity.lastDateLockout = DateTime.Now; /* Дата блокировки аккаута */ userEntity.lastDateLogin = DateTime.Now; /* Дата последнего входа */ userEntity.lastDateModified = DateTime.Now; /* Дата последнего редактировании профиля */ userEntity.lastPasswordDateChanged = DateTime.Now; /* Дата смены пароля */ userEntity.account = accountEntity; userEntity.profile = profileEntity; userEntity.role = roleEntity; unitOfWork.RepositoryFor<User>().Add(userEntity); unitOfWork.Commit(); #endregion }