protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ConstruirEF cf = new ConstruirEF();
                n = (NSAADMEntities)cf.RecuperaEntity(Entities.MercadoLivre);

                var um = (from ito in n.ML_ItemOrganizacao
                          join it in n.ML_Item on ito.id equals it.id_org
                          join ordit in n.ML_OrderItem on it.id equals ordit.id_item
                          join ord in n.ML_Order on ordit.id_order equals ord.id
                          join fd in n.ML_FeedbackSeller on ord.id equals fd.id_order
                         where fd.id_order == ord.id
                            && fd.rating == "positive"
                        select new { DescrItem = ito.Descricao, ValorOrdem = ord.total_amount });

                var dois = (from p in um group p by p.DescrItem into umg select new { ItemDesc = umg.Key, Qtd = umg.Count(), TotalBruto = umg.Sum(x => x.ValorOrdem), TotalLiquido = (umg.Sum(x1 => x1.ValorOrdem) * COMISSAO_ML) });

                GridView1.DataSource = dois;
                GridView1.DataBind();

                Label1.Text = String.Format("Total de valor recebido: {0}",dois.Sum(x => x.TotalLiquido));

            }
        }
        /// <summary>
        /// NÃO IMPLEMENTADO - COLOCAR ELE COMO PUBLICO DEPOIS.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="n"></param>
        public void GravaOrdem(Order o, NSAADMEntities n)
        {
            try
            {
                ML_Order Ordem;
                ConverterObjetoMLparaEF cf = new ConverterObjetoMLparaEF();

                Ordem = (from p in n.ML_Order where p.id == o.id select p).FirstOrDefault();
                if (Ordem == null)
                {
                    Ordem = cf.ConverteOrdem(o, n);
                    n.ML_Order.AddObject(Ordem);
                }
                else
                {
                    cf.AtualizaOrdem(Ordem, o, n);
                }

                n.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro na rotina GravaOrdem.", ex);
            }
        }
        public void GravaPergunta(Question q, NSAADMEntities n)
        {
            try
            {
                var i = (from p in n.ML_Question where p.id_question == q.id select p).First();

                i.status = q.status;

                if (q.from != null)
                {
                    i.answered_questions = q.from.answered_questions;
                }
                if (q.answer != null)
                {
                    i.Answer_date_created = q.answer.date_created;
                    i.Answer_status = q.answer.status;
                    i.Answer_text = q.answer.text;
                }

            }
            catch (Exception)
            {

                ML_Question mlQ = conv.ConverteQuestion(q);

                n.ML_Question.AddObject(mlQ);

            }

            n.SaveChanges();
        }
        public void GravaItem(ML_Item item, NSAADMEntities n)
        {
            ML_Item it = new ML_Item();

            try
            {
                it = (from p in n.ML_Item where p.id == item.id select p).First();

            }
            catch (InvalidOperationException)
            {

                it.id_org = item.id_org;
                it.id = item.id;
                it.title = item.title;
                it.variation_id = item.variation_id;

                n.ML_Item.AddObject(it);

                n.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro na rotina GravaItem", ex);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         ConstruirEF cf = new ConstruirEF();
         n = (NSAADMEntities)cf.RecuperaEntity(Entities.MercadoLivre);
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            ConstruirEF cf = new ConstruirEF();
            n = (NSAADMEntities)cf.RecuperaEntity(Entities.MercadoLivre);

            Decimal codigo = Convert.ToDecimal(Request.QueryString["code"]);

            var x = (from p in n.MP_Payments where p.id == codigo select p);

            GridView1.DataSource = x;
            GridView1.DataBind();
        }
 public ControlaMeli()
 {
     try
     {
         ConstruirEF cf = new ConstruirEF();
         n = (NSAADMEntities)cf.RecuperaEntity(Entities.MercadoLivre);
         d = (from p in n.DadosMLs where p.id == "Meli" select p).First();
         m = new Meli(Convert.ToInt64(d.ClientId), d.ClientSecret, d.AccessToken, d.RefreshToken);
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("Erro no New do ControlaMeli"), ex);
     }
 }
        /// <summary>
        /// Recebe um ID e Retona um ML_Order cadastrado no EF
        /// </summary>
        /// <param name="u">ID do usuário usado na pesquisa</param>
        /// <param name="n">Objeto NSAADMEntities onde vai ser pesquisado</param>
        /// <returns>Retorna o objeto ML_Usuario casdastrado no EF</returns>
        public ML_Usuario RetonarUsuario(decimal ID, NSAADMEntities n)
        {
            try
            {
                ML_Usuario m;
                m = (from p in n.ML_Usuario where p.id == ID select p).FirstOrDefault();
                return m;
            }
            catch (Exception ex)
            {

                throw new Exception("Erro na rotina RetonarUsuario.", ex);
            }
        }
        /// <summary>
        /// Recebe um ID e Retona um ML_Item cadastrado no EF
        /// </summary>
        /// <param name="u">ID do item usado na pesquisa</param>
        /// <param name="n">Objeto NSAADMEntities onde vai ser pesquisado</param>
        /// <returns>Retorna o objeto ML_Item casdastrado no EF</returns>
        public ML_Item RetonarItem(string ID, NSAADMEntities n)
        {
            try
            {
                ML_Item m;
                m = (from p in n.ML_Item where p.id == ID select p).FirstOrDefault();
                return m;
            }
            catch (Exception ex)
            {

                throw new Exception("Erro na rotina RetonarItem.", ex);
            }
        }
        public ML_Item RetornaProduto(string id, NSAADMEntities n)
        {
            try
            {
                return (from p in n.ML_Item where p.id == id select p).First();
            }
            catch (Exception)
            {

                ML_Item ml = new ML_Item();
                ml.title = "Sem venda";
                return ml;

            }
        }
        /// <summary>
        /// Recebe uma Order e Retona um ML_Order cadastrado no EF
        /// </summary>
        /// <param name="o">Objeto Order usado na pesquisa</param>
        /// <param name="n">Objeto NSAADMEntities onde vai ser pesquisado</param>
        /// <returns>Retorna o objeto ML_Order casdastrado no EF</returns>
        public ML_Order RetonarOrder(Order o, NSAADMEntities n)
        {
            try
            {

                ML_Order mo = (from p in n.ML_Order where p.id == o.id select p).First();

                return mo;

            }
            catch (Exception ex)
            {

                throw new Exception("Erro na rotina RetonarOrder.", ex);
            }
        }
示例#12
0
        public Object RecuperaEntity(Entities en)
        {
            Object EF;

            if (en == Entities.MercadoLivre)
            {
                EF = new NSAADMEntities(stringdeconexao());
                return (NSAADMEntities)EF;
            }
            else if (en == Entities.Bot)
            {
                EF = new BotWoWEntities(stringdeconexao());
                return (BotWoWEntities)EF;
            }
            else
            {
                throw new Exception("Enumerador inválido");
            }
        }
        public void AtualizaOrdem(ML_Order o, Order oML, NSAADMEntities n1)
        {
            try
            {

                if (o.ML_FeedbackBuyer != null)
                {
                    o.ML_FeedbackBuyer.Load();
                }

                if (o.ML_FeedbackSeller != null)
                {
                    o.ML_FeedbackSeller.Load();
                }

                if (o.ML_Payment != null)
                {
                    o.ML_Payment.Load();
                }

                if (oML.status != null)
                {
                    o.status = oML.status;
                }

                if (oML.status_detail != null)
                {
                    o.status_detail = oML.status_detail.description;
                }

                AtualizaFeedBackBuyer(o, oML, n1);
                AtualizaFeedBackSeller(o, oML, n1);
                AtualizaShipping(o, oML, n1);
                ML_Payment p = o.ML_Payment.FirstOrDefault();
                if (p != null) AtualizaPagamento(p, oML.payments.First(), n1);

            }
            catch (Exception ex)
            {
                throw new Exception("Erro na rotina AtualizaOrdem(ML_Order o, Order oML)", ex);
            }
        }
        public void GravaPergunta(ML_Question q, NSAADMEntities n)
        {
            try
            {
                var i = (from p in n.ML_Question where p.id == q.id select p).First();

                i.Answer_date_created = q.Answer_date_created;
                i.Answer_status = q.Answer_status;
                i.Answer_text = q.Answer_text;
                i.answered_questions = q.answered_questions;

                n.SaveChanges();

            }
            catch (Exception ex)
            {

                throw new Exception("Erro na rotina GravaPergunta(ML_Question q, NSAADMEntities n)", ex);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                ConstruirEF cf = new ConstruirEF();
                n = (NSAADMEntities)cf.RecuperaEntity(Entities.MercadoLivre);

                var x = (from p in n.ML_ItemOrganizacao select p);

                DropDownList1.Items.Clear();
                Label1.Text = "";
                Label2.Text = "";
                Label3.Text = "";

                DropDownList1.DataSource = x;
                DropDownList1.DataTextField = "descricao";
                DropDownList1.DataValueField = "id";

                DropDownList1.DataBind();

            }
        }
        public List<CallBackML> RetornaCallBacks(TipoRetonaCallBacks tcallback, NSAADMEntities n)
        {
            try{

                List<CallBackML> lCall = new List<CallBackML>();
                if (tcallback == TipoRetonaCallBacks.PERGUNTAS)
                {
                    lCall = (from p in n.CallBackMLs where p.topic == "questions" select p).ToList();

                }
                else
                {
                    throw new Exception("Tipo de Retorno CallBack não implementado ou inválido.");
                }

                return lCall;

            }
            catch (Exception ex)
            {

                throw new Exception("Erro na rotina RetornaCallBacks.", ex);
            }
        }
        public ML_Order ConverteOrdem(Order o, NSAADMEntities n)
        {
            try
            {

                ControlaUsuario ControlaUsu = new ControlaUsuario();
                ControlaItem ControlaIt = new ControlaItem();
                ControlaEndereco ControlEnd = new ControlaEndereco();
                ConstruirEF cf = new ConstruirEF();

                ML_Order ord = new ML_Order();

                //CONVERTENDO COMPRADOR E VENDEDOR
                ML_Usuario buy = ControlaUsu.RetonarUsuario(o.buyer.id, n);
                if (buy == null)
                {
                    buy = ConverteUsuario(o.buyer);
                }

                ML_Usuario sel = ControlaUsu.RetonarUsuario(o.seller.id, n);
                if (sel == null)
                {
                    sel = ConverteUsuario(o.seller);
                }

                ord.ML_Usuario = sel;
                ord.ML_Usuario1 = buy;

                //ITENS DA ORDEM
                ML_OrderItem oi;
                foreach (OrderItem item in o.order_items)
                {
                    oi = new ML_OrderItem();
                    oi.currency_id = item.currency_id;
                    oi.quantity = item.quantity;
                    oi.unit_price = item.unit_price;

                    ML_Item mitem = ControlaIt.RetonarItem(o.order_items[0].item.id, n);
                    if (mitem == null)
                    {
                        mitem = ConverteItem(o.order_items[0].item);
                    }

                    oi.ML_Item = mitem;
                    ord.ML_OrderItem.Add(oi);
                }

                ML_Payment pa;
                foreach (Payment p in o.payments)
                {
                    pa = new ML_Payment();
                    pa.currency_id = p.currency_id;
                    pa.date_created = p.date_created;
                    pa.date_last_updated = p.date_last_updated;
                    pa.status = p.status;
                    pa.transaction_amount = p.transaction_amount;

                    pa.id = p.id;

                    ord.ML_Payment.Add(pa);

                }

                if (o.feedback != null)
                {
                    if (o.feedback.purchase != null)
                    {
                        ML_FeedbackBuyer feeb = new ML_FeedbackBuyer();
                        feeb.date_created = o.feedback.purchase.date_created;
                        feeb.fulfilled = o.feedback.purchase.fulfilled.ToString();
                        feeb.rating = o.feedback.purchase.rating;
                        feeb.id_order = o.id;

                        ord.ML_FeedbackBuyer.Add(feeb);

                    }

                    if (o.feedback != null)
                    {
                        if (o.feedback.sale != null)
                        {
                            ML_FeedbackSeller fees = new ML_FeedbackSeller();
                            fees.date_created = o.feedback.sale.date_created;
                            fees.fulfilled = o.feedback.sale.fulfilled.ToString();
                            fees.rating = o.feedback.sale.rating;
                            fees.id_order = o.id;

                            ord.ML_FeedbackSeller.Add(fees);
                        }
                    }
                }

                ML_Shipping s = new ML_Shipping();
                s = ConverteShipping(o, n);
                if (s != null) ord.ML_Shipping.Add(s);

                //DADOS DA ORDEM
                ord.id = o.id;
                ord.currency_id = o.currency_id;
                ord.date_closed = o.date_closed;
                ord.date_created = o.date_created;
                ord.status = o.status;
                //ord.status_detail = o.status_detail.description;
                ord.total_amount = o.total_amount;

                return ord;

            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Erro na rotina de ConverteOrdem. OrdemID: {0}",o.id), ex);
            }
        }
        //private void AtualizaDados(ML_Question q, NSAADMEntities n)
        //{
        //    try
        //    {
        //        var i = (from p in n.ML_Question where p.id_question == q.id_question select p).First();
        //        i.status = q.status;
        //        i.Answer_date_created = q.Answer_date_created;
        //        i.Answer_status = q.Answer_status;
        //        i.Answer_text = q.Answer_text;
        //        i.answered_questions = q.answered_questions;
        //        i.date_created = q.date_created;
        //        i.id_from = q.id_from;
        //        n.SaveChanges();
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception("Erro na rotina AtualizaDados", ex);
        //    }
        //}
        public ML_Question RetornaPergunta(decimal idQuestion, NSAADMEntities n)
        {
            ML_Question q;

            try
            {
                q = (from p in n.ML_Question where p.id_question == idQuestion select p).First();

                return q;

            }
            catch (InvalidOperationException iex)
            {
                throw new Exception("Pergunta não encontrada.", iex);
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Erro na rotina RetornaPergunta. {0} idQuestion: {1} {0}", Environment.NewLine, idQuestion), ex);
            }
        }
        public List<ML_Question> RetonaPerguntas(decimal IDUsuario, NSAADMEntities n)
        {
            try
            {

                List<ML_Question> q = (from p in n.ML_Question where p.id_from == IDUsuario select p).ToList();

                return q;

            }
            catch (InvalidOperationException)
            {

                return new List<ML_Question>();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro na rotina RetonaPerguntas.", ex);
            }
        }
        public ML_Shipping ConverteShipping(Order o, NSAADMEntities n)
        {
            ControlaEndereco ControlEnd = new ControlaEndereco();

            if (o.shipping.id != null)
            {
                //IMPLEMENTAR ENDERECO
                ML_Shipping s = new ML_Shipping();
                s.cost = o.shipping.cost;
                s.currency_id = o.shipping.currency_id;
                if (o.shipping.date_created != null)
                {
                    s.date_created = Convert.ToDateTime(o.shipping.date_created);
                }
                s.id = Convert.ToDecimal(o.shipping.id);
                s.shipment_type = o.shipping.shipment_type;
                s.status = o.shipping.status;

                if (o.shipping.receiver_address != null && o.shipping.receiver_address.id != null)
                {

                    ML_ReceiverAddress rc;
                    decimal d = Convert.ToDecimal(o.shipping.receiver_address.id);
                    rc = (from p in n.ML_ReceiverAddress where p.ID == d select p).FirstOrDefault();
                    if (rc == null)
                    {
                        rc = new ML_ReceiverAddress();
                        rc.address_line = o.shipping.receiver_address.address_line;
                        rc.comment = o.shipping.receiver_address.comment;
                        rc.ID = Convert.ToDecimal(o.shipping.receiver_address.id.ToString());
                        //rc.latitude = o.shipping.receiver_address.latitude.ToString(); Todos vem Null
                        //rc.longitude = o.shipping.receiver_address.longitude.ToString();
                        rc.zip_code = o.shipping.receiver_address.zip_code;

                        rc.ML_State = ControlEnd.RetonarStado(o.shipping.receiver_address.state.id, n);
                        if (rc.ML_State == null && o.shipping.receiver_address.state.id != null)
                        {
                            rc.ML_State = ConverteState(o.shipping.receiver_address.state);
                        }

                        rc.ML_City = ControlEnd.RetonarCidade(o.shipping.receiver_address.city.id, n);
                        if (rc.ML_City == null && o.shipping.receiver_address.city.id != null)
                        {
                            rc.ML_City = ConverteCity(o.shipping.receiver_address.city);
                        }

                        rc.ML_Country = ControlEnd.RetonarPais(o.shipping.receiver_address.country.id, n);
                        if (rc.ML_Country == null && o.shipping.receiver_address.country.id != null)
                        {
                            rc.ML_Country = ConverteCountry(o.shipping.receiver_address.country);
                        }
                    }

                    s.ML_ReceiverAddress = rc;
                }
                return s;
            }
            else
            {
                return null;
            }
        }
 private void AtualizaPagamento(ML_Payment p, Payment py, NSAADMEntities n)
 {
     try
     {
         p.currency_id = py.currency_id;
         p.date_created = py.date_created;
         p.date_last_updated = py.date_last_updated;
         p.status = py.status;
         p.transaction_amount = py.transaction_amount;
         if (p.id == 0) p.id = py.id;
     }
     catch (Exception ex)
     {
         throw new Exception("Erro na rotina AtualziaPagamento.",ex);
     }
 }
 /// <summary>
 /// Inclui ou Altera uma ML_Order no banco de dados.
 /// </summary>
 /// <param name="o">Objeto ML_Order que vai ser inserido ou alterado</param>
 /// <param name="n">Objeto NSAADMEntities que vai ser usado para fazer a inclusão ou alteração.</param>
 public void GravaOrdem(ML_Order o, NSAADMEntities n)
 {
 }
        /// <summary>
        /// Retorna todas as ordens baseadas no filtro informado.
        /// </summary>
        /// <param name="to">TipoRetornaOrdens, informa quais as ordens devem ser retornadas</param>
        /// <param name="n">Objeto NSAADMEntities usado para selecionar as ordens</param>
        /// <returns>Retorna um List<ML_Order> com todas as ordens selecionadas</returns>
        public List<ML_Order> RetornaOrdens(TipoRetonaOrdens to, NSAADMEntities n)
        {
            try
            {
                List<ML_Order> mo = new List<ML_Order>();

                if (to == TipoRetonaOrdens.ABERTASPAGAS)
                {
                    mo = (from p in n.ML_Order where p.status == "paid" select p).ToList();
                }
                else
                {
                    throw new Exception("Tipo de Retorna Order não implementado ou inválido.");
                }
                return mo;
            }
            catch (Exception ex)
            {

                throw new Exception("Erro na rotina RetornaOrdens.", ex);
            }
        }
示例#24
0
 public Posts(Meli meli, NSAADMEntities nsaadm)
 {
     m = meli;
     n = nsaadm;
 }
        public List<ML_Question> RetonaPerguntas(TipoRetonaPerguntas t, NSAADMEntities n)
        {
            try
            {
                if (t == TipoRetonaPerguntas.NAORESPONDIDA)
                {
                    List<ML_Question> q = (from p in n.ML_Question where p.status == PERGUNTA_NAO_RESPONDIDA select p).ToList();

                    return q;
                }
                else
                {
                    throw new Exception("Tipo de Retona Pergunta não implementado ou inválido.");
                }
            }
            catch (InvalidOperationException)
            {

                return new List<ML_Question>();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro na rotina RetonaPerguntas.", ex);
            }
        }
        private void AtualizaFeedBackSeller(ML_Order o, Order oML, NSAADMEntities n)
        {
            try
            {
                if (o.ML_FeedbackSeller.Count > 0)
                {
                    if (RetornaFeedBackSeller(oML) != null)
                    {
                        ML_FeedbackSeller MLs = o.ML_FeedbackSeller.First();
                        Sale s = RetornaFeedBackSeller(oML);

                        MLs.date_created = s.date_created;
                        MLs.fulfilled = s.fulfilled.ToString();
                        MLs.rating = s.rating;
                        o.ML_FeedbackSeller.Add(MLs);
                    }
                }
                else
                {
                    if (RetornaFeedBackSeller(oML) != null)
                    {

                        ML_FeedbackSeller MLs1 = new ML_FeedbackSeller();
                        Sale s1 = RetornaFeedBackSeller(oML);

                        MLs1.date_created = s1.date_created;
                        MLs1.fulfilled = s1.fulfilled.ToString();
                        MLs1.rating = s1.rating;
                        MLs1.id_order = o.id;

                        o.ML_FeedbackSeller.Add(MLs1);
                    }
                }
            }
            catch (Exception ex)
            {

                throw new Exception("Erro na rotina AtualizaFeedBackSeller", ex);
            }
        }
        private void AtualizaFeedBackBuyer(ML_Order o, Order oML, NSAADMEntities n)
        {
            try
            {
                if (o.ML_FeedbackBuyer.Count > 0)
                {
                    if (RetornaFeedBackPurchase(oML) != null)
                    {
                        ML_FeedbackBuyer b = o.ML_FeedbackBuyer.First();
                        Purchase p = RetornaFeedBackPurchase(oML);

                        b.date_created = p.date_created;
                        b.fulfilled = p.fulfilled.ToString();
                        b.rating = p.rating;

                    }

                }
                else
                {
                    if (RetornaFeedBackPurchase(oML) != null)
                    {

                        ML_FeedbackBuyer b1 = new ML_FeedbackBuyer();
                        Purchase p1 = RetornaFeedBackPurchase(oML);

                        b1.date_created = p1.date_created;
                        b1.fulfilled = p1.fulfilled.ToString();
                        b1.rating = p1.rating;
                        b1.id_order = o.id;

                        n.ML_FeedbackBuyer.AddObject(b1);
                        o.ML_FeedbackBuyer.Add(b1);

                    }

                }
            }
            catch (Exception ex)
            {

                throw new Exception("Erro na rotina AtualizaFeedBackBuyer.", ex);
            }
        }
        private void AtualizaShipping(ML_Order o, Order oML, NSAADMEntities n)
        {
            try
            {
                if (oML.shipping.id != null)
                {
                    o.ML_Shipping.Load();

                    ML_Shipping ship;

                    ship = o.ML_Shipping.FirstOrDefault();

                    if (ship == null)
                    {

                        ship = ConverteShipping(oML, n);
                        o.ML_Shipping.Add(ship);

                    }
                    else
                    {
                        ship.status = oML.shipping.status;
                        ship.shipment_type = oML.shipping.shipment_type;
                        ship.currency_id = oML.shipping.currency_id;
                        ship.cost = oML.shipping.cost;

                    }

                }
            }
            catch (Exception ex)
            {

                throw new Exception(String.Format("Erro na rotina AtualizaShipping. {0} oML.id = {1} {0}", Environment.NewLine, oML.id), ex);
            }
        }