public GC_PagSeguroPagamento Post([FromBody] dynamic value)
        {
            Int32          idMensalidade = Convert.ToInt32(value.Id);
            GC_Mensalidade oMensalidade  = new GC_Mensalidade();

            oMensalidade = (from item in db.GC_Mensalidade
                            where item.Id == idMensalidade
                            select item).FirstOrDefault();

            GC_Academia oGC_Academia = (from item in db.GC_Academia
                                        where oMensalidade.GC_AcademiaId == item.Id
                                        select item).FirstOrDefault();

            GC_Usuario oGC_Usuario = (from item in db.GC_Usuario
                                      where item.Id == oMensalidade.GC_UsuarioId
                                      select item).FirstOrDefault();

            GC_PagSeguroPagamento oPagSeguroPagamento = new Pagseguro().Checkout(oMensalidade, oGC_Usuario, oGC_Academia, value.token.ToString(), value.senderHash.ToString());

            oPagSeguroPagamento.GC_MensalidadeId = idMensalidade;

            db.GC_PagSeguroPagamento.Add(oPagSeguroPagamento);
            oMensalidade.GC_MensalidadeStatusId = 2;

            db.SaveChanges();



            oPagSeguroPagamento.GC_MensalidadeId = oMensalidade.GC_AcademiaId;

            return(oPagSeguroPagamento);
        }
Ejemplo n.º 2
0
        public Boolean Post([FromBody] List <GC_Mensalidade> value)
        {
            value = value.OrderBy(x => x.Vencimento).ToList <GC_Mensalidade>();

            List <GC_PagSeguroPagamento> lstGC_PagSeguroPagamento = new GeradorBoleto().GerarBoletos(value);

            Int32      UsuarioId   = value[0].GC_UsuarioId;
            GC_Usuario oGC_Usuario = (from item in this.db.GC_Usuario
                                      where item.Id == UsuarioId
                                      select item).FirstOrDefault();


            if (lstGC_PagSeguroPagamento == null || lstGC_PagSeguroPagamento.Count == 0)
            {
                return(false);
            }

            for (int i = 0; i < value.Count; i++)
            {
                lstGC_PagSeguroPagamento[i].GC_MensalidadeId = value[i].Id;
            }

            db.GC_PagSeguroPagamento.AddRange(lstGC_PagSeguroPagamento);
            db.SaveChangesAsync();
            return(true);
        }
        public bool Post([FromBody] GC_Mensalidade value)
        {
            value = (from item in db.GC_Mensalidade
                     where item.Id == value.Id
                     select item).FirstOrDefault();

            GC_Usuario oGC_Usuario = (from item in db.GC_Usuario
                                      where item.Id == value.GC_UsuarioId
                                      select item).FirstOrDefault();

            GC_Academia OGC_Academia = (from item in db.GC_Academia
                                        where item.Id == value.GC_AcademiaId
                                        select item).FirstOrDefault();


            GC_PagSeguroPagamento oGC_PagSeguroPagamento = (from item in db.GC_PagSeguroPagamento
                                                            where item.GC_MensalidadeId == value.Id
                                                            select item).FirstOrDefault();

            if (oGC_Usuario.Telefone == null)
            {
                return(false);
            }

            String message = "Olá {0}! Seu boleto com vencimento para {1} referente a academia {3} pode ser impresso em {2}";

            message = message.Replace("{0}", oGC_Usuario.Nome);
            message = message.Replace("{1}", value.Vencimento.ToString("dd/MM/yyyy"));
            message = message.Replace("{2}", "http://basicflux.com/#/eu");
            message = message.Replace("{3}", OGC_Academia.Nome);

            new PapoSms().EnviarMensalidade(oGC_Usuario.Telefone, message);
            return(true);
        }
        public Boolean Post([FromBody] dynamic value)
        {
            Int32 GC_AcademiaId = value.GC_AcademiaId;
            Int32 GC_UsuarioId  = value.GC_UsuarioId;


            GC_Academia oGC_Academia = (from item in this.db.GC_Academia
                                        where item.Id == GC_AcademiaId
                                        select item).FirstOrDefault();

            if (oGC_Academia == null)
            {
                return(false);
            }

            GC_Usuario oGC_Usuario = (from item in this.db.GC_Usuario
                                      where item.Id == GC_UsuarioId
                                      select item).FirstOrDefault();

            if (oGC_Usuario == null)
            {
                return(false);
            }

            oGC_Academia.Usuarios = new Collection <GC_Usuario>();
            oGC_Academia.Usuarios.Add(oGC_Usuario);
            db.SaveChangesAsync();
            return(true);
        }
Ejemplo n.º 5
0
        public Boolean Post([FromBody] dynamic value)
        {
            Int32 oGC_UsuarioId     = value.GC_UsuarioId;
            Int32 oGC_MensalidadeId = value.GC_MensalidadeId;

            GC_Usuario oGC_Usuario = (from item in this.db.GC_Usuario
                                      where item.Id == oGC_UsuarioId
                                      select item).FirstOrDefault();

            if (oGC_Usuario == null)
            {
                return(false);
            }

            GC_Mensalidade oGC_Mensalidade = (from item in this.db.GC_Mensalidade
                                              where item.Id == oGC_MensalidadeId
                                              select item).FirstOrDefault();

            if (oGC_Mensalidade == null)
            {
                return(false);
            }

            oGC_Usuario.Mensalidades = new Collection <GC_Mensalidade>();
            oGC_Usuario.Mensalidades.Add(oGC_Mensalidade);


            db.SaveChangesAsync();
            new MensalidadeLogger().Log(oGC_Mensalidade, (ClaimsIdentity)User.Identity, "Criada pelo usuario");

            return(true);
        }
Ejemplo n.º 6
0
        public Boolean Post([FromBody] GC_Usuario gC_Usuario)
        {
            List <GC_Usuario> lst = (from item in db.GC_Usuario
                                     where (item.CPF == gC_Usuario.CPF ||
                                            item.Email == gC_Usuario.Email ||
                                            item.Login == gC_Usuario.Login) && item.IsActive && item.Id != gC_Usuario.Id
                                     select item).ToList();

            if (lst.Count > 0)
            {
                throw new Exception("Dados Duplicados");
            }


            GC_Usuario oGC_Usuario = (from item in db.GC_Usuario
                                      where item.Id == gC_Usuario.Id
                                      select item).FirstOrDefault();

            oGC_Usuario.Login    = gC_Usuario.Login;
            oGC_Usuario.CPF      = gC_Usuario.CPF;
            oGC_Usuario.Nome     = gC_Usuario.Nome;
            oGC_Usuario.Email    = gC_Usuario.Email;
            oGC_Usuario.Senha    = gC_Usuario.Senha;
            oGC_Usuario.Telefone = gC_Usuario.Telefone;

            db.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 7
0
        public GC_Usuario Post([FromBody] GC_Usuario value)
        {
            GC_Usuario oGC_Usuario = (from item in this.db.GC_Usuario
                                      where item.Senha == value.Senha && (item.Email == value.Email || item.Login == value.Login) && item.IsActive
                                      select item).FirstOrDefault();

            return(oGC_Usuario);
        }
        public GC_Usuario Post([FromBody] GC_Usuario value)
        {
            // busca usuario
            GC_Usuario oGC_Usuario = (from item in db.GC_Usuario
                                      where item.CPF == value.CPF
                                      select item).FirstOrDefault();

            return(oGC_Usuario);
        }
Ejemplo n.º 9
0
        public async Task <IHttpActionResult> GetGC_Usuario(int id)
        {
            GC_Usuario gC_Usuario = await db.GC_Usuario.FindAsync(id);

            if (gC_Usuario == null)
            {
                return(NotFound());
            }

            return(Ok(gC_Usuario));
        }
Ejemplo n.º 10
0
        public List <GC_Mensalidade> Post([FromBody] GC_Usuario value)
        {
            GC_Usuario oGC_Usuario = (from item in this.db.GC_Usuario
                                      where item.Id == value.Id && item.IsActive
                                      select item).FirstOrDefault();

            this.db.Entry(oGC_Usuario).Collection(b => b.Mensalidades).Load();
            return((from item in oGC_Usuario.Mensalidades
                    where item.IsActive
                    select item).OrderBy(x => x.Vencimento).ToList <GC_Mensalidade>());
        }
        public Boolean Post([FromBody] GC_Usuario gC_Usuario)
        {
            GC_Usuario oGC_Usuario = (from item in db.GC_Usuario
                                      where item.Id == gC_Usuario.Id
                                      select item).FirstOrDefault();

            oGC_Usuario.IsActive = false;

            db.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 12
0
        public async Task <IHttpActionResult> DeleteGC_Usuario(int id)
        {
            GC_Usuario gC_Usuario = await db.GC_Usuario.FindAsync(id);

            if (gC_Usuario == null)
            {
                return(NotFound());
            }

            db.GC_Usuario.Remove(gC_Usuario);
            await db.SaveChangesAsync();

            return(Ok(gC_Usuario));
        }
        public override Task GrantClientCredentials(OAuthGrantClientCredentialsContext context)
        {
            GC_Usuario oGC_Usuario = (from item in this.db.GC_Usuario
                                      where (item.Email == context.ClientId || item.Login == context.ClientId) && item.IsActive
                                      select item).FirstOrDefault();
            var oAuthIdentity = new ClaimsIdentity(context.Options.AuthenticationType);

            oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, oGC_Usuario.Nome));
            oAuthIdentity.AddClaim(new Claim(ClaimTypes.Sid, oGC_Usuario.Id.ToString()));

            var ticket = new AuthenticationTicket(oAuthIdentity, new AuthenticationProperties());

            context.Validated(ticket);
            return(base.GrantClientCredentials(context));
        }
Ejemplo n.º 14
0
        public async Task <IHttpActionResult> PutGC_Usuario(int id, GC_Usuario gC_Usuario)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != gC_Usuario.Id)
            {
                return(BadRequest());
            }

            List <GC_Usuario> lst = (from item in db.GC_Usuario
                                     where (item.CPF == gC_Usuario.CPF ||
                                            item.Email == gC_Usuario.Email ||
                                            item.Login == gC_Usuario.Login) && item.Id != id
                                     select item).ToList();

            if (lst.Count > 0)
            {
                return(BadRequest("Dados Duplicados"));
            }

            db.Entry(gC_Usuario).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GC_UsuarioExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId;
            string clientSecret;

            context.TryGetFormCredentials(out clientId, out clientSecret);



            GC_Usuario oGC_Usuario = (from item in this.db.GC_Usuario
                                      where item.Senha == clientSecret && (item.Email == clientId || item.Login == clientId) && item.IsActive
                                      select item).FirstOrDefault();

            if (oGC_Usuario != null)
            {
                context.Validated(clientId);
            }

            return(base.ValidateClientAuthentication(context));
        }
        public bool Post([FromBody] GC_Mensalidade value)
        {
            value = (from item in db.GC_Mensalidade
                     where item.Id == value.Id
                     select item).FirstOrDefault();

            GC_Usuario oGC_Usuario = (from item in db.GC_Usuario
                                      where item.Id == value.GC_UsuarioId
                                      select item).FirstOrDefault();

            GC_Academia OGC_Academia = (from item in db.GC_Academia
                                        where item.Id == value.GC_AcademiaId
                                        select item).FirstOrDefault();


            GC_PagSeguroPagamento oGC_PagSeguroPagamento = (from item in db.GC_PagSeguroPagamento
                                                            where item.GC_MensalidadeId == value.Id
                                                            select item).FirstOrDefault();

            return(new Mailer().Boleto(oGC_Usuario.Email, oGC_Usuario.Nome, value.Vencimento.ToString("dd/MM/yyyy"), oGC_PagSeguroPagamento.BarCode, oGC_PagSeguroPagamento.Link, OGC_Academia.Nome, OGC_Academia));
        }
        public Boolean Post([FromBody] GC_Usuario value)
        {
            GC_Usuario oUsu = (from item in db.GC_Usuario
                               where item.CPF == value.CPF
                               select item).FirstOrDefault();

            if (oUsu == null)
            {
                throw new Exception("U2X_MessageUsuario não encontrado");
            }

            oUsu.Senha = GerarSenha();
            db.SaveChanges();

            GC_Academia oGC_Academia = new GC_Academia();

            oGC_Academia.Id = 1;


            new Mailer().RecuperaSenha(oUsu.Email, oUsu.Senha, oGC_Academia);
            return(true);
        }
Ejemplo n.º 18
0
        public async Task <IHttpActionResult> PostGC_Usuario(GC_Usuario gC_Usuario)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            List <GC_Usuario> lst = (from item in db.GC_Usuario
                                     where item.CPF == gC_Usuario.CPF ||
                                     item.Email == gC_Usuario.Email ||
                                     item.Login == gC_Usuario.Login
                                     select item).ToList();

            if (lst.Count > 0)
            {
                return(BadRequest("Dados Duplicados"));
            }
            gC_Usuario.IsActive = true;
            db.GC_Usuario.Add(gC_Usuario);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = gC_Usuario.Id }, gC_Usuario));
        }
Ejemplo n.º 19
0
        public GC_PagSeguroPagamento Checkout(GC_Mensalidade oMensalidade, GC_Usuario oAluno, GC_Academia oInstituicao, String token, String senderHash)
        {
            string urlPagSeguro    = System.Configuration.ConfigurationManager.AppSettings["pagSeguroURL_CHECKOUT"];
            string urlNotification = System.Configuration.ConfigurationManager.AppSettings["notificationURL_" + oInstituicao.Id];

            String sXML = @"<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?>
                                <payment>
                                    <mode>default</mode>
                                    <method>creditCard</method>
                                    <sender>
                                        <name>#nome#</name>
                                        <email>#email#</email>
                                        <phone>
                                            <areaCode>11</areaCode>
                                            <number>30380000</number>
                                        </phone>
                                        <documents>
                                            <document>
                                                <type>CPF</type>
                                                <value>#cpf#</value>
                                            </document>
                                        </documents>
                                        <hash>#senderHash#</hash>
                                    </sender>
                                    <notificationURL>#notificationURL#</notificationURL>
                                    <currency>BRL</currency>
    
                                    <items>
                                        <item>
                                            <id>1</id>
                                            <description>#descricao#</description>
                                            <quantity>1</quantity>
                                            <amount>#valor#</amount>
                                        </item>
                                    </items>
                                    <extraAmount>0.00</extraAmount>
                                    <reference>R123456</reference>
                                    <shipping>
                                        <address>
                                            <street>Av. capistrano de Abreu</street>
                                            <number>486</number>
                                            <complement>1 andar</complement>
                                            <district>Jaguaribe</district>
                                            <city>Osasco</city>
                                            <state>SP</state>
                                            <country>BRA</country>
                                            <postalCode>06065120</postalCode>
                                        </address>
                                        <type>3</type>
                                        <cost>0.00</cost>
                                    </shipping>
                                    <creditCard>
                                        <token>#creditCardToken#</token>
                                        <installment>
                                            <quantity>1</quantity>
                                            <value>#valor#</value>
                                        </installment>
                                        <holder>
                                            <name>Nome No Cartao</name>
                                            <documents>
                                                <document>
                                                    <type>CPF</type>
                                                    <value>#cpf#</value>
                                                </document>
                                            </documents>
                                            <birthDate>20/10/1980</birthDate>
                                            <phone>
                                                <areaCode>11</areaCode>
                                                <number>999991111</number>
                                            </phone>
                                        </holder>
                                        <billingAddress>
                                            <street>Av. capistrano de Abreu</street>
                                            <number>486</number>
                                            <complement>1 andar</complement>
                                            <district>Jaguaribe</district>
                                            <city>Osasco</city>
                                            <state>SP</state>
                                            <country>BRA</country>
                                            <postalCode>06065120</postalCode>
                                        </billingAddress>
                                    </creditCard>
                                </payment>";



            sXML = sXML.Replace("#descricao#", "Mensalidade (" + oMensalidade.Vencimento.ToString("DD") + "/" + oMensalidade.Vencimento.ToString("YYYY") + ")");
            sXML = sXML.Replace("#valor#", Convert.ToInt32(oMensalidade.Valor).ToString("N2"));
            sXML = sXML.Replace("#valor#", Convert.ToInt32(oMensalidade.Valor).ToString("N2"));
            sXML = sXML.Replace("#nome#", oAluno.Nome);
            sXML = sXML.Replace("#email#", oAluno.Email);
            sXML = sXML.Replace("#cpf#", oAluno.CPF);
            sXML = sXML.Replace("#cpf#", oAluno.CPF);
            sXML = sXML.Replace("#reference#", oMensalidade.Id.ToString());
            sXML = sXML.Replace("#creditCardToken#", token);
            sXML = sXML.Replace("#senderHash#", senderHash);
            sXML = sXML.Replace("#notificationURL#", urlNotification);

            urlPagSeguro = urlPagSeguro.Replace("#emailInstituicao#", oInstituicao.Email);
            urlPagSeguro = urlPagSeguro.Replace("#token#", oInstituicao.Token);

            using (var client = new HttpClient())
            {
                var httpContent = new StringContent(sXML, Encoding.UTF8, "application/xml");
                var response    = client.PostAsync(urlPagSeguro, httpContent).Result;

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = response.Content;

                    // by calling .Result you are synchronously reading the result
                    string      responseString = responseContent.ReadAsStringAsync().Result;
                    XmlDocument xml            = new XmlDocument();
                    xml.LoadXml(responseString);

                    GC_PagSeguroPagamento oPagSeguroPagamento = new GC_PagSeguroPagamento();

                    XmlNodeList nodeList = xml.GetElementsByTagName("code");
                    oPagSeguroPagamento.Code = nodeList[0].InnerText;

                    nodeList = xml.GetElementsByTagName("date");
                    oPagSeguroPagamento.DueDate = nodeList[0].InnerText;

                    return(oPagSeguroPagamento);
                }
            }
            return(null);
        }
 public List <GC_Academia> Post([FromBody] GC_Usuario value)
 {
     return((from item in this.db.GC_Academia
             where item.Usuarios.FirstOrDefault((x) => x.Id == value.Id) != null
             select item).ToList());
 }
Ejemplo n.º 21
0
        public List <GC_PagSeguroPagamento> GerarBoletos(List <GC_Mensalidade> oGC_Mensalidade)
        {
            String url           = System.Configuration.ConfigurationManager.AppSettings["pagSeguro_Boleto"];
            Int32  idMensalidade = oGC_Mensalidade[0].Id;

            GC_Mensalidade targetGC_Mensalidade = (from item in db.GC_Mensalidade
                                                   where item.Id == idMensalidade
                                                   select item).FirstOrDefault();

            GC_Usuario oGC_Usuario = (from item in db.GC_Usuario
                                      where item.Id == targetGC_Mensalidade.GC_UsuarioId
                                      select item).FirstOrDefault();

            GC_Academia oGC_Academia = (from item in db.GC_Academia
                                        where item.Id == targetGC_Mensalidade.GC_AcademiaId
                                        select item).FirstOrDefault();


            String cpf = oGC_Usuario.CPF.Split('.').Aggregate((current, next) => current + "" + next).Split('-').Aggregate((current, next) => current + "" + next);

            String oBody = sBody.Replace("#Mensalidade_ID#", oGC_Mensalidade[0].Id.ToString());

            oBody = oBody.Replace("#FirstDueDate#", targetGC_Mensalidade.Vencimento.ToString("yyyy-MM-dd"));
            oBody = oBody.Replace("#amount#", (targetGC_Mensalidade.Valor - 1).ToString());
            oBody = oBody.Replace("#numberOfPayments#", oGC_Mensalidade.Count.ToString());
            oBody = oBody.Replace("#CPF#", cpf);
            oBody = oBody.Replace("#Name#", oGC_Usuario.Nome);
            oBody = oBody.Replace("#Email#", "fake_" + oGC_Usuario.Email);
            oBody = oBody.Replace("#AcademiaNome#", oGC_Academia.Nome);

            oBody = oBody.Split('\'').Aggregate((current, next) => current + "\"" + next);

            url = url.Replace("#token#", oGC_Academia.Token);
            url = url.Replace("#email#", oGC_Academia.Email);

            using (var client = new HttpClient())
            {
                var httpContent = new StringContent(oBody, Encoding.UTF8, "application/json");
                var response    = client.PostAsync(url, httpContent).Result;


                if (response.IsSuccessStatusCode)
                {
                    var    responseContent = response.Content;
                    string responseString  = responseContent.ReadAsStringAsync().Result;

                    dynamic myClass = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(responseString);

                    List <dynamic> boletos = myClass.boletos.ToObject <List <dynamic> >();

                    List <GC_PagSeguroPagamento> lstGC_PagSeguroPagamento = new List <GC_PagSeguroPagamento>();

                    boletos.ForEach((x) =>
                    {
                        GC_PagSeguroPagamento oGC_PagSeguroPagamento = new GC_PagSeguroPagamento();
                        oGC_PagSeguroPagamento.BarCode = x.barcode;
                        oGC_PagSeguroPagamento.Code    = x.code;
                        oGC_PagSeguroPagamento.Link    = x.paymentLink;
                        oGC_PagSeguroPagamento.DueDate = x.dueDate;

                        lstGC_PagSeguroPagamento.Add(oGC_PagSeguroPagamento);
                    });
                    lstGC_PagSeguroPagamento = lstGC_PagSeguroPagamento.OrderBy(x => x.DueDate).ToList();
                    return(lstGC_PagSeguroPagamento);
                }
                else
                {
                    var    responseContent = response.Content;
                    string responseString  = responseContent.ReadAsStringAsync().Result;
                    throw new Exception(responseString);
                }
            }

            return(null);
            //var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://ws.pagseguro.uol.com.br/recurring-payment/[email protected]&token=32728DC4EF0A4615BD716904E82DA4AE");
            //httpWebRequest.ContentType = "application/json";
            //httpWebRequest.Method = "POST";

            //using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            //{
            //    streamWriter.Write(oBody);
            //    streamWriter.Flush();
            //    streamWriter.Close();
            //}

            //var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            //using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            //{
            //    var result = streamReader.ReadToEnd();

            //    dynamic myClass = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(result);

            //    List<dynamic> boletos = myClass.boletos.ToObject<List<dynamic>>();

            //    List<GC_PagSeguroPagamento> lstGC_PagSeguroPagamento = new List<GC_PagSeguroPagamento>();

            //    boletos.ForEach((x) =>
            //    {
            //        GC_PagSeguroPagamento oGC_PagSeguroPagamento = new GC_PagSeguroPagamento();
            //        oGC_PagSeguroPagamento.BarCode = x.barcode;
            //        oGC_PagSeguroPagamento.Code = x.code;
            //        oGC_PagSeguroPagamento.Link = x.paymentLink;
            //        oGC_PagSeguroPagamento.DueDate = x.dueDate;

            //        lstGC_PagSeguroPagamento.Add(oGC_PagSeguroPagamento);
            //    });
            //    lstGC_PagSeguroPagamento = lstGC_PagSeguroPagamento.OrderBy(x => x.DueDate).ToList();
            //    return lstGC_PagSeguroPagamento;
            //}
        }
 public Boolean Post([FromBody] GC_Usuario gc_Usuario)
 {
     // Mensalidades
     db.Database.ExecuteSqlCommand("proc_delete_mensalidade_errada " + gc_Usuario.Id);
     return(true);
 }