Esempio n. 1
0
        public ProcessResult <object> EliminarIndicadorValor(IndicadorValorRequest data)
        {
            ProcessResult <object> resultado = new ProcessResult <object>();

            resultado.Result = string.Empty;
            try
            {
                IndicadorValorEntity oIndicadorValorEntity = indicadorValorEntityRepository.GetById(data.CodigoIndicadorValor);

                if (oIndicadorValorEntity != null)
                {
                    indicadorValorEntityRepository.Eliminar(oIndicadorValorEntity.CodigoIndicadorValor);
                    resultado.IsSuccess = true;
                    indicadorValorEntityRepository.GuardarCambios();
                }
            }
            catch (Exception ex)
            {
                resultado.Exception = new ApplicationLayerException <AreaService>(ex.Message);
            }
            return(resultado);
        }
Esempio n. 2
0
        public ProcessResult <IndicadorValorResponse> RegistrarIndicadorValor(IndicadorValorRequest data)
        {
            ProcessResult <IndicadorValorResponse> resultado = new ProcessResult <IndicadorValorResponse>();

            resultado.Result = new IndicadorValorResponse();
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    IndicadorValorEntity indicadorValorSincronizar = indicadorValorEntityRepository.GetById(data.CodigoIndicadorValor);
                    IndicadorValorEntity indicadorValorGeneral     = Mapper.Map <IndicadorValorRequest, IndicadorValorEntity>(data);

                    var indicadorValor = BuscarIndicadorValor(data);

                    if (indicadorValor.Result.Count > 0)
                    {
                        for (int i = 0; i < indicadorValor.Result.Count; i++)
                        {
                            if (indicadorValor.Result[0].EstadoRegistro == DatosConstantes.EstadoRegistro.Activo)
                            {
                                resultado.IsSuccess = false;
                                resultado.Exception = new ApplicationLayerException <IndicadorMetaService>(MensajesSistemaResource.ViolacionRegistro);
                                break;
                            }
                            else
                            {
                                if (indicadorValorSincronizar != null)
                                {
                                    Mapper.Map <IndicadorValorEntity, IndicadorValorEntity>(indicadorValorGeneral, indicadorValorSincronizar);
                                    indicadorValorEntityRepository.Editar(indicadorValorSincronizar);
                                    resultado.Result.CodigoIndicadorValor = data.CodigoIndicadorValor;
                                    resultado.Result.CodigoIndicador      = data.CodigoIndicador;
                                }
                                else
                                {
                                    indicadorValorEntityRepository.Insertar(indicadorValorGeneral);
                                    bool registroExitoso = resultado.IsSuccess;
                                    if (!registroExitoso)
                                    {
                                        resultado.IsSuccess = false;
                                        resultado.Exception = new ApplicationLayerException <IndicadorValorService>(MensajesSistemaResource.EtiquetaError);
                                    }
                                    resultado.Result.CodigoIndicadorValor = indicadorValorGeneral.CodigoIndicadorValor;
                                    resultado.Result.CodigoIndicador      = indicadorValorGeneral.CodigoIndicador;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (indicadorValorSincronizar != null)
                        {
                            Mapper.Map <IndicadorValorEntity, IndicadorValorEntity>(indicadorValorGeneral, indicadorValorSincronizar);
                            indicadorValorEntityRepository.Editar(indicadorValorSincronizar);
                            resultado.Result.CodigoIndicadorValor = data.CodigoIndicadorValor;
                            resultado.Result.CodigoIndicador      = data.CodigoIndicador;
                        }
                        else
                        {
                            indicadorValorEntityRepository.Insertar(indicadorValorGeneral);
                            bool registroExitoso = resultado.IsSuccess;
                            if (!registroExitoso)
                            {
                                resultado.IsSuccess = false;
                                resultado.Exception = new ApplicationLayerException <IndicadorValorService>(MensajesSistemaResource.EtiquetaError);
                            }
                            resultado.Result.CodigoIndicadorValor = indicadorValorGeneral.CodigoIndicadorValor;
                            resultado.Result.CodigoIndicador      = indicadorValorGeneral.CodigoIndicador;
                        }
                    }
                    indicadorValorEntityRepository.GuardarCambios();
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                resultado.IsSuccess = false;
                resultado.Exception = new ApplicationLayerException <IndicadorValorService>(ex.Message);
            }
            return(resultado);
        }