public void Validar(adduohelper.envelopes.RequestEnvelope <dto.entries.UsuarioAtualizacao> request)
        {
            if (request.Item.UsuarioId == Guid.Empty)
            {
                throw new Exception("UsuarioId vazio");
            }

            if (request.Item.EmpresaId == Guid.Empty)
            {
                throw new Exception("EmpresaId vazio");
            }

            request.Item.Apelido.AddValidation(new ApelidoEntryValidator(servico, request.Item.EmpresaId, request.Item.UsuarioId));

            request.Item.Validate();

            if (request.Item.AnyIsInvalid())
            {
                var response = request.CreateResponse();

                response.HttpStatusCode = HttpStatusCode.BadRequest;

                throw new EntriesException <dto.entries.UsuarioAtualizacao>(response);
            }
        }
        private void ThrowArgumentException(ArgumentException ex, adduohelper.envelopes.RequestEnvelope <T> request)
        {
            var response = request.CreateResponse();

            if (ex.Message == "Password must be at least 6 characters long.")
            {
                response.Item.Senha.Status = adduohelper.entries.STATUS.INVALID;
                response.Item.Senha.Code   = adduohelper.entries.CODE.INVALID;
                response.HttpStatusCode    = HttpStatusCode.BadRequest;
            }

            Throw(response);
        }
        private void ThrowFirebaseAuthException(FirebaseAuthException ex, adduohelper.envelopes.RequestEnvelope <T> request)
        {
            var response = request.CreateResponse();

            if (ex.ErrorCode == FirebaseAdmin.ErrorCode.AlreadyExists)
            {
                response.Item.Email.Status = adduohelper.entries.STATUS.INVALID;
                response.Item.Email.Code   = adduohelper.entries.CODE.ALREADY;
                response.HttpStatusCode    = HttpStatusCode.Conflict;
            }
            else if (ex.ErrorCode == FirebaseAdmin.ErrorCode.NotFound)
            {
                response.HttpStatusCode = HttpStatusCode.NotFound;
            }

            Throw(response);
        }
Exemple #4
0
        public adduohelper.envelopes.ResponseEnvelope <dto.Perfil> Registrar(adduohelper.envelopes.RequestEnvelope <dto.Perfil> request)
        {
            var response = request.CreateResponse();

            var perfil = request.Item;

            ValidarRegistrar(perfil);

            perfil.Ativo        = true;
            perfil.DataCadastro = corehelper.DateTimeHelper.Now();

            ProcessarToken(perfil);

            repositorio.Registrar(perfil);

            rtdbAtividadeClient.RegistrarPerfil(perfil.UsuarioId);

            response.HttpStatusCode = HttpStatusCode.Created;

            return(response);
        }
        public adduohelper.envelopes.ResponseEnvelope <dto.entries.UsuarioAtualizacao> Atualizar(adduohelper.envelopes.RequestEnvelope <dto.entries.UsuarioAtualizacao> request)
        {
            var response = request.CreateResponse();

            try
            {
                validador.Validar(request);

                registroFirebase.Atualizar(request);

                var usuario = new dto.Usuario
                {
                    Id        = request.Item.UsuarioId,
                    EmpresaId = request.Item.EmpresaId,
                    Nome      = request.Item.Nome.Value,
                    Apelido   = request.Item.Apelido.Value,
                    Email     = request.Item.Email.Value
                };

                repositorio.Atualizar(usuario);
            }
            catch (EntriesException <dto.entries.UsuarioAtualizacao> entriesEx)
            {
                // ## TODO LOG

                response = entriesEx.ResponseEnvelope;
            }
            catch (Exception ex)
            {
                // ## TODO LOG

                response.HttpStatusCode = HttpStatusCode.InternalServerError;
            }

            return(response);
        }
        public adduohelper.envelopes.ResponseEnvelope <dto.entries.UsuarioRegistro> Registrar(adduohelper.envelopes.RequestEnvelope <dto.entries.UsuarioRegistro> request)
        {
            var response = request.CreateResponse();

            var id = Guid.NewGuid();

            try
            {
                request.Item.UsuarioId = id;

                validador.Validar(request);

                registroFirebase.Registrar(request);

                var usuario = new dto.Usuario
                {
                    Id           = request.Item.UsuarioId,
                    EmpresaId    = request.Item.EmpresaId,
                    Nome         = request.Item.Nome.Value,
                    Apelido      = request.Item.Apelido.Value,
                    Email        = request.Item.Email.Value,
                    DataCadastro = DateTimeHelper.Now()
                };

                var classificadorRequest = new adduohelper.envelopes.RequestEnvelope <dto.Usuario>(usuario);

                var tasks = new List <Task>();

                tasks.Add(Task.Run(() =>
                {
                    classificador.Registrar(classificadorRequest);
                }));

                tasks.Add(Task.Run(() =>
                {
                    repositorio.Registrar(usuario);
                }));

                tasks.Add(Task.Run(() =>
                {
                    iniciadorFirebase.Iniciar(id);
                }));

                Task.WaitAll(tasks.ToArray());
            }
            catch (EntriesException <dto.entries.UsuarioRegistro> entriesEx)
            {
                // ## TODO LOG

                rollback.Rollback(id);
                response = entriesEx.ResponseEnvelope;
            }
            catch (GRPCException grpcEx)
            {
                // ## TODO LOG

                rollback.Rollback(id);
                response.HttpStatusCode = grpcEx.HttpStatusCode;
            }
            catch (Exception ex)
            {
                // ## TODO LOG

                rollback.Rollback(id);
                response.HttpStatusCode = HttpStatusCode.InternalServerError;
            }

            return(response);
        }