public SignUpInResult SignUp(SignUpRequest request) { return(BaseInvokeCheckModel(request, () => { var responseBuilder = ResponseBuilder <SignUpInResult> .Fail(); if (!_inviteService.IsInviteValid(request.VerificationCode)) { return responseBuilder.SetInfoAndBuild("Verification code is wrong"); } if (_dbContext.Users.Any(x => x.Email == request.Email)) { return responseBuilder.SetInfoAndBuild("User with this email already registered"); } if (_dbContext.Users.Any(x => x.VerificationCode == request.VerificationCode)) { return responseBuilder.SetInfoAndBuild("This invite already used"); } string salt = Crypto.GenerateSalt(); string passwordHah = Crypto.HashPassword(request.Password + salt); var dataUser = UserMapper.ToData.FromRequest(request, (user) => { user.Id = Guid.NewGuid(); user.IsUploadingAudio = false; user.PasswordHash = passwordHah; user.PasswordSalt = salt; user.RegisterDate = DateTime.Now; }); var dataAuthToken = new DataModel.AuthToken() { Id = Guid.NewGuid(), DateExpired = DateTime.Now.AddDays(AuthTokenDaysExpired), UserId = dataUser.Id, IsActive = true, }; var playlist = new DataModel.Playlist() { Id = Guid.NewGuid(), IsGeneral = true, OwnerId = dataUser.Id, OrderValue = 0, }; _dbContext.AuthTokens.Add(dataAuthToken); _dbContext.Users.Add(dataUser); _dbContext.Playlists.Add(playlist); _dbContext.SaveChanges(); return ResponseBuilder <SignUpInResult> .SuccessBuild(new SignUpInResult() { User = UserMapper.ToApi.FromData(dataUser), AuthToken = AuthTokenMapper.ToApi.FromData(dataAuthToken), }); })); }