public int CreateAlternateOrder(string Customerid, string transid, string Address, string paidAmount, string Quantity, string buywith, string discountamount = "", string Redemeamount = "", string coupanCode = "")
        {
            try
            {
                Logger.InsertLogsApp("PlaceOrder CreateAlternateOrder start : step 1");
                if (discountamount == "")
                { discountamount = "0"; }
                if (Redemeamount == "")
                { Redemeamount = "0"; }
                if (coupanCode == "")
                { coupanCode = "0"; }

                decimal totalamount = 0;
                decimal totalgram = 0;
                decimal totaloffer = 0;
                decimal totalsaving = 0;
                decimal totalquantity = 0;
                decimal shiprate = 0;
                decimal newprice = 0, NewTotalAmount = 0;

                string startdate = dbCon.getindiantime().ToString("dd/MMM/yyyy HH:mm:ss");
                DataTable ShipperList = dbCon.GetAllActiveShipperDetails();
                string qrypncd = "select Pincode from [CustomerAddress] where Id="+Address +"and CustomerId="+Customerid;
                DataTable dtpncd = dbCon.GetDataTable(qrypncd);
                int pincode = int.Parse(dtpncd.Rows[0]["Pincode"].ToString());
                foreach (DataRow dr in ShipperList.Rows)
                {
                    int ShipperId = int.Parse(dr["Id"].ToString());
                    Logger.InsertLogsApp("PlaceOrder CreateAlternateOrder CheckAvailability : step 2");
                    var value = dbCon.CheckAvailability(pincode, ShipperId);

                    if (value > 0)
                    {
                        Logger.InsertLogsApp("PlaceOrder CreateAlternateOrder CheckAvailability start : step 3");
                        //string querystr = "select * from Product where IsActive=1 and IsDeleted=0 and [StartDate]<='" + startdate + "' and [EndDate]>='" + startdate + "' and id=1045";
                        string querystr = "select * from Product Where StartDate<='" + dbCon.getindiantime().ToString("dd/MMM/yyyy HH:mm:ss") + "' and EndDate>='" + dbCon.getindiantime().ToString("dd/MMM/yyyy HH:mm:ss") + "'";

                        DataTable dtmain = dbCon.GetDataTable(querystr);

                        if (dtmain != null && dtmain.Rows.Count > 0)
                        {
                            Logger.InsertLogsApp("PlaceOrder CreateAlternateOrder dtmain start : step 4");
                            int productid = Convert.ToInt32(dtmain.Rows[0]["Id"]);
                            decimal offer = 0, price = 0,buywithprice=0;
                            offer = Convert.ToDecimal(dtmain.Rows[0]["Offer"]);
                            //for check pincode servicebility
                            //DataTable dtZippcode = dbCon.GetDataTable("select ZipPostalCode from [Address] where Id=" + Address);
                            // objorder.IsServicable = ChecoutCheckPinCode(dtZippcode.Rows[0]["ZipPostalCode"].ToString(), productid.ToString()).ToString();
                            string productname = dtmain.Rows[0]["Name"].ToString();
                            int gram = 0;
                            int quantity = Convert.ToInt32(Quantity);
                            price = Convert.ToDecimal(dtmain.Rows[0]["Mrp"]);
                             
                            decimal finalamount= 0,newfinalamount=0;
                            finalamount = Convert.ToDecimal(dtmain.Rows[0]["Mrp"]) * quantity;

                            if(buywith =="1")
                            {
                                buywithprice = Convert.ToDecimal(dtmain.Rows[0]["Mrp"]);
                                newfinalamount = Convert.ToDecimal(dtmain.Rows[0]["Mrp"]) * quantity;
                            }
                            else if(buywith =="2")
                            {
                                buywithprice = Convert.ToDecimal(dtmain.Rows[0]["BuyWith1FriendExtraDiscount"]);
                                newfinalamount = Convert.ToDecimal(dtmain.Rows[0]["BuyWith1FriendExtraDiscount"]) * quantity;
                            }
                            else if(buywith =="6")
                            {
                                buywithprice = Convert.ToDecimal(dtmain.Rows[0]["BuyWith5FriendExtraDiscount"]);
                                newfinalamount = Convert.ToDecimal(dtmain.Rows[0]["BuyWith5FriendExtraDiscount"]) * quantity;
                            }

                            decimal PricePerUnit = Math.Round(newfinalamount / quantity);
                            decimal FixedPrice = Convert.ToDecimal(dtmain.Rows[0]["FixedShipRate"]);

                            totaloffer += offer * quantity;
                            if (totaloffer > 0)
                            {
                                newprice = newfinalamount - offer;
                            }
                            else
                            {
                                newprice = newfinalamount;
                            }
                            gram = Convert.ToInt32(dtmain.Rows[0]["Unit"].ToString());
                            totalgram += (gram * quantity);
                            shiprate = Convert.ToDecimal(dtmain.Rows[0]["Offer"].ToString());
                            if (dtmain.Rows[0]["FixedShipRate"].ToString() != null && shiprate > 0)
                                NewTotalAmount = newprice + shiprate;
                            else
                                NewTotalAmount = newprice;

                            //vaishnavi Changes
                            totalamount = Math.Round(NewTotalAmount);

                            string[] param = { Address };
                            DataTable dtAddress = dbCon.GetDataTableWithParams("select [CustomerId],[FirstName],[LastName],[CountryId],[StateId],[CityId],[Address],[MobileNo],[PinCode] from [CustomerAddress] where [IsDeleted]=0 and [IsActive]=1 and Id=@1", param);
                            if (dtAddress != null && dtAddress.Rows.Count > 0)
                            {
                                if (paidAmount == "")
                                {
                                    paidAmount = "0";
                                }
                                string insertquery = "insert into AlterNetOrder([OrderGuid],[CustomerId],[AddressId],[OrderStatusId],[OrderDiscount],[OrderMRP],[OrderTotal],[RefundedAmount],[CustomerIp],[ShippingMethod],[Deleted],[CreatedOnUtc],[TotalQty],[PaidAmount],[TotalGram],[TotalSaving],[Customer_Redeem_Amount],[TrnId],[IsPaymentDone],[OrderSourceId],[CustOfferCode],[RefferedOfferCode],[PaymentGatewayId],[BuyWith],[UpdatedOnUtc]) values (@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,GETDATE(),@12,@13,@14,@15,@16,@17,@18,@19,@20,@21,@22,@23,GETDATE());Select SCOPE_IDENTITY()";
                                string[] param1 = { Guid.NewGuid().ToString(), Customerid, Address, "10", discountamount, finalamount.ToString(), newfinalamount.ToString(), "0", dbCon.GetIP4Address().ToString(), ShipperId.ToString(), "0", quantity.ToString(), paidAmount, totalgram.ToString(), totalsaving.ToString(), Redemeamount, transid, "0", "3", coupanCode, "", "1" ,buywith};
                                int Orderrslt = dbCon.ExecuteScalarQueryWithParams(insertquery, param1);
                                if (Orderrslt > 0)
                                {
                                    string gst = "select [TaxValue] from [GstTaxCategory] where Id=" + dtmain.Rows[0]["GSTTaxId"].ToString();
                                    DataTable dtgstv = dbCon.GetDataTable(gst);
                                    string insertquery1 = "insert into [AlternetOrderItem](OrderId,[ProductId],[Quantity],[MrpPerUnit],[DiscountPerUnit],[ExtraDiscountPerUnit],[SGSTValuePerUnit],[SGSTAmountPerUnit],[CGSTValuePerUnit],[CGSTAmountPerUnit],[IGSTValuePerUnit],[IGSTAmountPerUnit],[TaxablePerUnit],[TotalAmount],[ProductName],[BuyWith],[BuyWithPerUnit],[CreatedOnUtc]) values (@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17,GETDATE());Select SCOPE_IDENTITY()";
                                    string[] param11 = { Orderrslt.ToString(), productid.ToString(), quantity.ToString(), price.ToString(), discountamount, offer.ToString(), "0", "0", "0", "0", "0", "0", dtgstv.Rows[0]["TaxValue"].ToString(), paidAmount, productname, buywith.ToString(), buywithprice.ToString() };
                                    int result11 = dbCon.ExecuteScalarQueryWithParams(insertquery1, param11);
                                    return result11;

                                }
                                else
                                {
                                    return 0;
                                }
                            }
                        }
                    }
                    else
                    {
                        return 0;

                    }

                }

 
            }
            catch
            {
                return 0;
            }
            return 0;
        }