Exemplo n.º 1
0
        public WalletModel.RedeemeWalletFromOrder RedeemeWalletFromOrder(string CustomerId = "", string OrderAmount = "", string RedeemeAmount = "")
        {
            WalletModel.RedeemeWalletFromOrder objeWalletdt = new WalletModel.RedeemeWalletFromOrder();
            try
            {
                objeWalletdt.response          = "1";
                objeWalletdt.message           = "Successfully";
                objeWalletdt.WalletId          = "";
                objeWalletdt.WalletLinkId      = "";
                objeWalletdt.WalletType        = "";
                objeWalletdt.CrAmount          = "";
                objeWalletdt.CrDate            = "";
                objeWalletdt.CrDescription     = "";
                objeWalletdt.balance           = "";
                objeWalletdt.ValidationMessage = "";
                string where = "";
                if (CustomerId != "" && CustomerId != null)
                {
                    where = "AND [H].customer_id=" + CustomerId;
                    string querymain = "SELECT Top 1 w.wallet_id,H.wallet_link_id, W.terms AS CR_description, " +
                                       " WC.created_date AS CR_date,campaign_name,wallet_amount, H.balance " +
                                       " FROM[tblWalletCustomerHistory] H " +
                                       " INNER JOIN[tblWalletCustomerLink] WC ON H.wallet_id = WC.wallet_id " +
                                       " INNER JOIN[WalletMaster] W ON W.wallet_id = WC.wallet_id " +
                                       where +
                                       " AND W.is_active = 1 " +
                                       " AND H.balance > 0 " +
                                       " AND GETDATE() >=  W.start_date and GETDATE() <= W.end_date " +
                                       " Order by H.Id desc";
                    DataTable dtmain = dbc.GetDataTable(querymain);
                    if (dtmain != null && dtmain.Rows.Count > 0)
                    {
                        string walletId   = dtmain.Rows[0]["wallet_id"].ToString();
                        string usagequery = "SELECT w.per_type,w.per_amount,w.min_order_amount " +
                                            " FROM[tblWalletUsageMaster] w " +
                                            " WHERE w.is_active = 1 ";

                        DataTable dtusageQry = dbc.GetDataTable(usagequery);
                        //for (int i = 0; i < dtmain.Rows.Count; i++)
                        //{
                        string  walletlinkId  = dtmain.Rows[0]["wallet_link_id"].ToString();
                        decimal walletAmt     = Convert.ToDecimal(dtmain.Rows[0]["wallet_amount"]);
                        decimal perAmt        = Convert.ToDecimal(dtusageQry.Rows[0]["per_amount"]);
                        decimal minOrdAmt     = Convert.ToDecimal(dtusageQry.Rows[0]["min_order_amount"]);
                        string  crDate        = dtmain.Rows[0]["CR_date"].ToString();
                        string  crDescription = dtmain.Rows[0]["CR_description"].ToString();
                        string  balance       = dtmain.Rows[0]["balance"].ToString();
                        string  pertype       = dtusageQry.Rows[0]["per_type"].ToString();

                        objeWalletdt.WalletId      = walletId;
                        objeWalletdt.WalletLinkId  = walletlinkId;
                        objeWalletdt.WalletType    = pertype;
                        objeWalletdt.CrAmount      = perAmt.ToString();
                        objeWalletdt.CrDate        = crDate;
                        objeWalletdt.CrDescription = crDescription;
                        objeWalletdt.balance       = balance;

                        if (Convert.ToDecimal(balance) >= Convert.ToDecimal(RedeemeAmount))
                        {
                            if (dtusageQry.Rows[0]["per_type"].ToString() == "Fixed")
                            {
                                if (Convert.ToDecimal(RedeemeAmount) > perAmt)
                                {
                                    objeWalletdt.response          = CommonString.DataNotFoundResponse;
                                    objeWalletdt.message           = CommonString.DataNotFoundMessage;
                                    objeWalletdt.ValidationMessage = "You can redeem maximun ₹ " + perAmt + " for this order.";
                                }
                                else if (Convert.ToDecimal(RedeemeAmount) <= perAmt)
                                {
                                    objeWalletdt.response          = CommonString.successresponse;
                                    objeWalletdt.message           = CommonString.successmessage;
                                    objeWalletdt.ValidationMessage = "You have successfully redeemed ₹ " + RedeemeAmount + " for this order.";
                                }
                            }
                            if (dtusageQry.Rows[0]["per_type"].ToString() == "%")
                            {
                                //decimal redeemPerAmt = (walletAmt * perAmt) / 100;
                                decimal redeemPerAmt = (Convert.ToDecimal(balance) * perAmt) / 100;
                                if (Convert.ToDecimal(RedeemeAmount) > redeemPerAmt)
                                {
                                    objeWalletdt.response          = CommonString.DataNotFoundResponse;
                                    objeWalletdt.message           = CommonString.DataNotFoundMessage;
                                    objeWalletdt.ValidationMessage = "You can redeem maximun ₹ " + redeemPerAmt + " for this order.";
                                }
                                else if (Convert.ToDecimal(RedeemeAmount) <= redeemPerAmt)
                                {
                                    objeWalletdt.response          = CommonString.successresponse;
                                    objeWalletdt.message           = CommonString.successmessage;
                                    objeWalletdt.ValidationMessage = "You have successfully redeemed ₹ " + RedeemeAmount + " for this order.";
                                }
                            }
                            if (dtusageQry.Rows[0]["per_type"].ToString() == "Full Amount Applicable")
                            {
                                if (Convert.ToDecimal(RedeemeAmount) > perAmt)
                                {
                                    objeWalletdt.response          = CommonString.DataNotFoundResponse;
                                    objeWalletdt.message           = CommonString.DataNotFoundMessage;
                                    objeWalletdt.ValidationMessage = "You can redeem maximun ₹ " + perAmt + " for this order.";
                                }
                                else if (Convert.ToDecimal(RedeemeAmount) <= perAmt)
                                {
                                    objeWalletdt.response          = CommonString.successresponse;
                                    objeWalletdt.message           = CommonString.successmessage;
                                    objeWalletdt.ValidationMessage = "You have successfully redeemed ₹ " + RedeemeAmount + " for this order.";
                                }
                            }
                            if (minOrdAmt > Convert.ToDecimal(OrderAmount))
                            {
                                objeWalletdt.response          = CommonString.DataNotFoundResponse;
                                objeWalletdt.message           = CommonString.DataNotFoundMessage;
                                objeWalletdt.ValidationMessage = "Wallet money can be redeemed only if minimum order amount is more than ₹ " + minOrdAmt;
                            }
                        }
                        else
                        {
                            objeWalletdt.response          = CommonString.DataNotFoundResponse;
                            objeWalletdt.message           = CommonString.DataNotFoundMessage;
                            objeWalletdt.ValidationMessage = "Your Wallet money is ₹ " + balance;
                        }
                    }
                }
                else
                {
                    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);
            }
        }
Exemplo n.º 2
0
    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;
                    }
                }
            }
        }
    }