public async Task CreateUserProfileAsync(UserProfileBO profile) { Validate.NotNull(profile, "User profile"); var p = new Entities.UserProfile { FirstName = profile.FirstName, LastName = profile.LastName, Email = profile.Email }; await uow.UserProfileRepository.CreateAsync(p); }
public async Task <AuthTokens> RegisterAsync(RegistrationData data) { Validate.NotNull(data, "Registration data"); Validate.NotNull(data.FirstName, "First name"); Validate.NotNull(data.LastName, "Last name"); Validate.NotNull(data.Email, "Email"); Validate.NotNull(data.LanguageCode, "Language code"); { var temp = (await uow.UserProfileRepository.GetByConditionAsync(x => x.Email == data.Email)).FirstOrDefault(); if (temp != null) { throw new Exception("Email already in use"); } } var language = await FindEntityAsync(uow.LanguageRepository, x => x.ShortCode == data.LanguageCode); var enc = cs.EncryptPassword(data.Password); var rootFolder = new Entities.Folder { Name = "Root", ParentFolderId = null }; var settings = new Entities.UserSettings { LanguageId = language.Id, Folder = rootFolder }; var profile = new Entities.UserProfile { FirstName = data.FirstName, LastName = data.LastName, Email = data.Email, UserSettings = new System.Collections.Generic.List <Entities.UserSettings> { settings } }; var user = new Entities.AppUser { Username = "******", PasswordHash = enc, UserProfile = profile }; await uow.AppUserRepository.CreateAsync(user); user.Username = cs.GenerateUsername(); uow.AppUserRepository.Update(user); var tokens = GenerateTokens(user); var session = new Entities.Session { AppUserId = user.Id, Token = tokens.RefreshToken, CreatedAt = DateTime.UtcNow.ToLongTimeString() }; await uow.SessionRepository.CreateAsync(session); return(tokens); }