PageRenderTime 28ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/testwebapi/Controllers/OrdersController.cs

https://bitbucket.org/chmuniprasad/api
C# | 1271 lines | 1136 code | 103 blank | 32 comment | 134 complexity | 0dbb8acbea18b2c34495fc497e3a3be8 MD5 | raw file
  1. using CompLibrary;
  2. using DBLibrary;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel.DataAnnotations;
  7. using System.Data;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Net.Http;
  12. using System.Text;
  13. using System.Web.Http;
  14. using Pay2CartAPI.Models;
  15. using Pay2CartAPI.Response;
  16. using System.Xml.Linq;
  17. using Pay2CartAPI.Classes;
  18. using Pay2CartAPI.WalletService;
  19. using System.Configuration;
  20. using Newtonsoft.Json.Linq;
  21. using System.Text.RegularExpressions;
  22. namespace Pay2CartAPI.Controllers
  23. {
  24. public class OrdersController : ApiController
  25. {
  26. public string response = "";
  27. public DataTable MaxQty;
  28. public decimal result = decimal.Zero;
  29. public string MyIPAddress = "";
  30. public DataTable dt;
  31. public DataTable dt2;
  32. public decimal ProductInitialPrice = decimal.Zero;
  33. public decimal ProductAdjPrice = decimal.Zero;
  34. public decimal ProductFinalCost = decimal.Zero;
  35. public decimal ProductFinalCostInclTax = decimal.Zero;
  36. public decimal ProductFinalCostExclTax = decimal.Zero;
  37. public decimal CartSubTotal = decimal.Zero;
  38. public decimal CartSubTotalInclTax = decimal.Zero;
  39. public decimal CartSubTotalExclTax = decimal.Zero;
  40. public decimal taxrate = decimal.Zero;
  41. public decimal ProductTierPrice = decimal.Zero;
  42. [HttpPost]
  43. [Authorize]
  44. public HttpResponseMessage Summary([FromBody]Summary summary)
  45. {
  46. SummaryResponseObj ResponseObj = new SummaryResponseObj();
  47. string response = "";
  48. try
  49. {
  50. if (ModelState.IsValid)
  51. {
  52. DataTable priceDet = new DataTable();
  53. priceDet.Columns.Add("value",typeof(System.Int32));
  54. priceDet.Columns.Add("name");
  55. DataTable dtr = OrdersComp.CheckBundleIteminCart(summary.id_customer);
  56. DataTable paymentmethods = OrdersComp.Paymentmethods(summary.id_customer);
  57. DataTable paymentMethod = new DataTable();
  58. paymentMethod.Columns.Add("value");
  59. paymentMethod.Columns.Add("name");
  60. if (paymentmethods.Rows.Count>0)
  61. {
  62. for(int i=0;i<= paymentmethods.Rows.Count-1;i++)
  63. {
  64. if(paymentmethods.Rows[i]["name"].ToString().Contains("OnlinePayment"))
  65. {
  66. paymentMethod.Rows.Add("ccavenue", "Online Payment");
  67. }
  68. if (paymentmethods.Rows[i]["name"].ToString().Contains("CashOnDelivery"))
  69. {
  70. paymentMethod.Rows.Add("cod", "Cash On Delivery");
  71. }
  72. }
  73. }
  74. DataTable pricingDetails = OrdersComp.Pricedetails(summary.id_customer);
  75. pricingDetails.Columns.Add("Total");
  76. int sumAmount = 0;
  77. if(pricingDetails.Rows.Count>0)
  78. {
  79. int sum = Convert.ToInt32(pricingDetails.Compute("SUM(shipping)", string.Empty));
  80. priceDet.Rows.Add(0, "Shipping Total");
  81. //sumAmount = sum;
  82. sumAmount = 0;
  83. }
  84. if (pricingDetails.Rows.Count>0)
  85. {
  86. for (int i=0;i<= pricingDetails.Rows.Count-1;i++)
  87. {
  88. decimal price = decimal.Zero;
  89. price = decimal.Multiply((Int32)pricingDetails.Rows[i]["Quantity"], (decimal)pricingDetails.Rows[i]["Price"]);
  90. pricingDetails.Rows[i]["Total"] = price;
  91. }
  92. }
  93. float balance = Wallet.getCustomerCurrentWalletBalance(summary.id_customer);
  94. ResponseObj.userWalletAmount = balance;
  95. bool bundleitem = false;
  96. if (dtr.Rows.Count > 0)
  97. {
  98. for (int i = 0; i <= dtr.Rows.Count - 1; i++)
  99. {
  100. bundleitem = (bool)dtr.Rows[i][0];
  101. MaxQty = OrdersComp.GetCartItemsBeforeOrder(summary.id_customer, bundleitem);
  102. if (MaxQty.Rows.Count > 0)
  103. {
  104. foreach (DataRow dr in MaxQty.Rows)
  105. {
  106. if ((Int32)(dr["StockQuantity"]) < (Int32)(dr["Quantity"]))
  107. {
  108. ResponseObj.message = "Product Qty is not Available in Stock.";
  109. ResponseObj.status = 0;
  110. }
  111. else
  112. {
  113. GetCartSubTotal(dr);
  114. }
  115. CartSubTotal += ProductFinalCost;
  116. CartSubTotalInclTax += ProductFinalCostInclTax;
  117. CartSubTotalExclTax += ProductFinalCostExclTax;
  118. }
  119. }
  120. }
  121. priceDet.Rows.Add(CartSubTotal, "Subtotal");
  122. decimal pp = decimal.Add(CartSubTotal, sumAmount);
  123. priceDet.Rows.Add(pp, "Total");
  124. ResponseObj.status = 1;
  125. ResponseObj.paymentmethods = paymentMethod;
  126. ResponseObj.pricingDetails = priceDet;
  127. ResponseObj.deliverDays = "2-5 working days";
  128. ResponseObj.message = "Order Summary";
  129. }
  130. else
  131. {
  132. ResponseObj.status = 0;
  133. ResponseObj.message = Common.NoRecordsExists;
  134. }
  135. }
  136. else
  137. {
  138. ResponseObj.status = 0;
  139. ResponseObj.message = "Customer ID Required.";
  140. }
  141. }
  142. catch (Exception Err)
  143. {
  144. }
  145. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  146. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  147. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  148. return HttpResponseMessage;
  149. }
  150. [HttpPost]
  151. [Authorize]
  152. public HttpResponseMessage reOder([FromBody]ReOrder reorder)
  153. {
  154. reOrderResponseObj ResponseObj = new reOrderResponseObj();
  155. string response = "";
  156. try
  157. {
  158. if (ModelState.IsValid)
  159. {
  160. DataTable OrderProducts = OrdersComp.GetOrderProducts(reorder.customerID,reorder.orderID);
  161. if(OrderProducts.Rows.Count>0)
  162. {
  163. for(int i=0;i<= OrderProducts.Rows.Count -1;i++)
  164. {
  165. int productid = (Int32)OrderProducts.Rows[i]["ProductId"];
  166. DataTable MaxQty = ShopingCartComp.GetMaxProductQty(productid);
  167. if (MaxQty.Rows.Count > 0)
  168. {
  169. if (!Convert.IsDBNull(MaxQty.Rows[0]["OrderMaximumQuantity"]))
  170. {
  171. if ((Int32)OrderProducts.Rows[i]["Quantity"] > (Int32)MaxQty.Rows[0]["OrderMaximumQuantity"])
  172. {
  173. ResponseObj.message = "Max Quantiy Allowed for Purchase is : " + (Int32)MaxQty.Rows[0]["OrderMaximumQuantity"] + ".";
  174. ResponseObj.status = 0;
  175. return Request.CreateResponse(HttpStatusCode.OK, ResponseObj.message);
  176. }
  177. }
  178. if (!Convert.IsDBNull(MaxQty.Rows[0]["AllowedQuantities"]))
  179. {
  180. if ((Int32)OrderProducts.Rows[i]["Quantity"] > (Int32)MaxQty.Rows[0]["AllowedQuantities"])
  181. {
  182. ResponseObj.message = "Allowed Quantiy for Purchase is : " + (Int32)MaxQty.Rows[0]["AllowedQuantities"] + ".";
  183. ResponseObj.status = 0;
  184. return Request.CreateResponse(HttpStatusCode.OK, ResponseObj.message);
  185. }
  186. }
  187. if (reorder.customerID != 0)
  188. {
  189. //Checking given customerID is is valid or not
  190. DataTable customerIsValid = ShopingCartComp.CheckCustomerIsvalid(reorder.customerID);
  191. if (customerIsValid.Rows.Count == 0)
  192. {
  193. ResponseObj.message = "CustomerId is not valid.. Please provide vaild customerid";
  194. ResponseObj.status = 0;
  195. }
  196. else
  197. {
  198. // checking product had bundle items or not?
  199. DataTable ProdctBudles = ShopingCartComp.CheckProductIncluesBundle((Int32)OrderProducts.Rows[i]["ProductId"]);
  200. int? ParentItemId = null; int? BundleItemId = null;
  201. if (ProdctBudles.Rows.Count != 0)
  202. {
  203. int cnt = 0;
  204. string AttributesXml = "";
  205. DataTable checkprocutinCART = ShopingCartComp.AddShopingCartItem(reorder.customerID, (Int32)OrderProducts.Rows[i]["ProductId"]);
  206. if (checkprocutinCART.Rows.Count > 0)
  207. {
  208. long res = ShopingCartComp.UpdateCartItmes(reorder.customerID, (Int32)OrderProducts.Rows[i]["ProductId"], (Int32)OrderProducts.Rows[i]["Quantity"]);
  209. }
  210. else
  211. {
  212. long res = ShopingCartComp.AddShopingCartItem(reorder.customerID, ParentItemId, BundleItemId, (Int32)OrderProducts.Rows[i]["ProductId"], AttributesXml, (Int32)OrderProducts.Rows[i]["Quantity"]);
  213. }
  214. int parentitem = 0;
  215. DataTable bundle = ShopingCartComp.GetParentItemID((Int32)OrderProducts.Rows[i]["ProductId"], reorder.customerID);
  216. parentitem = (Int32)bundle.Rows[0][0];
  217. for (int ki = 0; ki <= ProdctBudles.Rows.Count - 1; ki++)
  218. {
  219. //// inserting Product Varinat Combination
  220. string AttributesXm = "";
  221. long result = ShopingCartComp.AddShopingCartItem(reorder.customerID, parentitem, (Int32)ProdctBudles.Rows[ki]["Id"], (Int32)ProdctBudles.Rows[ki]["ProductId"], AttributesXm, (Int32)ProdctBudles.Rows[ki]["Quantity"]);
  222. cnt += 1;
  223. }
  224. if (cnt == ProdctBudles.Rows.Count)
  225. {
  226. ResponseObj.status = 1;
  227. ResponseObj.message = "Item Added to Cart Successfylly.";
  228. }
  229. else
  230. {
  231. ResponseObj.message = Common.OopsSomethingWentWrong;
  232. ResponseObj.status = 0;
  233. }
  234. }
  235. else
  236. {
  237. string AttributesXml = "";
  238. DataTable checkprocutinCART = ShopingCartComp.AddShopingCartItem(reorder.customerID, (Int32)OrderProducts.Rows[i]["ProductId"]);
  239. long res = 0;
  240. if (checkprocutinCART.Rows.Count > 0)
  241. {
  242. res = ShopingCartComp.UpdateCartItmes(reorder.customerID, (Int32)OrderProducts.Rows[i]["ProductId"], (Int32)OrderProducts.Rows[i]["Quantity"]);
  243. }
  244. else
  245. {
  246. res = ShopingCartComp.AddShopingCartItem(reorder.customerID, ParentItemId, BundleItemId, (Int32)OrderProducts.Rows[i]["ProductId"], AttributesXml, (Int32)OrderProducts.Rows[i]["Quantity"]);
  247. }
  248. DataTable cartTotal = ShopingCartComp.cartTotal(reorder.customerID);
  249. if (res == 1)
  250. {
  251. DataTable productprice = ProductsComp.getProductDetails((Int32)OrderProducts.Rows[i]["ProductId"]);
  252. ResponseObj.status = 1;
  253. ResponseObj.message = "Item Added to Cart Successfylly.";
  254. }
  255. else
  256. {
  257. ResponseObj.message = Common.OopsSomethingWentWrong;
  258. ResponseObj.status = 0;
  259. }
  260. }
  261. }
  262. }
  263. else
  264. {
  265. ResponseObj.message = "CustomerId is required";
  266. ResponseObj.status = 0;
  267. }
  268. }
  269. else
  270. {
  271. ResponseObj.status = 1;
  272. ResponseObj.message = "Poduct is not available.";
  273. }
  274. }
  275. }
  276. }
  277. else
  278. {
  279. ResponseObj.status = 0;
  280. ResponseObj.message = "Customer ID Required.";
  281. }
  282. }
  283. catch (Exception Err)
  284. {
  285. }
  286. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  287. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  288. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  289. return HttpResponseMessage;
  290. }
  291. [HttpGet]
  292. [Authorize]
  293. public HttpResponseMessage shoppingCartOrders(int id_customer,int start=0)
  294. {
  295. DataTable orders = new DataTable();
  296. ResponseObj ResponseObj = new ResponseObj();
  297. string response = "";
  298. try
  299. {
  300. if (id_customer > 0)
  301. {
  302. int PageNumber = start; // Page Number
  303. int RowsPerPage = 10; // fixed items to display in a page
  304. orders = OrdersComp.getShopingCartOrders(id_customer, RowsPerPage, PageNumber );
  305. DataTable orrd = new DataTable();
  306. if (orders.Rows.Count > 0)
  307. {
  308. orrd = orders.Clone();
  309. orrd.Columns["order_state"].DataType = typeof(System.String);
  310. foreach (DataRow row in orders.Rows)
  311. {
  312. orrd.ImportRow(row);
  313. }
  314. for (int i=0;i<= orders.Rows.Count-1;i++)
  315. {
  316. if((Int32)orders.Rows[i]["order_state"]==10)
  317. {
  318. orrd.Rows[i]["id_order_state"] = 10;
  319. orrd.Rows[i]["order_state"] = "Order Pending";
  320. orrd.Rows[i]["order_state_color"] = ConfigurationManager.AppSettings["OrderPending"];
  321. }
  322. else if ((Int32)orders.Rows[i]["order_state"] == 20)
  323. {
  324. orrd.Rows[i]["id_order_state"] = 20;
  325. orrd.Rows[i]["order_state"] = "Order Processing";
  326. orrd.Rows[i]["order_state_color"] = ConfigurationManager.AppSettings["OrderProcessing"];
  327. }
  328. else if ((Int32)orders.Rows[i]["order_state"] == 30)
  329. {
  330. orrd.Rows[i]["id_order_state"] = 30;
  331. orrd.Rows[i]["order_state"] = "Order Complete";
  332. orrd.Rows[i]["order_state_color"] = ConfigurationManager.AppSettings["OrderComplete"];
  333. }
  334. else
  335. {
  336. orrd.Rows[i]["id_order_state"] = 40;
  337. orrd.Rows[i]["order_state"] = "Order Cancelled";
  338. orrd.Rows[i]["order_state_color"] = ConfigurationManager.AppSettings["OrderCancelled"];
  339. }
  340. if (orrd.Rows[i]["payment"].ToString().Contains("Payments.Prepayment"))
  341. {
  342. string str = orrd.Rows[i]["payment"].ToString();
  343. Regex rx = new Regex("Payments.");
  344. // replace all matches with empty strin
  345. str = rx.Replace(str, "");
  346. orrd.Rows[i]["payment"] = "Online Payment";
  347. }
  348. else if (orrd.Rows[i]["payment"].ToString().Contains("Payments.CashOnDelivery"))
  349. {
  350. string str = orrd.Rows[i]["payment"].ToString();
  351. Regex rx = new Regex("Payments.");
  352. // replace all matches with empty strin
  353. str = rx.Replace(str, "");
  354. orrd.Rows[i]["payment"] = "Cash On Delivery";
  355. }
  356. else if (orrd.Rows[i]["payment"].ToString().Contains("Payments.OnlinePayment"))
  357. {
  358. string str = orrd.Rows[i]["payment"].ToString();
  359. Regex rx = new Regex("Payments.");
  360. // replace all matches with empty strin
  361. str = rx.Replace(str, "");
  362. orrd.Rows[i]["payment"] = "Online Payment";
  363. }
  364. else if (orrd.Rows[i]["payment"].ToString().Contains("Payments.PayInStore"))
  365. {
  366. string str = orrd.Rows[i]["payment"].ToString();
  367. Regex rx = new Regex("Payments.");
  368. // replace all matches with empty strin
  369. str = rx.Replace(str, "");
  370. orrd.Rows[i]["payment"] = "Pay In Store";
  371. }
  372. else if (orrd.Rows[i]["payment"].ToString().Contains("Payments.PaymentMethod"))
  373. {
  374. string str = orrd.Rows[i]["payment"].ToString();
  375. Regex rx = new Regex("Payments.");
  376. // replace all matches with empty strin
  377. str = rx.Replace(str, "");
  378. orrd.Rows[i]["payment"] = "Online Payment";
  379. }
  380. }
  381. ResponseObj.status = 1;
  382. ResponseObj.message = Common.RecordsExists;
  383. ResponseObj.result = orrd;
  384. }
  385. else
  386. {
  387. ResponseObj.status = 0;
  388. ResponseObj.message = Common.NoRecordsExists;
  389. ResponseObj.result = orrd;
  390. }
  391. }
  392. else
  393. {
  394. ResponseObj.status = 0;
  395. ResponseObj.message = "orderID Required.";
  396. }
  397. }
  398. catch (Exception Err)
  399. {
  400. }
  401. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  402. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  403. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  404. return HttpResponseMessage;
  405. }
  406. [HttpGet]
  407. [Authorize]
  408. public HttpResponseMessage getOrderDetails(int customerID, int OrderID)
  409. {
  410. DataTable orders = new DataTable();
  411. ResponseObj ResponseObj = new ResponseObj();
  412. string response = "";
  413. try
  414. {
  415. if (OrderID > 0)
  416. {
  417. orders = OrdersComp.getOrderDetails(customerID , OrderID);
  418. if (orders.Rows.Count > 0)
  419. {
  420. ResponseObj.status = 1;
  421. ResponseObj.message = Common.RecordsExists;
  422. ResponseObj.result = orders;
  423. }
  424. else
  425. {
  426. ResponseObj.status = 0;
  427. ResponseObj.message = Common.NoRecordsExists;
  428. ResponseObj.result = orders;
  429. }
  430. }
  431. else
  432. {
  433. ResponseObj.status = 0;
  434. ResponseObj.message = "orderID Required.";
  435. }
  436. }
  437. catch (Exception Err)
  438. {
  439. }
  440. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  441. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  442. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  443. return HttpResponseMessage;
  444. }
  445. [HttpGet]
  446. [Authorize]
  447. public HttpResponseMessage getProductNamesByOrderId(int id_customer, int id_order)
  448. {
  449. DataTable orders = new DataTable();
  450. ResponseObj ResponseObj = new ResponseObj();
  451. string response = "";
  452. try
  453. {
  454. if (id_customer > 0 && id_order >0)
  455. {
  456. orders = OrdersComp.GetproductsInContactByOrderId(id_customer, id_order);
  457. if (orders.Rows.Count > 0)
  458. {
  459. ResponseObj.status = 1;
  460. ResponseObj.message = Common.RecordsExists;
  461. ResponseObj.result = orders;
  462. }
  463. else
  464. {
  465. ResponseObj.status = 0;
  466. ResponseObj.message = Common.NoRecordsExists;
  467. ResponseObj.result = orders;
  468. }
  469. }
  470. else
  471. {
  472. ResponseObj.status = 0;
  473. ResponseObj.message = "OrderId is Required.";
  474. }
  475. }
  476. catch (Exception Err)
  477. {
  478. }
  479. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  480. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  481. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  482. return HttpResponseMessage;
  483. }
  484. [HttpGet]
  485. [Authorize]
  486. public HttpResponseMessage orderReferencesByid(int id_customer)
  487. {
  488. DataTable orders = new DataTable();
  489. ResponseObj ResponseObj = new ResponseObj();
  490. string response = "";
  491. try
  492. {
  493. if (id_customer > 0 )
  494. {
  495. orders = OrdersComp.orderReferencesByCustomerid(id_customer);
  496. if (orders.Rows.Count > 0)
  497. {
  498. ResponseObj.status = 1;
  499. ResponseObj.message = Common.RecordsExists;
  500. ResponseObj.result = orders;
  501. }
  502. else
  503. {
  504. ResponseObj.status = 0;
  505. ResponseObj.message = Common.NoRecordsExists;
  506. ResponseObj.result = orders;
  507. }
  508. }
  509. else
  510. {
  511. ResponseObj.status = 0;
  512. ResponseObj.message = "CustomerId is Required.";
  513. }
  514. }
  515. catch (Exception Err)
  516. {
  517. }
  518. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  519. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  520. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  521. return HttpResponseMessage;
  522. }
  523. [HttpGet]
  524. [Authorize]
  525. public HttpResponseMessage getOrderDetailsByOrderId(int OrderID)
  526. {
  527. // DataTable orders = new DataTable();
  528. OrderDetailsByOrderidResponseObj ResponseObj = new OrderDetailsByOrderidResponseObj();
  529. string response = "";
  530. try
  531. {
  532. if (OrderID > 0)
  533. {
  534. DataTable orders = OrdersComp.getOrderDetailsbyOrderId(OrderID);
  535. DataTable deliveryAddress = OrdersComp.GetDeliveryAddressbyOrderID((Int32)orders.Rows[0]["addressid"],OrderID);
  536. DataTable orrd = new DataTable();
  537. DataTable OrderDetails = OrdersComp.GetOrderDetailsWithOrderId((Int32)orders.Rows[0]["id_customer"], OrderID);
  538. if (orders.Rows.Count > 0)
  539. {
  540. try
  541. {
  542. orrd = orders.Clone();
  543. orrd.Columns["id_image"].DataType = typeof(System.String);
  544. orrd.Columns["imageLink"].DataType = typeof(System.String);
  545. foreach (DataRow row in orders.Rows)
  546. {
  547. orrd.ImportRow(row);
  548. }
  549. if (orrd.Rows.Count > 0)
  550. {
  551. for (int i = 0; i <= orrd.Rows.Count - 1; i++)
  552. {
  553. DataTable storedetails = PasswordComp.StoreInformation();
  554. DataTable getImagesLinks = ProductsComp.GetImageFullNames((Int32)orders.Rows[i]["id_image"]);
  555. string mimetype = "";
  556. var imgurl = storedetails.Rows[0]["Url"].ToString();
  557. if ((getImagesLinks.Rows[0]["MimeType"].ToString()).Contains("image/jpeg"))
  558. {
  559. mimetype = ".jpg";
  560. }
  561. else if ((getImagesLinks.Rows[0]["MimeType"].ToString()).Contains("image/png"))
  562. {
  563. mimetype = ".png";
  564. }
  565. string imgId = getImagesLinks.Rows[0]["Id"].ToString();
  566. string imgName = getImagesLinks.Rows[0]["SeoFilename"].ToString();
  567. orrd.Rows[i]["imageLink"] = imgurl + "/media/image/" + imgId + "/" + imgName + mimetype + "";
  568. //orrd.Rows[i]["imageLink"] = imgurl + "" + imgName;
  569. //replacing html strings
  570. string str = orrd.Rows[i]["description"].ToString();
  571. Regex rx = new Regex("<[^>]*>");
  572. // replace all matches with empty strin
  573. str = rx.Replace(str, "");
  574. RegexOptions options = RegexOptions.None;
  575. Regex regex = new Regex("[ ]{2,}", options);
  576. str = regex.Replace(str, " ");
  577. str = str.Trim();
  578. orrd.Rows[i]["description"] = str;
  579. }
  580. }
  581. }
  582. catch (Exception Err) { }
  583. DataTable orderDett = new DataTable();
  584. try
  585. {
  586. orderDett = OrderDetails.Clone();
  587. orderDett.Columns["order_state"].DataType = typeof(System.String);
  588. orderDett.Columns["date_add"].DataType = typeof(System.String);
  589. foreach (DataRow row in OrderDetails.Rows)
  590. {
  591. orderDett.ImportRow(row);
  592. }
  593. for (int i = 0; i <= OrderDetails.Rows.Count - 1; i++)
  594. {
  595. DateTime OrderDate = (DateTime)orderDett.Rows[i]["date_add"];
  596. //DateTime utcTime = walletdate.ToLocalTime();
  597. var istdate = TimeZoneInfo.ConvertTimeFromUtc(OrderDate, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
  598. string walletDT = istdate.ToString("yyyy-MM-dd HH:mm:ss");
  599. orderDett.Rows[i]["date_add"] = walletDT;
  600. if ((Int32)OrderDetails.Rows[i]["order_state"] == 10)
  601. {
  602. orderDett.Rows[i]["id_order_state"] = 10;
  603. orderDett.Rows[i]["order_state"] = "Order Pending";
  604. orderDett.Rows[i]["order_state_color"] = ConfigurationManager.AppSettings["OrderPending"];
  605. }
  606. else if ((Int32)OrderDetails.Rows[i]["order_state"] == 20)
  607. {
  608. orderDett.Rows[i]["id_order_state"] = 20;
  609. orderDett.Rows[i]["order_state"] = "Order Processing";
  610. orderDett.Rows[i]["order_state_color"] = ConfigurationManager.AppSettings["OrderProcessing"];
  611. }
  612. else if ((Int32)OrderDetails.Rows[i]["order_state"] == 30)
  613. {
  614. orderDett.Rows[i]["id_order_state"] = 30;
  615. orderDett.Rows[i]["order_state"] = "Order Complete";
  616. orderDett.Rows[i]["order_state_color"] = ConfigurationManager.AppSettings["OrderComplete"];
  617. }
  618. else
  619. {
  620. orderDett.Rows[i]["id_order_state"] = 40;
  621. orderDett.Rows[i]["order_state"] = "Order Cancelled";
  622. orderDett.Rows[i]["order_state_color"] = ConfigurationManager.AppSettings["OrderCancelled"];
  623. }
  624. if (orderDett.Rows[i]["payment"].ToString().Contains("Payments.Prepayment"))
  625. {
  626. string str = orderDett.Rows[i]["payment"].ToString();
  627. Regex rx = new Regex("Payments.");
  628. // replace all matches with empty strin
  629. str = rx.Replace(str, "");
  630. orderDett.Rows[i]["payment"] = "Online Payment";
  631. }
  632. else if (orderDett.Rows[i]["payment"].ToString().Contains("Payments.CashOnDelivery"))
  633. {
  634. string str = orderDett.Rows[i]["payment"].ToString();
  635. Regex rx = new Regex("Payments.");
  636. // replace all matches with empty strin
  637. str = rx.Replace(str, "");
  638. orderDett.Rows[i]["payment"] = "Cash On Delivery";
  639. }
  640. else if (orderDett.Rows[i]["payment"].ToString().Contains("Payments.OnlinePayment"))
  641. {
  642. string str = orderDett.Rows[i]["payment"].ToString();
  643. Regex rx = new Regex("Payments.");
  644. // replace all matches with empty strin
  645. str = rx.Replace(str, "");
  646. orderDett.Rows[i]["payment"] = "Online Payment";
  647. }
  648. else if (orderDett.Rows[i]["payment"].ToString().Contains("Payments.PayInStore"))
  649. {
  650. string str = orderDett.Rows[i]["payment"].ToString();
  651. Regex rx = new Regex("Payments.");
  652. // replace all matches with empty strin
  653. str = rx.Replace(str, "");
  654. orderDett.Rows[i]["payment"] = "Pay In Store";
  655. }
  656. else if (orderDett.Rows[i]["payment"].ToString().Contains("Payments.PaymentMethod"))
  657. {
  658. string str = orderDett.Rows[i]["payment"].ToString();
  659. Regex rx = new Regex("Payments.");
  660. // replace all matches with empty strin
  661. str = rx.Replace(str, "");
  662. orderDett.Rows[i]["payment"] = "Online Payment";
  663. }
  664. }
  665. }
  666. catch (Exception ER)
  667. {
  668. }
  669. if (deliveryAddress.Rows.Count > 0)
  670. {
  671. string JSONresult;
  672. JSONresult = JsonConvert.SerializeObject(deliveryAddress);
  673. JSONresult = JSONresult.Replace("[", "");
  674. JSONresult = JSONresult.Replace("]", "");
  675. JObject jsonObject = JObject.Parse(JSONresult);
  676. ResponseObj.deliveryAddress = jsonObject;
  677. }
  678. ResponseObj.status = 1;
  679. ResponseObj.message = Common.RecordsExists;
  680. ResponseObj.delivery_days = "2-5 working days";
  681. //ResponseObj.orderDetails = OrderDetails;
  682. ResponseObj.orderDetails = orderDett;
  683. ResponseObj.result = orrd;
  684. }
  685. else
  686. {
  687. ResponseObj.status = 0;
  688. ResponseObj.message = Common.NoRecordsExists;
  689. ResponseObj.result = orrd;
  690. }
  691. }
  692. else
  693. {
  694. ResponseObj.status = 0;
  695. ResponseObj.message = "orderID Required.";
  696. }
  697. }
  698. catch (Exception Err)
  699. {
  700. }
  701. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  702. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  703. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  704. return HttpResponseMessage;
  705. }
  706. [HttpPost]
  707. [Authorize]
  708. public HttpResponseMessage CreateOrder([FromBody][Required]CreateOrder createOrder)
  709. {
  710. CreateOrderResponseObj ResponseObj = new CreateOrderResponseObj();
  711. InsufficientRechargeFundsObj ISRFObj = new InsufficientRechargeFundsObj();
  712. string response = "";
  713. try
  714. {
  715. if (createOrder != null)
  716. {
  717. if (ModelState.IsValid)
  718. {
  719. ConfirmOrder confirmOrder = new ConfirmOrder();
  720. InsertOrderItems insertOrderItems = new InsertOrderItems();
  721. DataTable getaddressofcustomer = OrdersComp.getcustomeraddress(createOrder.id_customer, createOrder.id_address_delivery);
  722. if (getaddressofcustomer.Rows.Count > 0)
  723. {
  724. int Customerid = createOrder.id_customer;
  725. // checking bundle items are available in cart or not
  726. DataTable dtr = OrdersComp.CheckBundleIteminCart(Customerid);
  727. bool bundleitem = false;
  728. if (dtr.Rows.Count > 0)
  729. {
  730. for (int i = 0; i <= dtr.Rows.Count - 1; i++)
  731. {
  732. CartSubTotal = decimal.Zero;
  733. CartSubTotalInclTax = decimal.Zero;
  734. CartSubTotalExclTax = decimal.Zero;
  735. bundleitem = (bool)dtr.Rows[i][0];
  736. //Checking Product Stock availability before purchase
  737. MaxQty = OrdersComp.GetCartItemsBeforeOrder(Customerid, bundleitem);
  738. if (MaxQty.Rows.Count > 0)
  739. {
  740. foreach (DataRow dr in MaxQty.Rows)
  741. {
  742. if ((Int32)(dr["StockQuantity"]) < (Int32)(dr["Quantity"]))
  743. {
  744. ResponseObj.message = "Product Qty is not Available in Stock.";
  745. ResponseObj.status = 2;
  746. }
  747. else
  748. {
  749. GetCartSubTotal(dr);
  750. }
  751. CartSubTotal += ProductFinalCost;
  752. CartSubTotalInclTax += ProductFinalCostInclTax;
  753. CartSubTotalExclTax += ProductFinalCostExclTax;
  754. }
  755. try
  756. {
  757. // MyIPAddress = new WebClient().DownloadString("http://icanhazip.com");
  758. MyIPAddress = Common.IPaddress;
  759. }
  760. catch (Exception Err) { }
  761. #region ORDER Data
  762. confirmOrder.StoreId = 1;
  763. confirmOrder.CustomerId = createOrder.id_customer;
  764. confirmOrder.BillingAddressId = createOrder.id_address_delivery;
  765. confirmOrder.ShippingAddressId = createOrder.id_address_delivery;
  766. confirmOrder.OrderStatusId = 10;
  767. confirmOrder.ShippingStatusId = 20;
  768. confirmOrder.PaymentStatusId = 10;
  769. confirmOrder.PaymentMethodSystemName = "Cash On Delivery";
  770. confirmOrder.CustomerCurrencyCode = "INR";
  771. confirmOrder.CurrencyRate = 1;
  772. confirmOrder.CustomerTaxDisplayTypeId = 10;
  773. confirmOrder.VatNumber = "";
  774. confirmOrder.OrderSubtotalInclTax = CartSubTotalInclTax;
  775. confirmOrder.OrderSubtotalExclTax = CartSubTotalExclTax;
  776. confirmOrder.OrderSubTotalDiscountInclTax = 0;
  777. confirmOrder.OrderSubTotalDiscountExclTax = 0;
  778. confirmOrder.OrderShippingInclTax = 0;
  779. confirmOrder.OrderShippingExclTax = 0;
  780. confirmOrder.PaymentMethodAdditionalFeeInclTax = 0;
  781. confirmOrder.PaymentMethodAdditionalFeeExclTax = 0;
  782. confirmOrder.TaxRates = "0:0;";
  783. confirmOrder.OrderTax = 0;
  784. confirmOrder.OrderDiscount = 0;
  785. confirmOrder.OrderTotal = CartSubTotal;
  786. confirmOrder.RefundedAmount = 0;
  787. confirmOrder.RewardPointsWereAdded = false;
  788. confirmOrder.CheckoutAttributeDescription = "";
  789. confirmOrder.CheckoutAttributesXml = "";
  790. confirmOrder.CustomerLanguageId = 1;
  791. confirmOrder.AffiliateId = 1;
  792. confirmOrder.CustomerIp = MyIPAddress;
  793. confirmOrder.AllowStoringCreditCardNumber = false;
  794. confirmOrder.CardType = "";
  795. confirmOrder.CardName = "";
  796. confirmOrder.CardNumber = "";
  797. confirmOrder.MaskedCreditCardNumber = "";
  798. confirmOrder.CardCvv2 = "";
  799. confirmOrder.CardExpirationMonth = "";
  800. confirmOrder.CardExpirationYear = "";
  801. confirmOrder.AllowStoringDirectDebit = false;
  802. confirmOrder.DirectDebitAccountHolder = "";
  803. confirmOrder.DirectDebitAccountNumber = "";
  804. confirmOrder.DirectDebitBankCode = "";
  805. confirmOrder.DirectDebitBankName = "";
  806. confirmOrder.DirectDebitBIC = "";
  807. confirmOrder.DirectDebitCountry = "";
  808. confirmOrder.DirectDebitIban = "";
  809. confirmOrder.AuthorizationTransactionId = "";
  810. confirmOrder.AuthorizationTransactionCode = "";
  811. confirmOrder.AuthorizationTransactionResult = "";
  812. confirmOrder.CaptureTransactionId = "";
  813. confirmOrder.CaptureTransactionResult = "";
  814. confirmOrder.SubscriptionTransactionId = "";
  815. confirmOrder.PurchaseOrderNumber = "";
  816. confirmOrder.PaidDateUtc = DateTime.Now;
  817. confirmOrder.ShippingMethod = "By Ground";
  818. confirmOrder.ShippingRateComputationMethodSystemName = "FixedRate";
  819. confirmOrder.Deleted = false;
  820. confirmOrder.CreatedOnUtc = DateTime.Now;
  821. confirmOrder.UpdatedOnUtc = DateTime.Now;
  822. confirmOrder.RewardPointsRemaining = 0;
  823. confirmOrder.CustomerOrderComment = "";
  824. confirmOrder.OrderShippingTaxRate = 0;
  825. confirmOrder.PaymentMethodAdditionalFeeTaxRate = 0;
  826. confirmOrder.HasNewPaymentNotification = false;
  827. confirmOrder.AcceptThirdPartyEmailHandOver = false;
  828. confirmOrder.OrderTotalRounding = 0;
  829. confirmOrder.order_from = createOrder.order_from;
  830. #endregion ORDER Data
  831. long res = OrdersComp.ConfirmOrder(confirmOrder.StoreId, confirmOrder.CustomerId, confirmOrder.BillingAddressId, confirmOrder.ShippingAddressId, confirmOrder.OrderStatusId, confirmOrder.ShippingStatusId, confirmOrder.PaymentStatusId, confirmOrder.PaymentMethodSystemName, confirmOrder.CustomerCurrencyCode, confirmOrder.CurrencyRate, confirmOrder.
  832. CustomerTaxDisplayTypeId, confirmOrder.VatNumber, confirmOrder.OrderSubtotalInclTax, confirmOrder.OrderSubtotalExclTax, confirmOrder.OrderSubTotalDiscountInclTax, confirmOrder.OrderSubTotalDiscountExclTax, confirmOrder.OrderShippingInclTax, confirmOrder.OrderShippingExclTax, confirmOrder.
  833. PaymentMethodAdditionalFeeInclTax, confirmOrder.PaymentMethodAdditionalFeeExclTax, confirmOrder.TaxRates, confirmOrder.OrderTax, confirmOrder.OrderDiscount, confirmOrder.OrderTotal, confirmOrder.RefundedAmount, confirmOrder.RewardPointsWereAdded, confirmOrder.CheckoutAttributeDescription, confirmOrder.CheckoutAttributesXml, confirmOrder.
  834. CustomerLanguageId, confirmOrder.AffiliateId, confirmOrder.CustomerIp, confirmOrder.AllowStoringCreditCardNumber, confirmOrder.CardType, confirmOrder.CardName, confirmOrder.CardNumber, confirmOrder.MaskedCreditCardNumber, confirmOrder.CardCvv2, confirmOrder.CardExpirationMonth, confirmOrder.CardExpirationYear, confirmOrder.AllowStoringDirectDebit, confirmOrder.
  835. DirectDebitAccountHolder, confirmOrder.DirectDebitAccountNumber, confirmOrder.DirectDebitBankCode, confirmOrder.DirectDebitBankName, confirmOrder.DirectDebitBIC, confirmOrder.DirectDebitCountry, confirmOrder.DirectDebitIban, confirmOrder.AuthorizationTransactionId, confirmOrder.AuthorizationTransactionCode, confirmOrder.
  836. AuthorizationTransactionResult, confirmOrder.CaptureTransactionId, confirmOrder.CaptureTransactionResult, confirmOrder.SubscriptionTransactionId, confirmOrder.PurchaseOrderNumber, confirmOrder.PaidDateUtc, confirmOrder.ShippingMethod, confirmOrder.ShippingRateComputationMethodSystemName, confirmOrder.Deleted, confirmOrder.
  837. CreatedOnUtc, confirmOrder.UpdatedOnUtc, confirmOrder.RewardPointsRemaining, confirmOrder.CustomerOrderComment, confirmOrder.OrderShippingTaxRate, confirmOrder.PaymentMethodAdditionalFeeTaxRate, confirmOrder.HasNewPaymentNotification, confirmOrder.AcceptThirdPartyEmailHandOver, confirmOrder.OrderTotalRounding, createOrder.order_from);
  838. //Insert data in OrderItem table
  839. foreach (DataRow dr2 in MaxQty.Rows)
  840. {
  841. //calculating cart subtotal value
  842. GetCartSubTotal(dr2);
  843. #region OrderItem Data
  844. insertOrderItems.ProductId = (Int32)dr2["ProductId"];
  845. insertOrderItems.Quantity = (Int32)dr2["Quantity"];
  846. insertOrderItems.UnitPriceInclTax = (decimal)dr2["Price"];
  847. insertOrderItems.UnitPriceExclTax = (decimal)dr2["Price"];
  848. insertOrderItems.PriceInclTax = ProductFinalCostInclTax;
  849. insertOrderItems.PriceExclTax = ProductFinalCostExclTax;
  850. insertOrderItems.DiscountAmountInclTax = 0;
  851. insertOrderItems.DiscountAmountExclTax = 0;
  852. insertOrderItems.AttributeDescription = "";
  853. insertOrderItems.AttributesXml = dr2["AttributesXml"].ToString();
  854. insertOrderItems.DownloadCount = 0;
  855. insertOrderItems.IsDownloadActivated = false;
  856. insertOrderItems.LicenseDownloadId = 0;
  857. insertOrderItems.ItemWeight = 0;
  858. insertOrderItems.BundleData = "";
  859. insertOrderItems.ProductCost = 0;
  860. insertOrderItems.TaxRate = 0;
  861. #endregion OrderItem Data
  862. int CustomerId = confirmOrder.CustomerId;
  863. long res1 = OrdersComp.InsertOrderItemsData(CustomerId, insertOrderItems.ProductId, insertOrderItems.Quantity, insertOrderItems.UnitPriceInclTax, insertOrderItems.UnitPriceExclTax, insertOrderItems.PriceInclTax, insertOrderItems.PriceExclTax, insertOrderItems.DiscountAmountInclTax, insertOrderItems.DiscountAmountExclTax, insertOrderItems.AttributeDescription,
  864. insertOrderItems.AttributesXml, insertOrderItems.DownloadCount, insertOrderItems.IsDownloadActivated, insertOrderItems.LicenseDownloadId, insertOrderItems.ItemWeight, insertOrderItems.BundleData, insertOrderItems.ProductCost, insertOrderItems.TaxRate);
  865. RemoveFromCart(Customerid);
  866. UpdateProductStock((Int32)dr2["ProductId"], (Int32)dr2["Quantity"]);
  867. }
  868. if (res > 0)
  869. {
  870. if (createOrder.useFromWallet == 1)
  871. {
  872. float currentbal = Wallet.getCustomerCurrentWalletBalance(createOrder.id_customer);
  873. if (currentbal >= (Int32)CartSubTotal)
  874. {
  875. float PrsntBlnc = currentbal - Convert.ToInt32(CartSubTotal);
  876. //deducting the wallet balance
  877. Wallet.saveWalletBalance(createOrder.id_customer.ToString(), res.ToString(), CartSubTotal.ToString(), PrsntBlnc.ToString(), 2, 2, MyIPAddress, "Place Order Using COD with Wallet ");
  878. ResponseObj.status = 1;
  879. ResponseObj.message = "Order Placed Successfully";
  880. ResponseObj.order_id = res;
  881. }
  882. else
  883. {
  884. float PrsntBlnc = currentbal - Convert.ToInt32(CartSubTotal);
  885. if (PrsntBlnc < 0)
  886. {
  887. PrsntBlnc = 0;
  888. }
  889. //deducting the wallet balance
  890. Wallet.saveWalletBalance(createOrder.id_customer.ToString(), res.ToString(), currentbal.ToString(), PrsntBlnc.ToString(), 2, 2, MyIPAddress, "Place Order Using COD with Wallet ");
  891. ResponseObj.status = 1;
  892. ResponseObj.message = "Order Placed Successfully";
  893. ResponseObj.order_id = res;
  894. }
  895. }
  896. else
  897. {
  898. ResponseObj.status = 1;
  899. ResponseObj.message = "Order Placed Successfully";
  900. ResponseObj.order_id = res;
  901. }
  902. }
  903. else
  904. {
  905. ResponseObj.message = Common.OopsSomethingWentWrong;
  906. ResponseObj.status = 0;
  907. }
  908. }
  909. else
  910. {
  911. ResponseObj.message = "Cart is Empty.. Please add items to cart before place order";
  912. ResponseObj.status = 0;
  913. }
  914. }
  915. }
  916. else
  917. {
  918. ResponseObj.message = "Cart is Empty.. Please add items to cart before place order";
  919. ResponseObj.status = 0;
  920. }
  921. }
  922. else
  923. {
  924. ResponseObj.message = "id_address_delivery does not belogs to the customer";
  925. ResponseObj.status = 0;
  926. }
  927. }
  928. else
  929. {
  930. var error = ModelState.SelectMany(x => x.Value.Errors).First();
  931. if (error.ErrorMessage != null && error.ErrorMessage != String.Empty)
  932. return Request.CreateErrorResponse(HttpStatusCode.BadRequest, error.ErrorMessage);
  933. return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
  934. }
  935. }
  936. else
  937. {
  938. ResponseObj.message = Common.OopsSomethingWentWrong;
  939. ResponseObj.status = 0;
  940. }
  941. }
  942. catch (Exception Err)
  943. {
  944. }
  945. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  946. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  947. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  948. return HttpResponseMessage;
  949. }
  950. [NonAction]
  951. public Decimal GetOrderTotalInclTax(DataTable dataTable)
  952. {
  953. result = 0;
  954. return result;
  955. }
  956. [NonAction]
  957. public Decimal GetOrderTotalExclTax(DataTable dataTable)
  958. {
  959. result = 0;
  960. return result;
  961. }
  962. [NonAction]
  963. public decimal GetCartSubTotal(DataRow dataRow)
  964. {
  965. result = 0;
  966. try
  967. {
  968. if (dataRow["SpecialPrice"].ToString() == "")
  969. {
  970. string str = dataRow["AttributesXml"].ToString();
  971. Product_GetPriceAdjustment(str);
  972. GetTaxRate((Int32)dataRow["id"]);
  973. //Checking Tier Price for the product
  974. if ((bool) dataRow["HasTierPrices"]==true)
  975. {
  976. GetTierProdutTierPrice((Int32)dataRow["id"], (Int32)dataRow["Quantity"]);
  977. }
  978. if(ProductTierPrice !=decimal.Zero)
  979. {
  980. ProductInitialPrice = ProductTierPrice;
  981. }
  982. else
  983. {
  984. ProductInitialPrice = (decimal)dataRow["Price"];
  985. }
  986. ProductFinalCost = decimal.Zero;
  987. ProductFinalCost = decimal.Multiply((ProductInitialPrice + ProductAdjPrice), (Int32)dataRow["Quantity"]);
  988. //ProductFinalCost = decimal.Multiply(((decimal)dataRow["Price"] + ProductAdjPrice - (decimal)dataRow["Discount"]), (Int32)dataRow["Quantity"]);
  989. ProductFinalCostExclTax = ProductFinalCost;
  990. ProductFinalCostInclTax = ProductFinalCost * (1 + taxrate / 100);
  991. }
  992. else
  993. {
  994. string str = dataRow["AttributesXml"].ToString();
  995. Product_GetPriceAdjustment(str);
  996. GetTaxRate((Int32)dataRow["id"]);
  997. ProductFinalCost = decimal.Zero;
  998. //ProductFinalCost = decimal.Multiply(((decimal)dataRow["SpecialPrice"] + ProductAdjPrice - (decimal)dataRow["Discount"]), (Int32)dataRow["Quantity"]);
  999. ProductFinalCost = decimal.Multiply(((decimal)dataRow["Price"] + ProductAdjPrice ), (Int32)dataRow["Quantity"]);
  1000. ProductFinalCostExclTax = ProductFinalCost;
  1001. ProductFinalCostInclTax = ProductFinalCost * (1 + taxrate / 100);
  1002. }
  1003. }
  1004. catch (Exception Err)
  1005. {
  1006. }
  1007. return CartSubTotal;
  1008. }
  1009. [NonAction]
  1010. private decimal Product_GetPriceAdjustment(string attribute )
  1011. {
  1012. ProductAdjPrice = decimal.Zero;
  1013. try
  1014. {
  1015. if (attribute != "")
  1016. {
  1017. var attributesXml = attribute.ToString();
  1018. var doc = XDocument.Parse(attributesXml);
  1019. // Attributes/ProductVariantAttribute
  1020. foreach (var node1 in doc.Descendants("ProductVariantAttribute"))
  1021. {
  1022. string ID = node1.Attribute("ID").Value;
  1023. int ir = int.Parse(ID);
  1024. // ProductVariantAttributeValue/Value
  1025. foreach (int node2 in node1.Descendants("Value"))
  1026. {
  1027. int Val = node2;
  1028. dt2 = GetPriceAjustments(ir, Val);
  1029. if (dt2.Rows.Count > 0)
  1030. {
  1031. decimal AdditionalPrice = decimal.Zero;
  1032. AdditionalPrice = (decimal)dt2.Rows[0][0];
  1033. ProductAdjPrice += AdditionalPrice;
  1034. }
  1035. }
  1036. }
  1037. }
  1038. }
  1039. catch (Exception Err)
  1040. {
  1041. }
  1042. return result;
  1043. }
  1044. [NonAction]
  1045. private DataTable GetPriceAjustments(int ID, int Value)
  1046. {
  1047. dt2 = OrdersComp.GetPriceAdjnustment(ID, Value);
  1048. return dt2;
  1049. }
  1050. [NonAction ]
  1051. private decimal GetTaxRate(int productID)
  1052. {
  1053. taxrate = decimal.Zero;
  1054. try
  1055. {
  1056. DataTable dt1 = OrdersComp.GetProductTaxCategory(productID);
  1057. if (dt1.Rows.Count > 0 && (bool)dt1.Rows[0]["IsTaxExempt"] == false)
  1058. {
  1059. taxrate = (decimal)dt1.Rows[0]["Percentage"];
  1060. }
  1061. else if (dt1.Rows.Count > 0 && (bool)dt1.Rows[0]["IsTaxExempt"] == true)
  1062. {
  1063. taxrate = 0;
  1064. }
  1065. }
  1066. catch (Exception Err)
  1067. {
  1068. }
  1069. return result=taxrate;
  1070. }
  1071. [NonAction]
  1072. private void RemoveFromCart(int CustomerID)
  1073. {
  1074. try
  1075. {
  1076. long res = OrdersComp.RemoveFromCart(CustomerID);
  1077. }
  1078. catch (Exception Err)
  1079. {
  1080. }
  1081. }
  1082. [NonAction]
  1083. private void UpdateProductStock(int ProductId, int Qty)
  1084. {
  1085. try
  1086. {
  1087. long res = OrdersComp.UpdateProductStock(ProductId, Qty);
  1088. }
  1089. catch (Exception Err)
  1090. {
  1091. }
  1092. }
  1093. [NonAction]
  1094. private void GetTierProdutTierPrice(int ProductId, int Qty)
  1095. {
  1096. try
  1097. {
  1098. DataTable dt1 = OrdersComp.GetTierPrice(ProductId);
  1099. if(dt1.Rows.Count > 0)
  1100. {
  1101. for(int i=0;i<=dt1.Rows.Count-1;i++)
  1102. {
  1103. if(Qty >= (Int32) dt1.Rows[i]["Quantity"] )
  1104. {
  1105. ProductTierPrice = (decimal)dt1.Rows[i]["TierPrice"];
  1106. }
  1107. }
  1108. }
  1109. else
  1110. {
  1111. ProductTierPrice = decimal.Zero;
  1112. }
  1113. }
  1114. catch (Exception Err)
  1115. {
  1116. }
  1117. }
  1118. [HttpPost]
  1119. [Authorize]
  1120. public HttpResponseMessage CreateOrderUsingPayment([FromBody][Required]CreateOrderUsingPayment createOrderUsingPayment)
  1121. {
  1122. CreateOrderPaymentResponseObj ResponseObj = new CreateOrderPaymentResponseObj();
  1123. HttpResponseMessage HttpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  1124. string response = "";
  1125. try
  1126. {
  1127. if (createOrderUsingPayment != null)
  1128. {
  1129. if (ModelState.IsValid)
  1130. {
  1131. string orderid = "";
  1132. if (createOrderUsingPayment.order_id != "" && createOrderUsingPayment.order_id != "0" && createOrderUsingPayment.order_id != null)
  1133. {
  1134. string sub = createOrderUsingPayment.order_id.Substring(0, 3);
  1135. if (sub == "odr")
  1136. {
  1137. orderid = createOrderUsingPayment.order_id.Substring(3);
  1138. }
  1139. }
  1140. response = PlaceOrder.CreateOrderWithPayment(createOrderUsingPayment.id_customer.ToString(), createOrderUsingPayment.id_address_delivery.ToString(), createOrderUsingPayment.useFromWallet.ToString(), createOrderUsingPayment.order_from, orderid);
  1141. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  1142. return HttpResponseMessage;
  1143. }
  1144. else
  1145. {
  1146. var error = ModelState.SelectMany(x => x.Value.Errors).First();
  1147. if (error.ErrorMessage != null && error.ErrorMessage != String.Empty)
  1148. return Request.CreateErrorResponse(HttpStatusCode.BadRequest, error.ErrorMessage);
  1149. return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
  1150. }
  1151. }
  1152. else
  1153. {
  1154. createorderPaymentResult resul = new createorderPaymentResult();
  1155. resul.message= Common.OopsSomethingWentWrong;
  1156. ResponseObj.result = resul;
  1157. ResponseObj.status = 0;
  1158. }
  1159. }
  1160. catch (Exception Err)
  1161. {
  1162. }
  1163. response = JsonConvert.SerializeObject(ResponseObj, Formatting.None);
  1164. HttpResponseMessage.Content = new StringContent(response, Encoding.UTF8, "application/json");
  1165. return HttpResponseMessage;
  1166. }
  1167. }
  1168. }