Beispiel #1
0
        public async Task <IActionResult> Put(string id, [FromBody] PropostaSituacaoModel model)
        {
            if (string.IsNullOrEmpty(model.Status.ToString()))
            {
                return(BadRequest(new { Response = "Não foi possivel aprovar a proposta" }));
            }
            if (string.IsNullOrEmpty(model.UsuarioId.ToString()))
            {
                return(BadRequest(new { Response = "Não foi possivel aprovar a proposta" }));
            }
            var  pb         = new PropostaBusiness(Context);
            Guid propsotaId = Guid.Parse(id);

            if (!pb.propostaIsValid(propsotaId))
            {
                return(BadRequest(new { Response = "Não foi possivel aprovar a proposta" }));
            }
            var proposta = pb.GetPropostaValida(propsotaId);

            var usuario = await pb.getUsuarioLogado(model.UsuarioId);

            proposta.Status = (pb.getPermissaoUsuarioLogado().Nivel.Equals(4))?  (PropostaStatus)4 : (PropostaStatus)2;

            var propostaHistorico = new PropostaHistorico(proposta, usuario);
            await Context.PropostasHistoricos.AddAsync(propostaHistorico);

            Context.Propostas.Update(proposta);
            await Context.SaveChangesAsync();

            MemoryCache.Remove("propostas");

            return(Ok(new { ok = true, Response = "Proposta Aprovada" }));
        }
        private void checaExistenciaDePropostasExpiradas()
        {
            var  pb        = new PropostaBusiness();
            var  propostas = Context.Propostas.Where(x => x.Status != (PropostaStatus)Enum.ToObject(typeof(PropostaStatus), 3) || x.Status != (PropostaStatus)Enum.ToObject(typeof(PropostaStatus), 1) && !x.Excluido);
            bool salvar    = false;

            foreach (var proposta in propostas)
            {
                var  usuario = Context.Usuarios.FirstOrDefault(x => x.UsuarioPermissoes.Permissoes.Nivel.Equals(1));
                bool valida  = (!Context.PropostasHistoricos.Any(x => proposta.Id == x.PropostaId && x.PropostaStatus == (PropostaStatus)3 || x.PropostaStatus == (PropostaStatus)2));
                if (valida && pb.validaSePropsotaExpirou(proposta))
                {
                    salvar          = true;
                    proposta.Status = (PropostaStatus)3;
                    var propostaHistorico = new PropostaHistorico(proposta, usuario);
                    Context.PropostasHistoricos.Add(propostaHistorico);
                    Context.Propostas.Update(proposta);
                }
            }
            if (salvar)
            {
                MemoryCache.Remove("propostas");
                Context.SaveChanges();
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Post([FromBody] PropostaSituacaoModel model)
        {
            var id = model.Id;

            if (string.IsNullOrEmpty(model.Status.ToString()))
            {
                return(BadRequest(new { Response = "Não foi possivel cadastar a proposta" }));
            }
            if (string.IsNullOrEmpty(model.UsuarioId.ToString()))
            {
                return(BadRequest(new { Response = "Não foi possivel cadastar a proposta" }));
            }
            var pb            = new PropostaBusiness(Context);
            var proposta      = new Proposta();
            var usuarioLogado = await pb.getUsuarioLogado(model.UsuarioId);

            var status = (PropostaStatus)Enum.ToObject(typeof(PropostaStatus), proposta.Status);

            proposta = await Context.Propostas.FirstOrDefaultAsync(x => x.Id == Guid.Parse(id));

            var propSituacao = pb.validate(proposta, usuarioLogado, status);

            var usuario = new NovoUsuarioModel()
            {
                Email         = usuarioLogado.Email,
                Nome          = usuarioLogado.Nome,
                PermissaoId   = pb.getPermissaoUsuarioLogado().Id,
                Perfil        = pb.getPermissaoUsuarioLogado().Nivel,
                DataNacimento = usuarioLogado.DataNacimento
            };

            MemoryCache.Remove("propostas");

            return(Ok(new { Ok = true, Response = new { propSituacao, usuario } }));
        }