private User RegisterUser(ISystemUnitOfWork unitOfWork, ExtAccount extAccount) { User user = _securityUserService.RegisterUser(unitOfWork, extAccount.ToUser()); if (user == null) return null; extAccount.User = user; _AttachImage(unitOfWork, user, extAccount.ProfilePicture); _extAccountService.Create(unitOfWork, extAccount); return user; }
private ExtAccount AddAccount(IUnitOfWork unitOfWork, ExtAccount newAccount) { var linkedAccounts = _extAccountService.GetLinked(unitOfWork, Ambient.AppContext.SecurityUser.ID); if (!linkedAccounts.Any(x => x.Type == newAccount.Type && x.ExternalId == newAccount.ExternalId)) { newAccount.UserID = Ambient.AppContext.SecurityUser.ID; _extAccountService.Create(unitOfWork, newAccount); } return newAccount; }
private User Authorize(ISystemUnitOfWork unitOfWork, ExtAccount extAccount) { User user = _extAccountService.GetAll(unitOfWork) .Where(x => x.Type == extAccount.Type && x.ExternalId == extAccount.ExternalId) .Select(x => x.User).FirstOrDefault(); if (user == null) { var securityUser = _securityUserService.GetSecurityUser(extAccount.Email); if (securityUser != null) { AddAccount(unitOfWork, extAccount); user = new User { Login = securityUser.Login }; } else { user = RegisterUser(unitOfWork, extAccount); } } return user; }