Exemple #1
0
        public ActionResult Cadastrar(EmpresaViewModel empresa)
        {
            if (_empresaAppService.ObterPorRazaoSocial(empresa.RazaoSocial).FirstOrDefault() == null)
            {
                _empresaAppService.Adicionar(empresa);

                var dataVencimento = DateTime.Now;
                if (dataVencimento.Day < empresa.DiaVencimento)
                {
                    dataVencimento = new DateTime(dataVencimento.Year, dataVencimento.Month, empresa.DiaVencimento) + new TimeSpan(23, 59, 59);
                }
                else if (dataVencimento.Day >= empresa.DiaVencimento)
                {
                    dataVencimento = new DateTime(dataVencimento.AddMonths(1).Year, dataVencimento.AddMonths(1).Month, empresa.DiaVencimento) + new TimeSpan(23, 59, 59);
                }
                var competenciaAberta = new CompetenciaAberturaViewModel
                {
                    DataVencimento = dataVencimento,
                    EmpresaId      = empresa.Id
                };
                _competenciaAbertaAppService.Adicionar(competenciaAberta);
                return(RedirectToAction("Index"));
            }

            ViewBag.Error         = true;
            ViewBag.ErrorMensager = "Razão social já está sendo usada.";
            return(View());
        }
Exemple #2
0
        public ActionResult Encerrar(CompetenciaAberturaViewModel competenciaAbertaId)
        {
            var competenciaAberta = _competenciaAbertaAppService.ObterPorId(competenciaAbertaId.Id);

            if (competenciaAberta == null)
            {
                return(HttpNotFound());
            }

            competenciaAberta.CompetenciasFechada = EncerrarCompetenciaAberta(competenciaAberta);

            _competenciaFechadaAppService.Adicionar(competenciaAberta.CompetenciasFechada);
            var novaCompetenciaAberta = new CompetenciaAberturaViewModel
            {
                DataVencimento = competenciaAberta.DataVencimento.AddMonths(1),
                EmpresaId      = competenciaAberta.EmpresaId
            };

            _competenciaAbertaAppService.Adicionar(novaCompetenciaAberta);
            return(RedirectToAction("Fechadas"));
        }