Example #1
0
        public async Task <string> AlterarAsync(FechamentoReabertura fechamentoReabertura, DateTime dataInicialAnterior, DateTime dataFimAnterior, bool confirmacacaoAlteracaoHierarquica)
        {
            var fechamentoReaberturas = await repositorioFechamentoReabertura.Listar(fechamentoReabertura.TipoCalendarioId, null, null, null);

            var fechamentoReaberturasParaVerificar = fechamentoReaberturas.Where(a => a.Id != fechamentoReabertura.Id);
            var fechamentoReaberturasParaAtualizar = fechamentoReaberturasParaVerificar.Where(a => fechamentoReabertura.Inicio > a.Inicio || a.Fim > fechamentoReabertura.Fim);

            var usuarioAtual = await servicoUsuario.ObterUsuarioLogado();

            fechamentoReabertura.PodeSalvar(fechamentoReaberturasParaVerificar, usuarioAtual);

            fechamentoReabertura.VerificaStatus();

            unitOfWork.IniciarTransacao();

            var fechamentoReaberturaId = await repositorioFechamentoReabertura.SalvarAsync(fechamentoReabertura);

            var mensagemRetorno = "Reabertura de Fechamento alterado com sucesso.";

            if (fechamentoReabertura.Status == EntidadeStatus.AguardandoAprovacao)
            {
                fechamentoReabertura.WorkflowAprovacaoId = PersistirWorkflowFechamentoReabertura(fechamentoReabertura);
                await repositorioFechamentoReabertura.SalvarAsync(fechamentoReabertura);

                mensagemRetorno = "Reabertura de Fechamento alterado e será válido após aprovação.";
            }

            await VerificaEAtualizaFechamentosReaberturasParaAlterar(fechamentoReabertura, fechamentoReaberturasParaAtualizar, confirmacacaoAlteracaoHierarquica);

            unitOfWork.PersistirTransacao();

            return(mensagemRetorno);
        }
        public async Task <string> Excluir(long[] ids)
        {
            var Mensagens = new List <string>();

            var fechamentos = await repositorioFechamentoReabertura.Listar(0, 0, 0, ids);

            if (fechamentos == null || !fechamentos.Any())
            {
                throw new NegocioException("Não foram localizados fechamento(s) válido(s) para exclusão.");
            }
            else
            {
                foreach (var fechamento in fechamentos)
                {
                    var mensagem = await servicoFechamentoReabertura.ExcluirAsync(fechamento);

                    if (!string.IsNullOrEmpty(mensagem))
                    {
                        Mensagens.Add(mensagem);
                    }
                }
            }

            return(string.Join(" <br />", Mensagens));
        }