using HakanSoftwareAPI.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Web.Http;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace HakanSoftwareAPI.Controllers
{
public class Despecn11Controller : ApiController
{
String imza = "<br><br><br>Bu ilan <b>PcToplaAl</b> projesininde sahibi olan <b>HakanSoftware</b> tarafından listelenmiştir.";
String appKey = "964d3200-832b-4451-8425-83e7a04c9249";
String appSecret = "ACBCQUdBiIRP523N";
//// GET api/<controller>
//public IEnumerable<string> Get()
//{
// return new string[] { "value1", "value2" };
//}
//// GET api/<controller>/5
//public string Get(int id)
//{
// return "value";
//}
//// POST api/<controller>
//public void Post([FromBody]string value)
//{
//}
//// PUT api/<controller>/5
//public void Put(int id, [FromBody]string value)
//{
//}
//// DELETE api/<controller>/5
//public void Delete(int id)
//{
//}
public HttpResponseMessage Get()
{
return Request.CreateResponse(HttpStatusCode.OK, "ok");
}
public HttpResponseMessage Get(String islemBilgi)
{
WebRequest request = WebRequest.Create("https://api.n11.com/ws/ProductService.wsdl");
request.Method = "POST";
request.ContentType = "text/xml";
n11UrunEkleme.auth auth = new n11UrunEkleme.auth();
auth.appKey = appKey;
auth.appSecret = appSecret;
n11UrunEkleme.product product = new n11UrunEkleme.product();
product.productSellerCode = "ilk Seller Code 9";
product.title = "ilk Title";
product.subtitle = "ilk subtitle";
product.description = "ilk description";
n11UrunEkleme.productCategory cat = new n11UrunEkleme.productCategory();
cat.id = 1000262;
product.category = cat;
product.price = 50;
product.currencyType = 2;
n11UrunEkleme.productImages images = new n11UrunEkleme.productImages();
n11UrunEkleme.productImagesImage image = new n11UrunEkleme.productImagesImage();
image.url = "http://www.indexpazar.com/all_images/DGA033.jpg";
image.order = 1;
images.image = image;
product.images = images;
product.approvalStatus = 3;
n11UrunEkleme.attributesAttribute attribute = new n11UrunEkleme.attributesAttribute();
attribute.name = "Marka";
attribute.value = "MSI";
product.productCondition = 1;
product.preparingDay = 5;
product.shipmentTemplate = 1;
n11UrunEkleme.productStockItemsStockItem stockItem = new n11UrunEkleme.productStockItemsStockItem();
stockItem.mpn = "MSI-Yanar-Doner";
stockItem.quantity = 1;
stockItem.sellerStockCode = "ilk stok code 9";
n11UrunEkleme.productStockItems stockItems = new n11UrunEkleme.productStockItems();
stockItems.stockItem = stockItem;
product.stockItems = stockItems;
Attributes attributesv2 = new Attributes();
attributesv2.Attribute = new List<Models.Attribute>();
HakanSoftwareAPI.Models.Attribute attributev2 = new HakanSoftwareAPI.Models.Attribute();
attributev2.Name = "Marka";
attributev2.Value = "MSI";
HakanSoftwareAPI.Models.Attribute attributev3 = new HakanSoftwareAPI.Models.Attribute();
attributev3.Name = "Slot Yapısı";
attributev3.Value = "Pcı-Express 3.0 16X";
HakanSoftwareAPI.Models.Attribute attributev4 = new HakanSoftwareAPI.Models.Attribute();
attributev4.Name = "Chip Set";
attributev4.Value = "Nvıdıa";
HakanSoftwareAPI.Models.Attribute attributev5 = new HakanSoftwareAPI.Models.Attribute();
attributev5.Name = "Ekran Kartı Belleği";
attributev5.Value = "6 Gb ve üzeri";
HakanSoftwareAPI.Models.Attribute attributev6 = new HakanSoftwareAPI.Models.Attribute();
attributev6.Name = "Bit Değeri";
attributev6.Value = "256 Bit";
attributesv2.Attribute.Add(attributev2);
attributesv2.Attribute.Add(attributev3);
attributesv2.Attribute.Add(attributev4);
attributesv2.Attribute.Add(attributev5);
attributesv2.Attribute.Add(attributev6);
product.attributes = attributesv2;
n11UrunEkleme.SaveProductRequest save = new n11UrunEkleme.SaveProductRequest();
save.auth = auth;
save.product = product;
var serializer2 = new XmlSerializer(typeof(n11UrunEkleme.Envelope));
n11UrunEklemeIlk productIlk = new n11UrunEklemeIlk();
n11UrunEkleme.EnvelopeBody eBody = new n11UrunEkleme.EnvelopeBody();
eBody.SaveProductRequest = save;
n11UrunEkleme.Envelope e = new n11UrunEkleme.Envelope();
e.Body = eBody;
using (var writer = new StreamWriter("D:\\File.xml"))
{
serializer2.Serialize(writer, e);
}
XmlSerializer xsSubmit = new XmlSerializer(typeof(n11UrunEkleme.Envelope));
var subReq = new n11UrunEkleme.Envelope();
var xml = "";
using (var sww = new StringWriter())
{
using (XmlWriter writer = XmlWriter.Create(sww))
{
xsSubmit.Serialize(writer, e);
xml = sww.ToString();
}
}
XDocument doc = XDocument.Parse(xml);
String sDoc = doc.ToString();
byte[] byteArray = Encoding.UTF8.GetBytes(sDoc);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
String status = ((HttpWebResponse)response).StatusDescription;
reader.Close();
dataStream.Close();
response.Close();
if(responseFromServer.Contains("<status>success</status>"))
{
return Request.CreateResponse(HttpStatusCode.OK, responseFromServer);
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest, responseFromServer);
}
}
}
}