public async Task <List <ShipmentProvider> > getTrendYolShipmentProviders(TrendYolAuthorization authorizationItems)
        {
            CreateAuthorization authorization = new CreateAuthorization(authorizationItems.apiKey, authorizationItems.apiSecret);

            HttpClient trendyolClient = new HttpClient();

            trendyolClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authorization.basicAuthorization);
            HttpResponseMessage responseTrendyolShipmentProviders = await trendyolClient.GetAsync(TrendYolEndPoints.trendyolShipmentProvidersEnpoint);

            var trendyolResponseResult = responseTrendyolShipmentProviders.Content.ReadAsStringAsync().ContinueWith(task => task.Result).Result;
            List <ShipmentProvider> deserializedShipmentProvider = JsonConvert.DeserializeObject <List <ShipmentProvider> >(trendyolResponseResult);

            foreach (ShipmentProvider item in deserializedShipmentProvider)
            {
                using (var db = new PazaryeriEntegrasyon.Models.TrendyolDBContext())
                {
                    db.Add(new PazaryeriEntegrasyon.Models.TrendyolShipmentCompany
                    {
                        ShipmentCompanyTrendyolID   = item.id,
                        ShipmentCompanyTrendyolCode = item.code,
                        ShipmentCompanyName         = item.name,
                        ShipmentCompanyTaxCode      = item.taxNumber
                    });
                    db.SaveChanges();
                }
            }
            return(deserializedShipmentProvider);
        }
Ejemplo n.º 2
0
        public TrendYolOrders getTrendyolOrders(TrendYolAuthorization authorizationItems)
        {
            CreateAuthorization authorization = new CreateAuthorization(authorizationItems.apiKey, authorizationItems.apiSecret);
            var client = new RestClient(string.Format(TrendYolEndPoints.trendyolOrdersEndPoint, authorizationItems.SupplierID));

            client.Timeout = -1;
            var request = new RestRequest(Method.POST);

            request.AddHeader("Authorization", "Basic " + authorization.basicAuthorization + "");
            request.AddHeader("Content-Type", "application/json");
            IRestResponse  response = client.Execute(request);
            TrendYolOrders deserializedTrendTolResponse = JsonConvert.DeserializeObject <TrendYolOrders>(response.Content);

            foreach (Content content in deserializedTrendTolResponse.content)
            {
                using (var db = new PazaryeriEntegrasyon.Models.TrendyolDBContext())
                {
                    db.Add(new PazaryeriEntegrasyon.Models.TrendyolCustomers
                    {
                        CustomerTrendYolID        = content.customerId,
                        CustomerTCKN              = content.tcIdentityNumber,
                        CustomerFirstName         = content.customerFirstName,
                        CustomerLastName          = content.customerLastName,
                        CustomerShipmentPackageID = content.id.ToString(),
                        CargoTrackingNumber       = content.cargoTrackingNumber.ToString(),
                        CargoTrackingLink         = content.cargoTrackingLink,
                        CargoSenderNumber         = content.cargoSenderNumber,
                        CargoProviderName         = content.cargoProviderName,
                        CustomerEmail             = content.customerEmail
                    }
                           );
                    db.SaveChanges();
                    db.Add(new PazaryeriEntegrasyon.Models.TrendyolOrders {
                        OrderCustomerName        = content.shipmentAddress.fullName,
                        OrderAdress              = content.shipmentAddress.fullAddress,
                        OrderCity                = content.shipmentAddress.city,
                        OrderDistrict            = content.shipmentAddress.district,
                        OrderInvoiceID           = content.invoiceAddress.id,
                        OrderInvoiceAdress       = content.invoiceAddress.fullAddress,
                        OrderInvoiceCustomerName = content.invoiceAddress.fullName,
                        OrderGrossAmount         = content.grossAmount,
                        OrderTotalDiscount       = content.totalDiscount,
                        OrderTotalPrice          = content.totalPrice
                    });
                    int orderid = db.SaveChanges();
                    foreach (Line orderproducts in content.lines)
                    {
                        db.Add(new PazaryeriEntegrasyon.Models.TrendYolOrderDetails {
                            OrderID                = orderid,
                            OrderDetailQuantity    = orderproducts.quantity,
                            OrderDetailProductName = orderproducts.productName
                        });
                    }
                    db.SaveChanges();
                }
            }
            return(deserializedTrendTolResponse);
        }
        public async Task <TrendYolCategory> getTrendyolCategories(TrendYolAuthorization authorizationItems)
        {
            CreateAuthorization authorization = new CreateAuthorization(authorizationItems.apiKey, authorizationItems.apiSecret);

            HttpClient trendyolClient = new HttpClient();

            trendyolClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authorization.basicAuthorization);
            HttpResponseMessage responseTrendyolShipmentProviders = await trendyolClient.GetAsync(TrendYolEndPoints.trendyolCategoryEnpoint);

            var trendyolResponseResult            = responseTrendyolShipmentProviders.Content.ReadAsStringAsync().ContinueWith(task => task.Result).Result;
            TrendYolCategory deserializedCategory = JsonConvert.DeserializeObject <TrendYolCategory>(trendyolResponseResult);

            foreach (Category category in deserializedCategory.categories)
            {
                if (category.subCategories.Count() == 0)
                {
                    using (var db = new PazaryeriEntegrasyon.Models.TrendyolDBContext())
                    {
                        db.Add(new PazaryeriEntegrasyon.Models.TrendyolCategories
                        {
                            TrendyolCategoryID   = category.id,
                            TrendyolCategoryCode = "KGTR",
                            TrendyolCategoryName = category.name,
                        }
                               );
                        db.SaveChanges();
                    }
                }
                else
                {
                    foreach (SubCategory subcategory in category.subCategories)
                    {
                        if (subcategory.subCategories.Count() == 0)
                        {
                            using (var db = new PazaryeriEntegrasyon.Models.TrendyolDBContext())
                            {
                                db.Add(new PazaryeriEntegrasyon.Models.TrendyolCategories
                                {
                                    TrendyolCategoryID       = subcategory.id,
                                    TrendyolCategoryCode     = "KGTR",
                                    TrendyolCategoryName     = subcategory.name,
                                    TrendyolParentCategoryID = subcategory.parentId
                                }
                                       );
                                db.SaveChanges();
                            }
                        }
                        else
                        {
                            foreach (SubCategory2 subcategory2 in subcategory.subCategories)
                            {
                                if (subcategory2.subCategories.Count() == 0)
                                {
                                    using (var db = new PazaryeriEntegrasyon.Models.TrendyolDBContext())
                                    {
                                        db.Add(new PazaryeriEntegrasyon.Models.TrendyolCategories
                                        {
                                            TrendyolCategoryID       = subcategory2.id,
                                            TrendyolCategoryCode     = "KGTR",
                                            TrendyolCategoryName     = subcategory2.name,
                                            TrendyolParentCategoryID = subcategory2.parentId
                                        }
                                               );
                                        db.SaveChanges();
                                    }
                                }
                                else
                                {
                                    foreach (SubCategory3 subcategory3 in subcategory2.subCategories)
                                    {
                                        if (subcategory3.subCategories.Count() == 0)
                                        {
                                            using (var db = new PazaryeriEntegrasyon.Models.TrendyolDBContext())
                                            {
                                                db.Add(new PazaryeriEntegrasyon.Models.TrendyolCategories
                                                {
                                                    TrendyolCategoryID       = subcategory3.id,
                                                    TrendyolCategoryCode     = "KGTR",
                                                    TrendyolCategoryName     = subcategory3.name,
                                                    TrendyolParentCategoryID = subcategory3.parentId
                                                }
                                                       );
                                                db.SaveChanges();
                                            }
                                        }
                                        else
                                        {
                                            foreach (SubCategory4 subcategory4 in subcategory3.subCategories)
                                            {
                                                if (subcategory4.subCategories.Count() == 0)
                                                {
                                                    using (var db = new PazaryeriEntegrasyon.Models.TrendyolDBContext())
                                                    {
                                                        db.Add(new PazaryeriEntegrasyon.Models.TrendyolCategories
                                                        {
                                                            TrendyolCategoryID       = subcategory4.id,
                                                            TrendyolCategoryCode     = "KGTR",
                                                            TrendyolCategoryName     = subcategory4.name,
                                                            TrendyolParentCategoryID = subcategory4.parentId
                                                        }
                                                               );
                                                        db.SaveChanges();
                                                    }
                                                }
                                                else
                                                {
                                                    foreach (SubCategory5 subcategory5 in subcategory4.subCategories)
                                                    {
                                                        if (subcategory5.subCategories.Count() == 0)
                                                        {
                                                            using (var db = new PazaryeriEntegrasyon.Models.TrendyolDBContext())
                                                            {
                                                                db.Add(new PazaryeriEntegrasyon.Models.TrendyolCategories
                                                                {
                                                                    TrendyolCategoryID       = subcategory5.id,
                                                                    TrendyolCategoryCode     = "KGTR",
                                                                    TrendyolCategoryName     = subcategory5.name,
                                                                    TrendyolParentCategoryID = subcategory5.parentId
                                                                }
                                                                       );
                                                                db.SaveChanges();
                                                            }
                                                        }
                                                        else
                                                        {
                                                            // 5. katmanlı kategori yapısı olduğu için burayı boş bıraktık
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(deserializedCategory);
        }