コード例 #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" }));
        }
コード例 #2
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 } }));
        }