Esempio n. 1
0
        public object Create( AccountUser accountUser )
        {
            IProfile profile = new Profile();
            AccountUser retorno = new AccountUser();

            if( !String.IsNullOrEmpty(accountUser.CustomId) )
            {
                profile = this.model.ProfileExists(accountUser);
            }

            if( profile.UserId == 0 )
            {
                profile = this.model.CreateAccount(accountUser);
            }

            retorno = this.model.GetAccount(profile.UserId);

            var simpleResult = CleanUser(retorno);

            return simpleResult;
        }
Esempio n. 2
0
        public IProfile CreateAccount(AccountUser usuario)
        {
            IProfile result = new Profile();

            using (TransactionScope scope = new TransactionScope())
            {
                usuario.Created = DateTime.Now;
                usuario.City = Security.ClearSQLInjection(usuario.City);
                usuario.Country = Security.ClearSQLInjection(usuario.Country);
                usuario.CustomId = Security.ClearSQLInjection(usuario.CustomId);
                usuario.Email = Security.ClearSQLInjection(usuario.Email);
                usuario.Name = Security.ClearSQLInjection(usuario.Name);
                usuario.Password = Security.ClearSQLInjection(usuario.Password);
                usuario.Picture = Security.ClearSQLInjection(usuario.Picture);
                usuario.Gender = Security.ClearSQLInjection(usuario.Gender);

                string emailcrypted = Security.Encrypt(usuario.Email);
                string passw = PasswordHash.CreateHash(usuario.Password);

                usuario.Email = emailcrypted;
                usuario.Password = passw;

                IUsuario iusuario = _repository.Add(usuario);

                ProfileRepository profile = new ProfileRepository(_dataBase);
                IProfile newProfile = new Profile();
                newProfile.UserId = iusuario.UsuarioId;
                newProfile.Upadted = DateTime.Now;
                newProfile.Picture = Security.ClearSQLInjection(usuario.Picture);
                result = profile.Add(newProfile);

                scope.Complete();
            }

            return result;
        }
Esempio n. 3
0
        public IProfile GetProfile(int usuarioId)
        {
            IDataQuery query = new DataQuery();
            query.Where = string.Format("userId={0} and removed=0", usuarioId);

            IList<IProfile> result = _repositoryProfile.Find(query);
            IProfile profile = new Profile();

            if (result.Count > 0)
            {
                profile = result[0];
            }

            return profile;
        }
Esempio n. 4
0
        public IProfile ProfileExists(AccountUser usuario)
        {
            IDataQuery query = new DataQuery();
            query.Where = string.Format("customId='{0}'", Security.ClearSQLInjection(usuario.CustomId));

            IList<IUsuario> result = _repository.Find(query);
            IProfile profile = new Profile();

            if (result.Count > 0)
            {
                query.Where = string.Format("userId={0} and removed=0", result[0].UsuarioId);
                profile = _repositoryProfile.Find(query)[0];
            }

            return profile;
        }
Esempio n. 5
0
        public AccountUser GetAccount(int userId)
        {
            AccountUser retorno = new AccountUser();

            IDataQuery query = new DataQuery();
            query.Where = string.Format("usuarioId={0}", userId);
            IList<IUsuario> result = _repository.Find(query);
            IProfile profile = new Profile();
            IUsuario usuario = new Usuario();

            if (result.Count > 0)
            {
                usuario = result[0];
                query.Where = string.Format("userId={0} and removed=0", result[0].UsuarioId);
                profile = _repositoryProfile.Find(query)[0];

                retorno.Birthdate = usuario.Birthdate;
                retorno.Created = usuario.Created;
                retorno.CustomId = usuario.CustomId;
                retorno.Email = usuario.Email;
                retorno.Gender = usuario.Gender;
                retorno.Name = usuario.Name;
                retorno.UsuarioId = usuario.UsuarioId;
                retorno.City = usuario.City;
                retorno.Country = usuario.Country;

                retorno.Picture = profile.Picture;
                retorno.ProfileId = profile.ProfileId;
                retorno.UserId = profile.UserId;
            }

            return retorno;
        }