Ejemplo n.º 1
0
        public HttpResponseMessage InserirCartaoCredito(HttpRequestMessage request, CartaoCreditoViewModel cartaoCreditoViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                var cartao = new CartaoCredito();

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                                      .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    var usuario = _usuarioRep.GetSingle(int.Parse(HttpContext.Current.User.Identity.GetUserId()));
                    var membro = this._membroRep.GetAll().FirstOrDefault(x => x.PessoaId.Equals(usuario.PessoaId));


                    if (cartaoCreditoViewModel.Padrao)
                    {
                        var _param = new[]
                        {
                            new SqlParameter {
                                ParameterName = "@PADRAO", SqlDbType = System.Data.SqlDbType.Bit, Value = 0
                            },
                            new SqlParameter {
                                ParameterName = "@PADRAO1", SqlDbType = System.Data.SqlDbType.Bit, Value = 1
                            }
                        };

                        var sql = "UPDATE CartaoCredito set Padrao = @PADRAO WHERE Padrao = @PADRAO1";
                        _cartaoCreditoRep.ExecuteWithStoreProcedure(sql, _param);
                        _unitOfWork.Commit();
                    }

                    if (cartaoCreditoViewModel.Id != null && cartaoCreditoViewModel.Id > 0)
                    {
                        cartao = _cartaoCreditoRep.FirstOrDefault(x => x.Id == cartaoCreditoViewModel.Id);


                        cartao.Nome = cartaoCreditoViewModel.Nome;
                        cartao.Numero = cartaoCreditoViewModel.Numero;
                        cartao.DataVencimento = Convert.ToDateTime(cartaoCreditoViewModel.DataVencimento);
                        cartao.Cvc = $"{usuario.Chave}|{_encryptionService.EncryptCvv(cartaoCreditoViewModel.Cvc)}";
                        cartao.TokenCartaoGerenciaNet = string.Empty;
                        cartao.CartaoBandeiraId = cartaoCreditoViewModel.CartaoBandeiraId;
                        cartao.Padrao = cartaoCreditoViewModel.Padrao;
                        cartao.MembroId = membro.Id;
                        cartao.Ativo = true;
                        cartao.UsuarioAlteracaoId = usuario.Id;
                        cartao.UsuarioAlteracao = usuario;
                        cartao.DtAlteracao = DateTime.Now;


                        _cartaoCreditoRep.Edit(cartao);
                        _unitOfWork.Commit();
                    }
                    else
                    {
                        cartao = new CartaoCredito
                        {
                            Nome = cartaoCreditoViewModel.Nome,
                            Numero = cartaoCreditoViewModel.Numero,
                            DataVencimento = Convert.ToDateTime(cartaoCreditoViewModel.DataVencimento),
                            CartaoBandeiraId = cartaoCreditoViewModel.CartaoBandeiraId,
                            Cvc = $"{usuario.Chave}|{_encryptionService.EncryptCvv(cartaoCreditoViewModel.Cvc)}",
                            TokenCartaoGerenciaNet = string.Empty,
                            Padrao = true,
                            MembroId = membro.Id,
                            Ativo = true,
                            UsuarioCriacaoId = usuario.Id,
                            UsuarioCriacao = usuario,
                            DtCriacao = DateTime.Now,
                        };

                        _cartaoCreditoRep.Add(cartao);
                        _unitOfWork.Commit();

                        cartaoCreditoViewModel.Id = cartao.Id;
                    }

                    response = request.CreateResponse(HttpStatusCode.Created, cartaoCreditoViewModel);
                }

                return response;
            }));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Inserir(HttpRequestMessage request, MenuViewModel menuViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                      ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                                      .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    Usuario usuario = _usuarioRep.GetSingle(int.Parse(HttpContext.Current.User.Identity.GetUserId()));

                    Menu novoMenu = new Menu
                    {
                        UsuarioCriacaoId = usuario.Id,
                        DtCriacao = DateTime.Now,
                        Ativo = menuViewModel.Ativo,
                        ModuloId = menuViewModel.ModuloId,
                        DescMenu = menuViewModel.DescMenu,
                        MenuPaiId = menuViewModel.MenuPaiId,
                        Nivel = menuViewModel.Nivel,
                        Ordem = menuViewModel.Ordem,
                        Url = menuViewModel.Url,
                        FontIcon = menuViewModel.FontIcon,
                        Feature1 = menuViewModel.Feature1,
                        Feature2 = menuViewModel.Feature2
                    };

                    var pOut = new SqlParameter
                    {
                        ParameterName = "@New_Id",
                        SqlDbType = SqlDbType.Int,
                        Direction = ParameterDirection.Output
                    };

                    var pMenuPaiId = new SqlParameter
                    {
                        ParameterName = "@MenuPaiId",
                        SqlDbType = SqlDbType.Int,
                        Value = novoMenu.MenuPaiId
                    };

                    if (novoMenu.MenuPaiId == 0)
                    {
                        pMenuPaiId.Value = DBNull.Value;
                    }

                    var pUrl = new SqlParameter
                    {
                        ParameterName = "@Url",
                        SqlDbType = SqlDbType.VarChar,
                        Value = novoMenu.Url
                    };

                    if (novoMenu.Url == null)
                    {
                        pUrl.Value = DBNull.Value;
                    }

                    var pFontIcon = new SqlParameter
                    {
                        ParameterName = "@FontIcon",
                        SqlDbType = SqlDbType.VarChar,
                        Value = novoMenu.FontIcon
                    };

                    if (novoMenu.FontIcon == null)
                    {
                        pFontIcon.Value = DBNull.Value;
                    }

                    var pFeature1 = new SqlParameter
                    {
                        ParameterName = "@Feature1",
                        SqlDbType = SqlDbType.VarChar,
                        Value = novoMenu.Feature1
                    };

                    if (novoMenu.Feature1 == null)
                    {
                        pFeature1.Value = DBNull.Value;
                    }

                    var pFeature2 = new SqlParameter
                    {
                        ParameterName = "@Feature2",
                        SqlDbType = SqlDbType.VarChar,
                        Value = novoMenu.Feature2
                    };

                    if (novoMenu.Feature2 == null)
                    {
                        pFeature2.Value = DBNull.Value;
                    }

                    _menuRep.ExecuteWithStoreProcedure("stp_ins_menu @UsuarioCriacaoId, @DtCriacao, @Ativo, @MenuPaiId, @ModuloId, " +
                                                       "@DescMenu, @Nivel, @Ordem, @Url, @FontIcon, @Feature1, @Feature2, @New_Id out",
                                                       new SqlParameter("@UsuarioCriacaoId", novoMenu.UsuarioCriacaoId),
                                                       new SqlParameter("@DtCriacao", novoMenu.DtCriacao),
                                                       new SqlParameter("@Ativo", novoMenu.Ativo == true ? '1' : '0'),
                                                       pMenuPaiId,
                                                       new SqlParameter("@ModuloId", novoMenu.ModuloId),
                                                       new SqlParameter("@DescMenu", novoMenu.DescMenu),
                                                       new SqlParameter("@Nivel", novoMenu.Nivel),
                                                       new SqlParameter("@Ordem", novoMenu.Ordem),
                                                       pUrl,
                                                       pFontIcon,
                                                       pFeature1,
                                                       pFeature2,
                                                       pOut
                                                       );

                    // Update view model
                    novoMenu.Id = Convert.ToInt32(pOut.Value.TryParseInt());
                    menuViewModel = Mapper.Map <Menu, MenuViewModel>(novoMenu);
                    response = request.CreateResponse(HttpStatusCode.Created, menuViewModel);
                }

                return response;
            }));
        }
        public GeraCotacaoViewModel GeraCotacaoPedidos()
        {
            GeraCotacaoViewModel cotacao = new GeraCotacaoViewModel();

            var statusId   = _statusSisRep.FirstOrDefault(x => x.WorkflowStatusId == 14 && x.Ordem == 1).Id;
            var qtdPedidos = _pedidoRep.GetAll().Count(x => !x.FlgCotado && x.DtCotacao <= DateTime.Now);


            if (qtdPedidos > 0)
            {
                var pOut = new SqlParameter
                {
                    ParameterName = "@cotacaoId",
                    SqlDbType     = SqlDbType.Int,
                    Direction     = ParameterDirection.Output
                };

                _pedidoRep.ExecuteWithStoreProcedure("stp_upd_pedidos_sem_cotar @cotacaoId out", pOut);


                //Resgata ID da cotação inserida
                var cotacaoID = Convert.ToInt32(pOut.Value);

                //Historico de Cotação
                var cotacaoHistorico = new HistStatusCotacao
                {
                    Ativo            = true,
                    CotacaoId        = cotacaoID,
                    DtCriacao        = DateTime.Now,
                    UsuarioCriacaoId = 1,
                    StatusSistemaId  = statusId
                };
                _histStatusCotacaoRep.Add(cotacaoHistorico);

                var cot          = _cotacaoRep.GetSingle(cotacaoID);
                var naService    = new NotificacoesAlertasService();
                var listaUsuario = naService.TrataNovaCotacaoFornecedor(cot, (int)TipoAviso.NovaCotacao);

                foreach (var retAviso in listaUsuario)
                {
                    var aviso = new Avisos
                    {
                        UsuarioCriacaoId    = 1,
                        DtCriacao           = DateTime.Now,
                        Ativo               = true,
                        IdReferencia        = cot.Id,
                        DataUltimoAviso     = DateTime.Now,
                        ExibeNaTelaAvisos   = true,
                        TipoAvisosId        = (int)TipoAviso.NovaCotacao, //Id TipoAviso para esse aviso
                        URLPaginaDestino    = "/#/cotacoes",
                        TituloAviso         = "Cotação Pendente de Resposta",
                        ToolTip             = "Cotação Pendente de Resposta",
                        DescricaoAviso      = "Cotação " + cot.Id + " Pendente de Resposta",
                        ModuloId            = 4, //Modulo Fornecedor
                        UsuarioNotificadoId = retAviso.Usuario.Id
                    };

                    _avisosRep.Add(aviso);
                }

                _unitOfWork.Commit();

                var usuarios   = listaUsuario.Select(x => x.Usuario).Distinct();
                var listaToken = usuarios.Select(x => x.TokenSignalR).ToList();

                cotacao.CotacaoId          = cot.Id;
                cotacao.ListaTokenUsuarios = listaToken;

                return(cotacao);
            }

            return(cotacao);
        }