public async Task <UserGetFullApiModel> Registration(string login, string password, string userName, UserContactTypeEnum contactType, UserProfileAddApiModel userProfile) { if (await _repository.AnyAsync(x => x.Email == login)) { throw new ArgumentException($"User with this email already exist"); } if (await _repository.AnyAsync(x => x.UserName == userName)) { throw new ArgumentException($"User with this userName already exist"); } var contact = login.ToLower(); var hash = _passwordManager.GetHash(password); User user = await CreateByEmail(contact, hash); user.SetId(); user.UserName = userName; user.UserProfile = _dataMapper.Parse <UserProfileAddApiModel, UserProfile>(userProfile); user.UserProfileId = user.Id; user.UserProfile.Id = user.Id; user.UserProfile.Created = DateTime.UtcNow; user.UserProfile.Updated = user.UserProfile.Created; await _repository.Add(user); user.UserRoles = (await _userRoleRepository.AddRoles(user.Id, RoleHelper.Current.User.Id)).ToList(); var userModel = _dataMapper.Parse <User, UserGetFullApiModel>(user); return(userModel); }
public void SetUserProfileDefaultDataForEntity(ref UserProfileAddApiModel model) { if (model.LanguageId == 0) { model.LanguageId = LanguageHelper.Current.Russian.Id; } if (model.GenderId == 0) { model.GenderId = GenderHelper.Current.Unknown.Id; model.GenderLanguageId = LanguageHelper.Current.Russian.Id; } model.Created = DateTime.UtcNow; model.Updated = model.Created; }
public void SetUserProfileDefaultDataForRegistration(ref UserProfileAddApiModel model) { if (model.LanguageId == 0) { model.LanguageId = LanguageHelper.Current.Russian.Id; } if (model.GenderId == 0) { model.GenderId = GenderHelper.Current.Unknown.Id; model.GenderLanguageId = LanguageHelper.Current.Russian.Id; } model.FileEntityId = "default-user"; model.Created = DateTime.UtcNow; model.Updated = model.Created; model.ActivityStatus = EntityActivityStatusEnum.Inactive; }
public async Task <UserGetFullApiModel> Anonymous() { User user = new User(); var userProfile = new UserProfileAddApiModel(); user.SetId(); user.UserProfile = _dataMapper.Parse <UserProfileAddApiModel, UserProfile>(userProfile); user.UserProfile.Id = user.Id; await _repository.Add(user); await _userRoleRepository.AddRoles(user.Id, RoleHelper.Current.User.Id); var userModel = _dataMapper.Parse <User, UserGetFullApiModel>(user); return(userModel); }
public async Task <UserGetFullApiModel> AnonymousAsync() { User user = new User(); var userProfile = new UserProfileAddApiModel(); UserProfileHelper.Current.SetUserProfileDefaultDataForRegistration(ref userProfile); user.SetId(); user.UserProfile = _dataMapper.Parse <UserProfileAddApiModel, UserProfile>(userProfile); user.UserProfile.Id = user.Id; await _userRepository.AddAsync(user); await _userRoleRepository.AddRolesAsync(user.Id, RoleHelper.Current.User.Id); var userModel = _dataMapper.Parse <User, UserGetFullApiModel>(user); return(userModel); }
public async Task <UserGetFullApiModel> RegistrationAsync(string login, string password, ContactTypeEnum contactType, UserProfileAddApiModel userProfile) { var contact = login.ToLower(); var hash = AppHelper.Current.GetCryptoHash(password); User user = await CreateDefaultUserEntityAsync(contact, hash, contactType); UserProfileHelper.Current.SetUserProfileDefaultDataForRegistration(ref userProfile); user.SetId(); user.UserProfileId = user.Id; user.UserProfile = _dataMapper.Parse <UserProfileAddApiModel, UserProfile>(userProfile); user.UserProfile.Id = user.Id; await _userRepository.AddAsync(user); user.UserRoles = (await _userRoleRepository.AddRolesAsync(user.Id, RoleHelper.Current.User.Id)).ToList(); var userModel = _dataMapper.Parse <User, UserGetFullApiModel>(user); return(userModel); }