Пример #1
0
        public string Publish(string username, string token)
        {
            Integration ecommerce_int;

            using (LinkContext ctx = new LinkContext())
            {
                Client client = ctx.ClientUsers.Include("IsUserOf").Where(usr => usr.UserName == username).FirstOrDefault().IsUserOf;
                ecommerce_int = ctx.Integrations.Include("EcommerceIntegrated").Where(integ => integ.ClientIntegrated.ClientId == client.ClientId).FirstOrDefault();
            }
            IEcommerceIntegration ecommerceIntegration = IntegrationFactory.IntegrationFactory.GetEcommerceIntegration(ecommerce_int.EcommerceIntegrated.EcommerceName);

            ecommerceIntegration.SetCredentials(ecommerce_int.EcommerceIntegrated.EcommerceAppId, ecommerce_int.EcommerceIntegrated.EcommerceSecret, ecommerce_int.EcommerceAccessToken);
            List <Item> listaItems = new List <Item>();

            using (LinkContext ctx = new LinkContext())
            {
                listaItems = ctx.Items.Where(itm => itm.Integration.IntegrationId == ecommerce_int.IntegrationId).ToList();
            }
            List <IEcommerceItem> listaItemsEcom = new List <IEcommerceItem>();

            foreach (Item item in listaItems)
            {
                listaItemsEcom.Add(new ArticleERP()
                {
                    available_quantity = item.available_quantity, description = item.description, price = item.price, title = item.title, warranty = item.warranty
                });
            }
            //string json = JsonConvert.SerializeObject(listaItemsEcom);
            return(ecommerceIntegration.Publish(listaItemsEcom));
        }
Пример #2
0
        public DtoPurchase GetLastPurchase()
        {
            Integration integration;

            using (LinkContext ctx = new LinkContext())
            {
                ClientUser user    = ctx.ClientUsers.Include("IsUserOf").Where(usr => usr.UserName == "NOVA").FirstOrDefault();
                Client     cliente = user.IsUserOf;
                integration = ctx.Integrations.Include("EcommerceIntegrated").Where(inte => inte.ClientIntegrated.ClientId == cliente.ClientId).FirstOrDefault();
            }
            IEcommerceIntegration erp_integration = IntegrationFactory.IntegrationFactory.GetEcommerceIntegration(integration.EcommerceIntegrated.EcommerceName);

            erp_integration.SetCredentials(integration.EcommerceIntegrated.EcommerceAppId, integration.EcommerceIntegrated.EcommerceSecret, integration.EcommerceAccessToken);
            return(erp_integration.GetLastPurchase());
        }