public WalletModel.RedeemePromoCodeFromOrder RedeemePromoCodeFromOrder(string CustomerId = "", string OrderAmount = "", string PromoCode = "") { WalletModel.RedeemePromoCodeFromOrder objeWalletdt = new WalletModel.RedeemePromoCodeFromOrder(); try { objeWalletdt.response = "1"; objeWalletdt.message = "Successfully"; string where = ""; if (CustomerId != "" && CustomerId != null) { where = "AND [WC].customer_id=" + CustomerId; string querymain = " SELECT Top 1 w.wallet_id,WC.Id as wallet_link_id, W.terms AS CR_description, WC.created_date AS CR_date,W.per_type," + " W.per_amount,wallet_amount,per_type,per_amount, W.min_order_amount, ISNULL((select isnull(H.balance,0) " + " from [tblWalletCustomerHistory] H " + " where H.Id = (select max(id) From[tblWalletCustomerHistory] Hi where Hi.customer_id = Wc.customer_id)),0) as Balance, " + " O.offer_id, O.offer_name" + " FROM[tblWalletCustomerLink] WC " + " INNER JOIN[WalletMaster] W ON W.wallet_id = WC.wallet_id " + " INNER JOIN tblOfferTypes O ON O.offer_id = W.offer_id " + where + " AND ISNULL(W.coupon_code,'') != '' " + " AND W.is_active = 1 " + " AND ISNULL(WC.is_used,0) = 0 " + " AND GETDATE() >= W.start_date and GETDATE() <= W.end_date " + " AND W.coupon_code = '" + PromoCode + "'" + " order by WC.created_date asc "; DataTable dtmain = dbc.GetDataTable(querymain); if (dtmain != null && dtmain.Rows.Count > 0) { for (int i = 0; i < dtmain.Rows.Count; i++) { string walletId = dtmain.Rows[i]["wallet_id"].ToString(); string walletlinkId = dtmain.Rows[i]["wallet_link_id"].ToString(); decimal walletAmt = Convert.ToDecimal(dtmain.Rows[i]["wallet_amount"]); string pertype = dtmain.Rows[i]["per_type"].ToString(); decimal perAmt = Convert.ToDecimal(dtmain.Rows[i]["per_amount"]); decimal minOrdAmt = Convert.ToDecimal(dtmain.Rows[i]["min_order_amount"]); string crDate = dtmain.Rows[i]["CR_date"].ToString(); string crDescription = dtmain.Rows[i]["CR_description"].ToString(); string balance = dtmain.Rows[i]["balance"].ToString(); string offerId = dtmain.Rows[i]["offer_id"].ToString(); string offerName = dtmain.Rows[i]["offer_name"].ToString(); decimal calcAmt = 0; if (dtmain.Rows[i]["per_type"].ToString() == "Fixed" || dtmain.Rows[i]["per_type"].ToString() == "Full Amount Applicable") { calcAmt = perAmt; } if (dtmain.Rows[i]["per_type"].ToString() == "%") { calcAmt = (Convert.ToDecimal(OrderAmount) * perAmt) / 100; } objeWalletdt.PromoCodeId = walletId; objeWalletdt.PromoCodeLinkId = walletlinkId; objeWalletdt.PromoCodetype = pertype; objeWalletdt.PromoCodeCrAmount = perAmt.ToString(); objeWalletdt.PromoCodeCrDate = crDate; objeWalletdt.PromoCodeCrDescription = crDescription; objeWalletdt.PromoCodebalance = balance; objeWalletdt.PromoCodeCalcAmount = calcAmt.ToString(); objeWalletdt.OfferId = offerId; objeWalletdt.OfferName = offerName; if (dtmain.Rows[i]["per_type"].ToString() == "Fixed") { if (calcAmt > perAmt) { objeWalletdt.response = CommonString.DataNotFoundResponse; objeWalletdt.message = CommonString.DataNotFoundMessage; objeWalletdt.ValidationMessage = "Coupon code can only be used for order amount more than ₹ " + minOrdAmt; } else if (calcAmt <= perAmt) { objeWalletdt.response = CommonString.successresponse; objeWalletdt.message = CommonString.successmessage; if (offerName == "Discount") { objeWalletdt.ValidationMessage = "Congratulation! you got a discount of ₹ " + calcAmt + " for this order."; } else { objeWalletdt.ValidationMessage = "Congratulation! you got a cashback of ₹ " + calcAmt + " in your wallet."; } } } if (dtmain.Rows[i]["per_type"].ToString() == "%") { decimal redeemPerAmt = (Convert.ToDecimal(OrderAmount) * perAmt) / 100; if (calcAmt > redeemPerAmt) { objeWalletdt.response = CommonString.DataNotFoundResponse; objeWalletdt.message = CommonString.DataNotFoundMessage; objeWalletdt.ValidationMessage = "Coupon code can only be used for order amount more than ₹ " + minOrdAmt; } else if (calcAmt <= redeemPerAmt) { objeWalletdt.response = CommonString.successresponse; objeWalletdt.message = CommonString.successmessage; if (offerName == "Discount") { objeWalletdt.ValidationMessage = "Congratulation! you got a discount of ₹ " + calcAmt + " for this order."; } else { objeWalletdt.ValidationMessage = "Congratulation! you got a cashback of ₹ " + calcAmt + " in your wallet."; } } } if (dtmain.Rows[i]["per_type"].ToString() == "Full Amount Applicable") { if (calcAmt > perAmt) { objeWalletdt.response = CommonString.DataNotFoundResponse; objeWalletdt.message = CommonString.DataNotFoundMessage; objeWalletdt.ValidationMessage = "Coupon code can only be used for order amount more than ₹ " + minOrdAmt; } else if (calcAmt <= perAmt) { objeWalletdt.response = CommonString.successresponse; objeWalletdt.message = CommonString.successmessage; if (offerName == "Discount") { objeWalletdt.ValidationMessage = "Congratulation! you got a discount of ₹ " + calcAmt + " for this order."; } else { objeWalletdt.ValidationMessage = "Congratulation! you got a cashback of ₹ " + calcAmt + " in your wallet."; } } } if (minOrdAmt > Convert.ToDecimal(OrderAmount)) { objeWalletdt.response = CommonString.DataNotFoundResponse; objeWalletdt.message = CommonString.DataNotFoundMessage; objeWalletdt.ValidationMessage = "Coupon code can only be used for order amount more than ₹ " + minOrdAmt; } } } else { objeWalletdt.PromoCodeId = "0"; objeWalletdt.PromoCodeLinkId = "0"; objeWalletdt.PromoCodetype = ""; objeWalletdt.PromoCodeCrAmount = "0"; objeWalletdt.PromoCodeCrDate = ""; objeWalletdt.PromoCodeCrDescription = ""; objeWalletdt.PromoCodebalance = "0"; objeWalletdt.PromoCodeCalcAmount = "0"; objeWalletdt.response = CommonString.DataNotFoundResponse; objeWalletdt.message = CommonString.DataNotFoundMessage; objeWalletdt.ValidationMessage = ""; } } return(objeWalletdt); } catch (Exception ex) { objeWalletdt.response = CommonString.Errorresponse; objeWalletdt.message = ex.StackTrace + " " + ex.Message; return(objeWalletdt); } }
public static void ConfirmOrder() { List <ClsOrderModels.ConfirmOrderNewModel> summeryModel; if ((HttpContext.Current.Session["summeryModel"] != null)) { summeryModel = (List <ClsOrderModels.ConfirmOrderNewModel>)HttpContext.Current.Session["summeryModel"]; } else { summeryModel = new List <ClsOrderModels.ConfirmOrderNewModel>(); } ClsOrderModels.PlaceMultipleOrderNewModel OrderDetail; WalletModel.RedeemeWalletFromOrder walletHistory; WalletModel.RedeemePromoCodeFromOrder PromoHistory; if ((HttpContext.Current.Session["ConfirmOrder"] != null)) { //OrderDetail = (ClsOrderModels.PlaceMultipleOrderModel)HttpContext.Current.Session["ConfirmOrder"]; OrderDetail = (ClsOrderModels.PlaceMultipleOrderNewModel)HttpContext.Current.Session["ConfirmOrder"]; } else { //OrderDetail = new ClsOrderModels.PlaceMultipleOrderModel(); OrderDetail = new ClsOrderModels.PlaceMultipleOrderNewModel(); } if ((HttpContext.Current.Session["WalletHistory"] != null)) { walletHistory = (WalletModel.RedeemeWalletFromOrder)HttpContext.Current.Session["WalletHistory"]; } else { walletHistory = new WalletModel.RedeemeWalletFromOrder(); } if ((HttpContext.Current.Session["PromoHistory"] != null)) { PromoHistory = (WalletModel.RedeemePromoCodeFromOrder)HttpContext.Current.Session["PromoHistory"]; } else { PromoHistory = new WalletModel.RedeemePromoCodeFromOrder(); } OrderDetail.WalletId = walletHistory.WalletId; OrderDetail.WalletLinkId = walletHistory.WalletLinkId; OrderDetail.WalletType = walletHistory.WalletType; OrderDetail.Walletbalance = walletHistory.balance; OrderDetail.WalletCrAmount = walletHistory.CrAmount; OrderDetail.WalletCrDate = walletHistory.CrDate; OrderDetail.WalletCrDescription = walletHistory.CrDescription; //OrderDetail.PromoCodeamount = PromoAmount; OrderDetail.PromoCodebalance = PromoHistory.PromoCodebalance; OrderDetail.PromoCodeCrAmount = PromoHistory.PromoCodeCrAmount; OrderDetail.PromoCodeCrDate = PromoHistory.PromoCodeCrDate; OrderDetail.PromoCodeCrDescription = PromoHistory.PromoCodeCrDescription; OrderDetail.PromoCodeId = PromoHistory.PromoCodeId; OrderDetail.PromoCodeLinkId = PromoHistory.PromoCodeLinkId; OrderDetail.PromoCodetype = PromoHistory.PromoCodetype; string PromoAmount = string.Empty; string Discount = string.Empty; string PaidAmt = string.Empty; string PromoCode = string.Empty; string reorderid = "0"; string redeemamount = string.Empty; string totalamount = string.Empty; if ((HttpContext.Current.Session["PromoAmount"] != null) && (HttpContext.Current.Session["PromoAmount"].ToString() != "")) { PromoAmount = HttpContext.Current.Session["PromoAmount"].ToString(); } if ((HttpContext.Current.Session["Discount"] != null) && (HttpContext.Current.Session["Discount"].ToString() != "")) { Discount = HttpContext.Current.Session["Discount"].ToString(); } if ((HttpContext.Current.Session["PaidAmt"] != null) && (HttpContext.Current.Session["PaidAmt"].ToString() != "")) { PaidAmt = HttpContext.Current.Session["PaidAmt"].ToString(); } if ((HttpContext.Current.Session["PromoCode"] != null) && (HttpContext.Current.Session["PromoCode"].ToString() != "")) { PromoCode = HttpContext.Current.Session["PromoCode"].ToString(); } if ((HttpContext.Current.Session["reorderid"] != null) && (HttpContext.Current.Session["reorderid"].ToString() != "")) { reorderid = HttpContext.Current.Session["reorderid"].ToString(); } if ((HttpContext.Current.Session["redeemamount"] != null) && (HttpContext.Current.Session["redeemamount"].ToString() != "")) { redeemamount = HttpContext.Current.Session["redeemamount"].ToString(); } if ((HttpContext.Current.Session["totalamount"] != null) && (HttpContext.Current.Session["totalamount"].ToString() != "")) { totalamount = HttpContext.Current.Session["totalamount"].ToString(); } OrderDetail.Cashbackamount = string.IsNullOrEmpty(PromoAmount) ? 0 : Convert.ToDecimal(PromoAmount); OrderDetail.discountamount = Discount; OrderDetail.PaidAmount = Convert.ToDecimal(PaidAmt); OrderDetail.PromoCode = PromoCode; OrderDetail.ReOrderId = reorderid; decimal payableamt = 0; decimal.TryParse(OrderDetail.products[0].PaidAmount.ToString(), out payableamt); if (payableamt > 0) { NewCode: string CCCode = ""; string refercode = ""; string addressid = ""; if ((HttpContext.Current.Session["ReferCode"] != null) && (HttpContext.Current.Session["ReferCode"].ToString() != "")) { refercode = HttpContext.Current.Session["ReferCode"].ToString(); } if ((HttpContext.Current.Session["fcode"] != null) && (HttpContext.Current.Session["fcode"].ToString() != "")) { refercode = HttpContext.Current.Session["fcode"].ToString(); } if ((HttpContext.Current.Session["JurisdictionId"] != null) && (HttpContext.Current.Session["JurisdictionId"].ToString() != "")) { OrderDetail.JurisdictionID = HttpContext.Current.Session["JurisdictionId"].ToString(); } //if (refercode == "") //{ // string coddd = clsCommon.GenerateRandomNumber().ToString(); // int test = getcheck(coddd); // if (test == 0) // { // goto NewCode; // } // CCCode = coddd; //} //else //{ //} if ((HttpContext.Current.Session["Addressid"] != null)) { addressid = HttpContext.Current.Session["Addressid"].ToString(); addressid = clsCommon.Base64Decode(addressid); } OrderDetail.AddressId = addressid; OrderDetail.CustomerId = clsCommon.getCurrentCustomer().id; OrderDetail.Redeemeamount = redeemamount; OrderDetail.orderMRP = totalamount; OrderDetail.totalAmount = totalamount; foreach (var item in OrderDetail.products) { item.couponCode = CCCode; item.refrcode = refercode; } if (summeryModel.Count > 0 && summeryModel != null) { int totalqty = 0; //List<ClsOrderModels.OrderQuantityModel> orderQuantities = new List<ClsOrderModels.OrderQuantityModel>(); //OrderDetail.orderMRP = totalamount; //OrderDetail.totalAmount = totalamount; foreach (var item in summeryModel) { foreach (var product in OrderDetail.products) { if (item.Productid == product.productid) { product.Quantity = item.Qty.ToString(); } } } for (int i = 0; i < OrderDetail.products.Count; i++) { totalqty += Convert.ToInt32(OrderDetail.products[i].Quantity); } OrderDetail.totalQty = totalqty.ToString(); } WebClient client = new WebClient(); client.Encoding = Encoding.UTF8; client.Headers["Content-type"] = "application/json"; client.Headers["DeviceType"] = "Web"; var model = JsonConvert.SerializeObject(OrderDetail); //var data = client.UploadString(clsCommon.strApiUrl + "/api/CODOrder/CODPlaceMultipleOrder", model); var data = client.UploadString(clsCommon.strApiUrl + "/api/CODOrder/CODPlaceMultipleOrderNew", model); //string creaturl = clsCommon.strApiUrl + "/api/CODOrder/CODPlaceOrder?CustomerId=" + CustId + "&PaidAmount=" + PayAmt + "&AddressId=" + addr + "&Quantity=" + qty + "&buywith=" + buyflag + "&discountamount=" + disc + "&Redeemeamount=" + redm + "&couponCode=" + (String.IsNullOrWhiteSpace(CCCode) ? "0" : CCCode) + "&refrcode=" + (String.IsNullOrWhiteSpace(rcode) ? "0" : rcode) + ""; //string creaturl = clsCommon.strApiUrl + "/api/CODOrder/CODPlaceOrder?CustomerId=" + CustId + "&PaidAmount=" + PayAmt + "&AddressId=" + addr + "&Quantity=" + qty + "&buywith=" + buyflag + "&discountamount=" + disc + "&Redeemeamount=" + redm + "&couponCode=" + (String.IsNullOrWhiteSpace(CCCode) ? "0" : CCCode) + "&refrcode=" + rcode + ""; //string res = clsCommon.GET(creaturl); if (!string.IsNullOrWhiteSpace(data)) { ClsOrderModels.PlaceOrderModel objplaceorder = JsonConvert.DeserializeObject <ClsOrderModels.PlaceOrderModel>(data); //ClsOrderModels.PlaceMultipleOrderNewModel objplaceorder = JsonConvert.DeserializeObject<ClsOrderModels.PlaceMultipleOrderNewModel>(data); if (objplaceorder.resultflag == "1") { string Oid = objplaceorder.OrderId; string value = clsCommon.Base64Encode(Oid); string couponcode = objplaceorder.Ccode; if (!string.IsNullOrWhiteSpace(Oid)) { HttpContext.Current.Session["PlaceOrderId"] = value; HttpContext.Current.Session["CouponCode"] = couponcode; //return data; } } } } }