public static void SaveGiftCardByAdmin(int giftCardId, GiftCard giftCardDetail, bool isActive, AspxCommonInfo aspxCommonObj)
 {
     try
     {
         AspxGiftCardProvider.SaveGiftCardByAdmin(giftCardId, giftCardDetail, isActive, aspxCommonObj);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public static bool SendEmailForGiftCard(int portalId, int storeId, string cultureName, GiftCard giftCardinfo)
        {
            bool isemailSent = true;
            StoreSettingConfig ssc = new StoreSettingConfig();
            // sendEmailFrom = ssc.GetStoreSettingsByKey(StoreSetting.SendEcommerceEmailsFrom, storeID, portalID, "en-US");
            string sendOrderNotice = ssc.GetStoreSettingsByKey(StoreSetting.SendOrderNotification, storeId, portalId,
                                                               cultureName);
            string logosrc = ssc.GetStoreSettingsByKey(StoreSetting.StoreLogoURL, storeId, portalId, cultureName);
            string inquiry = ssc.GetStoreSettingsByKey(StoreSetting.SendEcommerceEmailsFrom, storeId, portalId,
                                                       cultureName);
            string storeName = ssc.GetStoreSettingsByKey(StoreSetting.StoreName, storeId, portalId, cultureName);

            if (bool.Parse(sendOrderNotice))
            {
                //  MessageTemplateDataContext dbMessageTemplate = new MessageTemplateDataContext(SystemSetting.SageFrameConnectionString);
                // MessageTokenDataContext messageTokenDB = new MessageTokenDataContext(SystemSetting.SageFrameConnectionString);
                SageFrameConfig pagebase = new SageFrameConfig();
                //  var template = dbMessageTemplate.sp_MessageTemplateByMessageTemplateTypeID(SystemSetting.ORDER_PLACED, portalId).SingleOrDefault();
                string messageTemplate =
                    "<table width='650' cellspacing='5' cellpadding='0' border='0' bgcolor='#e0e0e0' align='center' style='font:12px Arial, Helvetica, sans-serif;'> <tbody> <tr> <td valign='top' align='center'> <table width='680' cellspacing='0' cellpadding='0' border='0'> <tbody> <tr> <td><img width='1' height='10' src='http://%ServerPath%/blank.gif' alt=' ' /></td> </tr> <tr> <td> <table width='680' cellspacing='0' cellpadding='0' border='0'> <tbody> <tr> <td width='300'><a href='http://%ServerPath%' target='_blank' style='outline:none; border:none;'><img width='143' height='62' src='%LogoSource%' alt='Logo' title='Logo' /></a></td> <td width='191' valign='middle' align='left'>&nbsp;</td> <td width='189' valign='middle' align='right'><b style='padding:0 20px 0 0; text-shadow:1px 1px 0 #fff;'> Date: %DateTime%</b></td> </tr> </tbody> </table> </td> </tr> <tr> <td><img width='1' height='10' src='http://%ServerPath%/blank.gif' alt=' ' /></td> </tr> <tr> <td bgcolor='#fff'> <div style='border:1px solid #c7c7c7; background:#fff; padding:20px'> <table width='650' cellspacing='0' cellpadding='0' border='0' bgcolor='#FFFFFF'> <tbody> <tr> <td> <p style='font-family:Arial, Helvetica, sans-serif; font-size:17px; line-height:16px; color:#278ee6; margin:0; padding:0 0 10px 0; font-weight:bold; text-align:left;'> Dear %RecipientName% </p> <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>You've got gift card from %SenderName% and it is now ready to be used for purchases at our store <a href='%ServerPath%' >%ServerPath%<a></p> </td> </tr> <tr> <td> <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>Gift Card Details</p> </td> </tr> <tr> <td> <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>Gift Card Code : %GiftCardCode%</p>  <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>Gift Card PinCode :****%PinCode%****</p> <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>Balance : %Balance%</p> <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>Expiry Date : %ExpiryDate%</p> <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>Message from Sender : %Message%</p> </td> </tr> <tr> <td> <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>Have a great shopping!</p> </td> </tr> </tbody> </table> <p style='margin:0; padding:10px 0 0 0; font:bold 11px Arial, Helvetica, sans-serif; color:#666;'>Thank You<br /> <span style='font-weight:normal; font-size:12px; font-family:Arial, Helvetica, sans-serif;'>AspxCommerce Team </span></p> </div> </td> </tr> <tr> <td><img width='1' height='20' src='http://%ServerPath%/blank.gif' alt=' ' /></td> </tr> <tr> <td valign='top' align='center'> <p style='font-size:11px; color:#4d4d4d'>&copy; %DateYear% AspxCommerce. All Rights Reserved.</p> </td> </tr> <tr> <td valign='top' align='center'><img width='1' height='10' src='http://%ServerPath%/blank.gif' alt=' ' /></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> ";
                // if (template != null)
                // {
                string[] tokens = GetAllToken(messageTemplate);
                foreach (string token in tokens)
                {
                    switch (token)
                    {
                        case "%DateYear%":
                            messageTemplate = messageTemplate.Replace(token, DateTime.Now.Year.ToString());
                            break;
                        case "%Balance%":
                            messageTemplate = messageTemplate.Replace(token, giftCardinfo.Balance.ToString());
                            break;
                        case "%PinCode%":
                            messageTemplate = messageTemplate.Replace(token, giftCardinfo.GiftCardPinCode.ToString());

                            break;
                        case "%ExpiryDate%":
                            messageTemplate = messageTemplate.Replace(token, giftCardinfo.ExpireDate.ToString());
                            break;
                        case "%RecipientName%":
                            messageTemplate = messageTemplate.Replace(token, giftCardinfo.RecipientName);
                            break;
                        case "%SenderName%":

                            messageTemplate = messageTemplate.Replace(token, giftCardinfo.SenderName);
                            break;
                        case "%GiftCardCode%":

                            messageTemplate = messageTemplate.Replace(token, giftCardinfo.GiftCardCode);
                            break;
                        case "%Message%":

                            messageTemplate = messageTemplate.Replace(token, giftCardinfo.Messege);
                            break;
                        case "%LogoSource%":
                            // string src = " http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/Templates/" + templateName + "/images/aspxcommerce.png";
                            string src = " http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/" +
                                         logosrc;
                            messageTemplate = messageTemplate.Replace(token, src);
                            break;
                        case "%DateTime%":
                            messageTemplate = messageTemplate.Replace(token, DateTime.Now.ToString("dd MMMM yyyy "));

                            break;
                        case "%InquiryEmail%":
                            string x =
                                "<a  target=\"_blank\" style=\"text-decoration: none;color: #226ab7;font-style: italic;\" href=\"mailto:" +
                                inquiry + "\" >" + inquiry + "</a>";
                            messageTemplate = messageTemplate.Replace(token, x);
                            break;
                        case "%StoreName%":
                            messageTemplate = messageTemplate.Replace(token, storeName);
                            break;
                        case "%ServerPath%":
                            string path = " http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] +
                                          "/";
                            messageTemplate = messageTemplate.Replace(token, path);
                            break;
                    }
                }
                // return messageTemplate;
                string emailSuperAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SuperUserEmail);
                string emailSiteAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SiteAdminEmailAddress);
                try
                {
                    MailHelper.SendMailNoAttachment(giftCardinfo.SenderEmail, giftCardinfo.RecipientEmail,
                                                    "You've got a Gift card", messageTemplate, emailSiteAdmin,
                                                    emailSuperAdmin);
                    isemailSent = true;
                }
                catch (Exception)
                {
                    isemailSent = false;
                }
            }
            return isemailSent;
        }
 public static int AddItemstoCartFromDetail(AddItemToCartInfo AddItemToCartObj, AspxCommonInfo aspxCommonObj, GiftCard giftCardDetail, CartKit kitInfo)
 {
     try
     {
         int retValue = AspxCommonProvider.AddItemstoCartFromDetail(AddItemToCartObj, aspxCommonObj, giftCardDetail, kitInfo);
         return retValue;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public static void SaveGiftCardByAdmin(int giftCardId, GiftCard giftCardDetail, bool isActive, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                List<KeyValuePair<string, object>> parameter = CommonParmBuilder.GetParamSPUC(aspxCommonObj);
                parameter.Add(new KeyValuePair<string, object>("@GiftCardId", giftCardId));
                parameter.Add(new KeyValuePair<string, object>("@GiftCardGraphicsId", giftCardDetail.GraphicThemeId));
                parameter.Add(new KeyValuePair<string, object>("@IsRecipientNotified",
                                                               giftCardDetail.IsRecipientNotified));
                //add column in table expiry date /add default 1 year after/ paid 
                parameter.Add(new KeyValuePair<string, object>("@ExpireDate", giftCardDetail.ExpireDate));
                parameter.Add(new KeyValuePair<string, object>("@Amount", giftCardDetail.Price));
                parameter.Add(new KeyValuePair<string, object>("@IsActive", isActive));

                parameter.Add(new KeyValuePair<string, object>("@RecipientEmail", giftCardDetail.RecipientEmail));
                parameter.Add(new KeyValuePair<string, object>("@RecipientName", giftCardDetail.RecipientName));
                parameter.Add(new KeyValuePair<string, object>("@SenderEmail", giftCardDetail.SenderEmail));
                parameter.Add(new KeyValuePair<string, object>("@SenderName", giftCardDetail.SenderName));
                parameter.Add(new KeyValuePair<string, object>("@Messege", giftCardDetail.Messege));
                if (giftCardId > 0)
                {
                    parameter.Add(new KeyValuePair<string, object>("@GiftCardCode", giftCardDetail.GiftCardCode));
                }
                else
                {
                    parameter.Add(new KeyValuePair<string, object>("@GiftCardCode", GetGiftCardKey()));
                }

                parameter.Add(new KeyValuePair<string, object>("@GiftCardTypeId", giftCardDetail.GiftCardTypeId));
                SQLHandler sqlH = new SQLHandler();
                int i = sqlH.ExecuteAsScalar<int>("usp_Aspx_SaveGiftCardByAdmin", parameter);
                var typeId = GetGiftCardType(aspxCommonObj.StoreID, aspxCommonObj.PortalID, i);
                if (giftCardId == 0)
                {
                    IssueGiftCard(i,null ,aspxCommonObj);
                    if (typeId == 1) //both or virtual
                        NotifyUser(i, aspxCommonObj);
                }   else
                {
                    if ((bool) (!giftCardDetail.IsRecipientNotified))
                    {
                        NotifyUser(i, aspxCommonObj);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static int AddItemstoCartFromDetail(AddItemToCartInfo AddItemToCartObj, AspxCommonInfo aspxCommonObj, GiftCard giftCardDetail, CartKit kitInfo)
        {
            try
            {

                StoreSettingConfig ssc = new StoreSettingConfig();
                if (AspxCartController.CheckItemCart(AddItemToCartObj.ItemID, aspxCommonObj.StoreID, aspxCommonObj.PortalID, AddItemToCartObj.CostVariantIDs))
                {
                    int cartItemId = 0;
                    if (AddItemToCartObj.IsKitItem)
                    {
                        //if kit type 
                        //logic 
                        // serialize
                        //   kitInfo.Data into string and save it db and also description
                        //++price and weight will be from kit info it contains total configured price and weight
                        JavaScriptSerializer json_serializer = new JavaScriptSerializer();
                        string kitconfigureddata = json_serializer.Serialize(kitInfo.Data);

                        List<KeyValuePair<string, object>> parameter = CommonParmBuilder.GetParamSPUS(aspxCommonObj);
                        parameter.Add(new KeyValuePair<string, object>("@ItemID", AddItemToCartObj.ItemID));
                        parameter.Add(new KeyValuePair<string, object>("@Price", kitInfo.Price));
                        parameter.Add(new KeyValuePair<string, object>("@Weight", kitInfo.Weight));
                        parameter.Add(new KeyValuePair<string, object>("@Quantity", AddItemToCartObj.Quantity));
                        parameter.Add(new KeyValuePair<string, object>("@CostVariantsValueIDs", AddItemToCartObj.CostVariantIDs));
                        parameter.Add(new KeyValuePair<string, object>("@KitDescription", kitInfo.Description));
                        parameter.Add(new KeyValuePair<string, object>("@KitData", kitconfigureddata));
                        SQLHandler sqlH = new SQLHandler();
                        cartItemId = sqlH.ExecuteAsScalar<int>("dbo.usp_Aspx_AddToCart", parameter);
                    }
                    else
                    {
                        List<KeyValuePair<string, object>> parameter = CommonParmBuilder.GetParamSPUS(aspxCommonObj);
                        parameter.Add(new KeyValuePair<string, object>("@ItemID", AddItemToCartObj.ItemID));
                        parameter.Add(new KeyValuePair<string, object>("@Price", AddItemToCartObj.Price));
                        parameter.Add(new KeyValuePair<string, object>("@Weight", AddItemToCartObj.Weight));
                        parameter.Add(new KeyValuePair<string, object>("@Quantity", AddItemToCartObj.Quantity));
                        parameter.Add(new KeyValuePair<string, object>("@CostVariantsValueIDs", AddItemToCartObj.CostVariantIDs));
                        parameter.Add(new KeyValuePair<string, object>("@KitDescription", null));
                        parameter.Add(new KeyValuePair<string, object>("@KitData", null));
                        SQLHandler sqlH = new SQLHandler();
                        cartItemId = sqlH.ExecuteAsScalar<int>("dbo.usp_Aspx_AddToCart", parameter);
                    }

                    if (AddItemToCartObj.IsGiftCard == true && giftCardDetail != null)
                    {
                        List<KeyValuePair<string, object>> param = new List<KeyValuePair<string, object>>();
                        param.Add(new KeyValuePair<string, object>("@CartItemId", cartItemId));
                        param.Add(new KeyValuePair<string, object>("@ItemId", AddItemToCartObj.ItemID));
                        param.Add(new KeyValuePair<string, object>("@GiftCardTypeId", giftCardDetail.GiftCardTypeId));
                        param.Add(new KeyValuePair<string, object>("@GiftCardGraphicsId", giftCardDetail.GraphicThemeId));
                        param.Add(new KeyValuePair<string, object>("@Amount", giftCardDetail.Price));
                        param.Add(new KeyValuePair<string, object>("@GiftCardCode", giftCardDetail.GiftCardCode));
                        param.Add(new KeyValuePair<string, object>("@RecipientName", giftCardDetail.RecipientName));
                        param.Add(new KeyValuePair<string, object>("@RecipientEmail", giftCardDetail.RecipientEmail));
                        param.Add(new KeyValuePair<string, object>("@SenderName", giftCardDetail.SenderName));
                        param.Add(new KeyValuePair<string, object>("@SenderEmail", giftCardDetail.SenderEmail));
                        param.Add(new KeyValuePair<string, object>("@Messege", giftCardDetail.Messege));
                        param.Add(new KeyValuePair<string, object>("@StoreId", aspxCommonObj.StoreID));
                        param.Add(new KeyValuePair<string, object>("@PortalId", aspxCommonObj.PortalID));
                        param.Add(new KeyValuePair<string, object>("@CultureName", aspxCommonObj.CultureName));
                        param.Add(new KeyValuePair<string, object>("@UserName", aspxCommonObj.UserName));
                        SQLHandler sqlH = new SQLHandler();
                        sqlH.ExecuteNonQuery("usp_Aspx_AddGiftCard", param);
                    }
                    return 1;
                }
                else
                {
                    if (bool.Parse(ssc.GetStoreSettingsByKey(StoreSetting.AllowOutStockPurchase, aspxCommonObj.StoreID, aspxCommonObj.PortalID, aspxCommonObj.CultureName)))
                    {
                        int cartItemId = 0;
                        if (AddItemToCartObj.IsKitItem)
                        {
                            List<KeyValuePair<string, object>> parameter = CommonParmBuilder.GetParamSPUS(aspxCommonObj);
                            parameter.Add(new KeyValuePair<string, object>("@ItemID", AddItemToCartObj.ItemID));
                            parameter.Add(new KeyValuePair<string, object>("@Price", AddItemToCartObj.Price));
                            parameter.Add(new KeyValuePair<string, object>("@Weight", AddItemToCartObj.Weight));
                            parameter.Add(new KeyValuePair<string, object>("@Quantity", AddItemToCartObj.Quantity));
                            parameter.Add(new KeyValuePair<string, object>("@CostVariantsValueIDs", AddItemToCartObj.CostVariantIDs));
                            parameter.Add(new KeyValuePair<string, object>("@KitDescription", null));
                            parameter.Add(new KeyValuePair<string, object>("@KitData", null));
                            SQLHandler sqlH = new SQLHandler();
                            cartItemId = sqlH.ExecuteAsScalar<int>("dbo.usp_Aspx_AddToCart", parameter);
                        }
                        else
                        {
                            List<KeyValuePair<string, object>> parameter = CommonParmBuilder.GetParamSPUS(aspxCommonObj);
                            parameter.Add(new KeyValuePair<string, object>("@ItemID", AddItemToCartObj.ItemID));
                            parameter.Add(new KeyValuePair<string, object>("@Price", AddItemToCartObj.Price));
                            parameter.Add(new KeyValuePair<string, object>("@Weight", AddItemToCartObj.Weight));
                            parameter.Add(new KeyValuePair<string, object>("@Quantity", AddItemToCartObj.Quantity));
                            parameter.Add(new KeyValuePair<string, object>("@CostVariantsValueIDs", AddItemToCartObj.CostVariantIDs));
                            parameter.Add(new KeyValuePair<string, object>("@KitDescription", null));
                            parameter.Add(new KeyValuePair<string, object>("@KitData", null));
                            SQLHandler sqlH = new SQLHandler();
                            cartItemId = sqlH.ExecuteAsScalar<int>("dbo.usp_Aspx_AddToCart", parameter);
                        }


                        if (AddItemToCartObj.IsGiftCard == true && giftCardDetail != null)
                        {
                            List<KeyValuePair<string, object>> param = new List<KeyValuePair<string, object>>();
                            param.Add(new KeyValuePair<string, object>("@CartItemId", cartItemId));
                            param.Add(new KeyValuePair<string, object>("@ItemId", AddItemToCartObj.ItemID));
                            param.Add(new KeyValuePair<string, object>("@GiftCardTypeId", giftCardDetail.GiftCardTypeId));
                            param.Add(new KeyValuePair<string, object>("@GiftCardGraphicsId", giftCardDetail.GraphicThemeId));
                            param.Add(new KeyValuePair<string, object>("@Amount", giftCardDetail.Price));
                            param.Add(new KeyValuePair<string, object>("@GiftCardCode", giftCardDetail.GiftCardCode));
                            param.Add(new KeyValuePair<string, object>("@RecipientName", giftCardDetail.RecipientName));
                            param.Add(new KeyValuePair<string, object>("@RecipientEmail", giftCardDetail.RecipientEmail));
                            param.Add(new KeyValuePair<string, object>("@SenderName", giftCardDetail.SenderName));
                            param.Add(new KeyValuePair<string, object>("@SenderEmail", giftCardDetail.SenderEmail));
                            param.Add(new KeyValuePair<string, object>("@Messege", giftCardDetail.Messege));
                            param.Add(new KeyValuePair<string, object>("@StoreId", aspxCommonObj.StoreID));
                            param.Add(new KeyValuePair<string, object>("@PortalId", aspxCommonObj.PortalID));
                            param.Add(new KeyValuePair<string, object>("@CultureName", aspxCommonObj.CultureName));
                            param.Add(new KeyValuePair<string, object>("@UserName", aspxCommonObj.UserName));
                            SQLHandler sqlH = new SQLHandler();
                            sqlH.ExecuteNonQuery("usp_Aspx_AddGiftCard", param);
                        }
                        return 1;
                    }
                    else
                    {
                        return 2;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public static int AddItemstoCartFromDetail(AddItemToCartInfo AddItemToCartObj, AspxCommonInfo aspxCommonObj, GiftCard giftCardDetail, CartKit kitInfo)
 {
     try
     {
         int retValue = AspxCommonProvider.AddItemstoCartFromDetail(AddItemToCartObj, aspxCommonObj, giftCardDetail, kitInfo);
         return(retValue);
     }
     catch (Exception e)
     {
         throw e;
     }
 }