Esempio n. 1
0
        public static OperationStatus CreateFromException(string message, Exception ex)
        {
            OperationStatus opStatus = new OperationStatus
            {
                Success = true,
                Messages = new List<string>(),
            };

            if (ex != null)
            {
                opStatus.Messages.Add(ex.Message);
                opStatus.Success = false;
            }
            return opStatus;
        }
        public OperationStatus CrearAnuncio(string titulo, string descripcion)
        {
            try
            {
                //Aptitud aptitudesExistentes = AptitudDAO.ListarTodos;
                Anuncio anuncioCrear = new Anuncio()
                {
                    Titulo = titulo,
                    Descripcion = descripcion,
                };

                var validationContext = new ValidationContext(anuncioCrear, serviceProvider: null, items: null);
                var validationResults = new List<ValidationResult>();

                var isValid = Validator.TryValidateObject(anuncioCrear, validationContext, validationResults, true);

                if (!isValid)
                {
                    OperationStatus opStatus = new OperationStatus();
                    opStatus.Success = false;

                    foreach (ValidationResult message in validationResults)
                    {
                        opStatus.Messages.Add(message.ErrorMessage);
                    }

                    return opStatus;
                }
                else
                {
                    AnuncioDAO.Crear(anuncioCrear);
                    return new OperationStatus { Success = true };
                }
            }
            catch (Exception e)
            {
                return OperationStatus.CreateFromException("Al crear el anuncio.", e);
            }
        }
        public OperationStatus CrearPostulante(string nombre, string apellidoPaterno, string apellidoMaterno, DateTime fechaNacimiento, string email, string dni,string clave)
        {
            try
            {
                //Rubro rubroExistente = RubroDAO.Obtener(idRubro);
                Postulante postulanteCrear = new Postulante()
                {
                    nombre = nombre,
                    apellidoPaterno = apellidoPaterno,
                    apellidoMaterno = apellidoMaterno,
                    fechaNacimiento = fechaNacimiento,
                    email = email,
                    dni = dni,
                    clave = clave
                };

                var validationContext = new ValidationContext(postulanteCrear, serviceProvider: null, items: null);
                var validationResults = new List<ValidationResult>();

                var isValid = Validator.TryValidateObject(postulanteCrear, validationContext, validationResults, true);

                if (!isValid)
                {
                    OperationStatus opStatus = new OperationStatus();
                    opStatus.Success = false;

                    foreach (ValidationResult message in validationResults)
                    {
                        opStatus.Messages.Add(message.ErrorMessage);
                    }

                    return opStatus;
                }
                else
                {
                    PostulanteDAO.Crear(postulanteCrear);
                    return new OperationStatus { Success = true };
                }
            }
            catch (Exception e)
            {
                return OperationStatus.CreateFromException("Al crear al postulante.", e);
            }
        }
        public OperationStatus CrearEmpresa(string email, string clave, string razonSocial, string numeroRuc, int idRubro)
        {
            try
            {
                Rubro rubroExistente = RubroDAO.Obtener(idRubro);
                Empresa empresaCrear = new Empresa()
                {
                    EmailContacto = email,
                    Clave = clave,
                    RazonSocial = razonSocial,
                    NumeroRuc = numeroRuc,
                    Rubro = rubroExistente
                };

                var validationContext = new ValidationContext(empresaCrear, serviceProvider: null, items: null);
                var validationResults = new List<ValidationResult>();

                var isValid = Validator.TryValidateObject(empresaCrear, validationContext, validationResults, true);

                if (!isValid)
                {
                    OperationStatus opStatus = new OperationStatus();
                    opStatus.Success = false;

                    foreach (ValidationResult message in validationResults)
                    {
                        opStatus.Messages.Add(message.ErrorMessage);
                    }

                    return opStatus;
                }
                else
                {
                    EmpresaDAO.Crear(empresaCrear);
                    return new OperationStatus { Success = true };
                }
            }
            catch (Exception e)
            {
                return OperationStatus.CreateFromException("Al crear la empresa.", e);
            }
        }