Esempio n. 1
0
 /// <summary>
 /// Поиск существующего и создание нового пользователя
 /// </summary>
 /// <param name="cookieUserData"></param>
 /// <param name="newUser"></param>
 /// <returns></returns>
 private User FindOrCreateUser(CookieUserData cookieUserData, out bool newUser)
 {
     using (IUnitOfWork unitOfWork = _unitOfWorkFactory.Create())
     {
         OAuthMembership oAuthMembership =
             _oAuthMembershipRepository.GetWithUser()
             .FirstOrDefault(
                 m =>
                 m.OAuthUserId == cookieUserData.OAuthUserId &&
                 m.ProviderName == cookieUserData.OAuthProviderName);
         if (oAuthMembership != null)
         {
             newUser = false;
             return(oAuthMembership.User);
         }
         User user = new User();
         user.Name = cookieUserData.UserName;
         OAuthMembership membership = new OAuthMembership();
         membership.User         = user;
         membership.ProviderName = cookieUserData.OAuthProviderName;
         membership.OAuthUserId  = cookieUserData.OAuthUserId;
         _userRepository.Create(user);
         _oAuthMembershipRepository.Create(membership);
         unitOfWork.Commit();
         newUser = true;
         return(user);
     }
 }
 /// <summary>
 /// Заполнение тестовыми данными
 /// </summary>
 private void CreateTestData()
 {
     _testOAuthMembership = new OAuthMembership()
     {
         OAuthUserId  = "TestUserId",
         ProviderName = "TestProvider",
         User         = new User {
             Name = "test1"
         }
     };
     using (IUnitOfWork unitOfWork = _unitOfWorkFactory.Create())
     {
         _userRepository.Create(_testOAuthMembership.User);
         _oAtuhMembershipRepository.Create(_testOAuthMembership);
         unitOfWork.Commit();
     }
 }