예제 #1
0
 public ICollection<Offer> GetOffers(Int32 page, Int32 size)
 {
     using (var dataManager = factory.GetDataManager())
     {
         var repository = dataManager.GetRepository<IOfferRepository>();
         return repository.GetOffers(page, size);
     }
 }
        public string GetConnectionByCommandName(string commandName)
        {
            if (connectionStringsDictionary.ContainsKey(commandName))
            {
                return(connectionStringsDictionary[commandName]);
            }

            string ConnString;

            using (var dataManager = _factory.GetDataManager())
            {
                dataManager.CommandName = "usp_GetConnString";
                dataManager.Parameters.AddWithValue("@ProcName", commandName);

                dataManager.Connection.Open();
                ConnString = dataManager.ExecuteScalar <string>();
                dataManager.Connection.Close();
            }

            object lockobj = new object();

            lock (lockobj)
            {
                connectionStringsDictionary.Add(commandName, ConnString);
            }

            return(ConnString);
        }
예제 #3
0
        public User Validate(String login, String password)
        {
            User user;

            using (var dataManager = factory.GetDataManager())
            {
                var userRepository = dataManager.GetRepository <IUserRepository>();
                user = userRepository.GetByLogin(login);

                if (user == null)
                {
                    return(null);
                }
            }

            if (user.PasswordHash == null)
            {
                using (var dataManager = factory.GetDataManager(ConcurrencyLock.Pessimistic))
                {
                    var userRepository = dataManager.GetRepository <IUserRepository>();
                    user = userRepository.GetByLogin(login);

                    if (user == null)
                    {
                        throw new NullReferenceException(String.Format("User with login \"{0}\" not found", login));
                    }

                    if (user.PasswordHash == null)
                    {
                        user.PasswordHash = algorithm.ComputeHash(new MemoryStream(Encoding.UTF8.GetBytes(password)));
                        userRepository.Save(user);
                        dataManager.Commit();
                        return(user);
                    }
                }
            }

            return(user.PasswordHash.SequenceEqual(algorithm.ComputeHash(new MemoryStream(Encoding.UTF8.GetBytes(password)))) ? user : null);
        }
예제 #4
0
 public static DataManager GetSQLCacheDataManager()
 {
     return(sqlcacheFactory.GetDataManager());
 }
예제 #5
0
 public static DataManager GetSQLDataManager()
 {
     return(sqlFactory.GetDataManager());
 }