Пример #1
0
 public UnitOfWork(MyDatabase context)
 {
     this.context   = context;
     Cares          = new CareRepository.CareRepository(context);
     FaceCreams     = new FaceCreamRepository(context);
     Hairs          = new HairRepository(context);
     Lotions        = new LotionRepository(context);
     ShaveBeards    = new ShaveBeardRepository(context);
     FoodHerbs      = new FoodHerbRepository(context);
     Salts          = new SaltRepository(context);
     Spices         = new SpiceRepository(context);
     SproutingSeeds = new SproutingSeedRepository(context);
     Teas           = new TeaRepository(context);
     Candles        = new CandleRepository(context);
     EssentialOils  = new EssentialOilRepository(context);
     Homes          = new HomeRepository.HomeRepository(context);
     HomeCleanings  = new HomeCleaningRepository(context);
     Kitchens       = new KitchenRepository(context);
     PowerHealths   = new PowerHealthRepository(context);
     SuperFoods     = new SuperFoodRepository(context);
     Supplements    = new SupplementRepository.SupplementRepository(context);
     Orders         = new OrderRepository(context);
     Products       = new ProductRepository(context);
     Users          = new UserRepository(context);
 }
Пример #2
0
        public static void CadastraUsuarioDemonstracao(string nome, string email, string keyDescriptografada)
        {
            try
            {
                UsuarioRepository usuarioRepository = new UsuarioRepository();
                KeyRepository     keyRepository     = new KeyRepository();
                SaltRepository    saltRepository    = new SaltRepository();

                if (usuarioRepository.getAll().Count == 0)
                {
                    // Recupero o Salt inicial e o final
                    string salt1 = SaltService.geraSalt();
                    string salt2 = SaltService.geraSalt();

                    // Criptografo a senha
                    string KeyCriptografada = CriptografaService.GetKey(salt1, salt2, keyDescriptografada);

                    // Divido a Senha em duas partes
                    // A idéia á aumentar a segurança gravando a senha do usuário em
                    // dois locais diferentes. Preferencialmente servidores diferentes
                    string InitialKey = CriptografaService.InitialKey(KeyCriptografada);
                    string FinalKey   = CriptografaService.FinalKey(KeyCriptografada);

                    // Crio novo usuario
                    Usuario usuario = new Usuario();
                    usuario.Nome  = nome;
                    usuario.Email = email;
                    usuarioRepository.Add(usuario);

                    // Crio nova key
                    Key key = new Key();
                    key.UsuarioId = usuario.Id;
                    key.KeyString = InitialKey;
                    keyRepository.Add(key);

                    // Crio novo Salt e armazeno a parte final da key
                    Salt salt = new Salt();
                    salt.KeyId          = key.Id;
                    salt.Salt1          = salt1;
                    salt.Salt2          = salt2;
                    salt.FinalKeyString = FinalKey;

                    // A gravação do Salt e da parte final da key deveria ser realizada através
                    // de uma chamada a uma outra api, com uma credencial valida.
                    // Por motivos de tempo estou simplificando e chamando diretamente o repositório
                    saltRepository.Add(salt);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #3
0
 public static Salt GetSaltByKey(long keyId)
 {
     try
     {
         SaltRepository saltRepository = new SaltRepository();
         Salt           salt           = saltRepository.getSaltByKeyId(keyId);
         if (salt != null)
         {
             return(salt);
         }
         else
         {
             throw new Exception("Salt não localizada para a key: " + keyId);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }