public JsonResult _RegisterAndSubscribe(FormCollection fc)
        {
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = String.Empty,
                info = "Registration",
                TransactionType = "Registration"
            };

            if (!Request.IsAjaxRequest())
            {
                ReturnCode.StatusMessage = "Invalid request";
                return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
            }

            bool isSourceAir = false;
            string url = Url.Action("Register", "User").ToString();
            var field_names = new string[] { "uid", "provider", "full_name", "pid", "cmd", "a1", "p1", "t1", "a3", "t3", "p3", "src", "item_name", "amount", "currency", "custom", "ip" };
            try
            {
                if (TempData["qs"] != null)
                {
                    var qs = (NameValueCollection)TempData["qs"];
                    ViewBag.qs = qs;
                    TempData["qs"] = qs;
                }

                DateTime registDt = DateTime.Now;
                Dictionary<string, string> tmpCollection = fc.AllKeys.ToDictionary(k => k, v => fc[v]);
                bool isMissingRequiredFields = false;

                foreach (var x in tmpCollection)
                {
                    if (!field_names.Contains(x.Key))
                        if (String.IsNullOrEmpty(x.Value))
                        {
                            isMissingRequiredFields = true;
                            break;
                        }
                }

                if (!isMissingRequiredFields) // process form
                {
                    var ip = Request.GetUserHostAddressFromCloudflare();
                    if (!String.IsNullOrEmpty(tmpCollection["ip"]))
                        ip = tmpCollection["ip"];

                    var location = MyUtility.GetLocationBasedOnIpAddress(ip);
                    string FirstName = tmpCollection["first_name"];
                    string LastName = tmpCollection["last_name"];

                    string EMail = tmpCollection["p_login_email"];
                    string ConfirmEmail = tmpCollection["p_login_email_c"];
                    string Password = tmpCollection["login_pass"];

                    //autodetect country, city, state
                    string CountryCode = location.countryCode;
                    string City = location.city;
                    string State = location.region;

                    string provider = String.IsNullOrEmpty(tmpCollection["provider"]) ? String.Empty : tmpCollection["provider"];
                    string uid = String.IsNullOrEmpty(tmpCollection["uid"]) ? String.Empty : tmpCollection["uid"];
                    System.Guid userId = System.Guid.NewGuid();
                    string browser = Request.UserAgent;

                    if (FirstName.Length > 32)
                        ReturnCode.StatusMessage = "First Name cannot exceed 32 characters.";
                    if (LastName.Length > 32)
                        ReturnCode.StatusMessage = "Last Name cannot exceed 32 characters.";
                    if (EMail.Length > 64)
                        ReturnCode.StatusMessage = "Email address cannot exceed 64 characters.";
                    if (State.Length > 30)
                        ReturnCode.StatusMessage = "State cannot exceed 30 characters.";
                    if (City.Length > 50)
                        ReturnCode.StatusMessage = "City cannot exceed 50 characters.";
                    if (String.Compare(EMail, ConfirmEmail, true) != 0)
                        ReturnCode.StatusMessage = "Email addresses do not match";

                    RegexUtilities util = new RegexUtilities();
                    //if (!MyUtility.isEmail(EMail))
                    if (!util.IsValidEmail(EMail))
                        ReturnCode.StatusMessage = "Email address is invalid.";

                    var context = new IPTV2Entities();
                    User user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EMail, true) == 0);
                    if (user != null)
                        ReturnCode.StatusMessage = "Email address is already taken.";

                    if (GlobalConfig.ExcludedCountriesFromRegistrationDropDown.Split(',').Contains(CountryCode)) // check if country is part of the exclusion list first
                        ReturnCode.StatusMessage = "Country does not exist.";
                    else if (context.Countries.Count(c => String.Compare(c.Code, CountryCode, true) == 0) <= 0) // then check if country is part of the list                    
                        ReturnCode.StatusMessage = "Country does not exist.";
                    if (context.States.Count(s => String.Compare(s.CountryCode, CountryCode, true) == 0) > 0)
                        if (context.States.Count(s => String.Compare(s.CountryCode, CountryCode, true) == 0 && (String.Compare(s.StateCode, State, true) == 0 || String.Compare(s.Name, State, true) == 0)) <= 0)
                            ReturnCode.StatusMessage = "State is invalid for this country.";

                    if (!String.IsNullOrEmpty(ReturnCode.StatusMessage))
                        return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);

                    user = new User()
                    {
                        UserId = userId,
                        FirstName = FirstName,
                        LastName = LastName,
                        City = City,
                        State = State,
                        CountryCode = CountryCode,
                        EMail = EMail,
                        Password = MyUtility.GetSHA1(Password),
                        GigyaUID = userId.ToString(),
                        RegistrationDate = registDt,
                        LastUpdated = registDt,
                        RegistrationIp = ip,
                        StatusId = GlobalConfig.Visible,
                        ActivationKey = Guid.NewGuid(),
                        DateVerified = registDt
                    };

                    try
                    {
                        if (Request.Cookies.AllKeys.Contains("tuid"))
                            user.RegistrationCookie = Request.Cookies["tuid"].Value;
                        else if (Request.Cookies.AllKeys.Contains("regcook"))
                            user.RegistrationCookie = Request.Cookies["regcook"].Value;
                    }
                    catch (Exception) { }

                    ////check for cookie 
                    try
                    {
                        var dt = DateTime.Parse(Request.Cookies["rcDate"].Value);
                        if (registDt.Subtract(dt).Days < 45)
                        {
                            ReturnCode.StatusMessage = "We have detected that you have already registered using this machine.";
                            return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
                        }
                    }
                    catch (Exception) { }

                    string CurrencyCode = GlobalConfig.DefaultCurrency;
                    var country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0);
                    if (country != null)
                        CurrencyCode = country.CurrencyCode;
                    var wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0);
                    if (wallet == null) // Wallet does not exist. Create new wallet for User.
                    {
                        wallet = ContextHelper.CreateWallet(0, CurrencyCode, registDt);
                        user.UserWallets.Add(wallet);
                    }

                    var transaction = new RegistrationTransaction()
                    {
                        RegisteredState = user.State,
                        RegisteredCity = user.City,
                        RegisteredCountryCode = user.CountryCode,
                        Amount = 0,
                        Currency = CurrencyCode,
                        Reference = isSourceAir ? "New Registration (air)" : "New Registration",
                        Date = registDt,
                        OfferingId = GlobalConfig.offeringId,
                        UserId = user.UserId,
                        StatusId = GlobalConfig.Visible
                    };
                    user.Transactions.Add(transaction);

                    context.Users.Add(user);
                    if (context.SaveChanges() > 0)
                    {
                        string verification_email = String.Format("{0}/User/Verify?key={1}", GlobalConfig.baseUrl, user.ActivationKey.ToString());
                        if (isSourceAir)
                        {
                            try
                            {
                                verification_email = String.Format("{0}&source=air", verification_email);
                                var template = MyUtility.GetUrlContent(GlobalConfig.ProjectAirEmailVerificationBodyTemplateUrl);
                                var htmlBody = String.Format(template, FirstName, EMail, verification_email);
                                if (!Request.IsLocal)
                                    try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", htmlBody, MailType.HtmlOnly, String.Empty); }
                                    catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); }
                            }
                            catch (Exception)
                            {
                                string emailBody = String.Format(GlobalConfig.EmailVerificationBodyTextOnly, FirstName, EMail, verification_email);
                                if (!Request.IsLocal)
                                    try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody, MailType.TextOnly, emailBody); }
                                    catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); }
                            }
                        }
                        else
                        {
                            string emailBody = String.Format(GlobalConfig.EmailVerificationBodyTextOnly, FirstName, EMail, verification_email);
                            if (!Request.IsLocal)
                                try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody, MailType.TextOnly, emailBody); }
                                catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); }
                        }
                        GSResponse res = null;
                        if (!String.IsNullOrEmpty(uid) && !String.IsNullOrEmpty(provider))
                        {
                            Dictionary<string, object> collection = new Dictionary<string, object>();
                            collection.Add("siteUID", user.UserId);
                            collection.Add("uid", Uri.UnescapeDataString(uid));
                            collection.Add("cid", String.Format("{0} - New User", provider));
                            res = GigyaHelpers.createAndSendRequest("socialize.notifyRegistration", GigyaHelpers.buildParameter(collection));
                            if (res.GetErrorCode() == 0) //Successful link
                            {
                                if (user != null)
                                {
                                    var UserId = user.UserId.ToString();
                                    user.StatusId = GlobalConfig.Visible; //activate account
                                    user.DateVerified = DateTime.Now;
                                    SetAutheticationCookie(UserId);
                                    SetSession(UserId);
                                    if (!ContextHelper.SaveSessionInDatabase(context, user))
                                        context.SaveChanges();
                                }
                            }
                        }
                        else
                        {
                            var info = new GigyaUserInfo()
                            {
                                firstName = FirstName,
                                lastName = LastName,
                                email = EMail
                            };
                            var registrationInfo = new GigyaNotifyLoginInfo()
                            {
                                siteUID = user.UserId.ToString(),
                                cid = "TFCTV - Registration",
                                sessionExpiration = 0,
                                newUser = true,
                                userInfo = Newtonsoft.Json.JsonConvert.SerializeObject(info)
                            };
                            GSObject obj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(registrationInfo));
                            res = GigyaHelpers.createAndSendRequest("socialize.notifyLogin", obj);

                        }

                        if (user != null)
                        {
                            if (user.StatusId == GlobalConfig.Visible)
                            {
                                int freeTrialProductId = 0;
                                if (GlobalConfig.IsFreeTrialEnabled)
                                {
                                    freeTrialProductId = MyUtility.GetCorrespondingFreeTrialProductId();
                                    if (GlobalConfig.TfcTvFree2StartDate < registDt && GlobalConfig.TfcTvFree2EndDate > registDt)
                                    {
                                        string UserCountryCode = user.CountryCode;
                                        if (!GlobalConfig.isUAT)
                                            try { UserCountryCode = MyUtility.GetCountryCodeViaIpAddressWithoutProxy(); }
                                            catch (Exception) { }

                                        var countryList = GlobalConfig.TfcTvFree2CountryWhiteList.Split(',');
                                        if (countryList.Contains(UserCountryCode) && String.Compare(user.CountryCode, UserCountryCode, true) == 0)
                                            freeTrialProductId = GlobalConfig.TfcTvFree2ProductId;
                                    }
                                    PaymentHelper.PayViaWallet(context, userId, freeTrialProductId, SubscriptionProductType.Package, userId, null);
                                }

                                //authenticate user
                                SetAutheticationCookie(user.UserId.ToString());

                                SendToGigya(user);
                                SetSession(user.UserId.ToString());
                                ContextHelper.SaveSessionInDatabase(context, user);

                                //add uid cookie
                                HttpCookie uidCookie = new HttpCookie("uid");
                                uidCookie.Value = user.UserId.ToString();
                                uidCookie.Expires = DateTime.Now.AddDays(30);
                                Response.Cookies.Add(uidCookie);
                            }
                        }

                        GigyaHelpers.setCookie(res, this.ControllerContext);
                        GigyaUserData2 userData = new GigyaUserData2()
                        {
                            city = user.City,
                            country = user.CountryCode,
                            email = user.EMail,
                            firstName = user.FirstName,
                            lastName = user.LastName,
                            state = user.State
                        };

                        //GigyaUserDataInfo userDataInfo = new GigyaUserDataInfo()
                        //{
                        //    UID = user.UserId.ToString(),
                        //    data = Newtonsoft.Json.JsonConvert.SerializeObject(userData, Formatting.None)
                        //};

                        TFCTV.Helpers.UserData privacyData = new UserData() { IsExternalSharingEnabled = "true,false", IsInternalSharingEnabled = "true,false", IsProfilePrivate = "false" };

                        GigyaUserDataInfo2 userDataInfo = new GigyaUserDataInfo2()
                        {
                            UID = user.UserId.ToString(),
                            profile = Newtonsoft.Json.JsonConvert.SerializeObject(userData, Formatting.None),
                            data = Newtonsoft.Json.JsonConvert.SerializeObject(privacyData, Formatting.None)
                        };

                        GSObject userDataInfoObj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo));
                        //res = GigyaHelpers.createAndSendRequest("gcs.setUserData", userDataInfoObj);
                        res = GigyaHelpers.createAndSendRequest("ids.setAccountInfo", userDataInfoObj);
                        var returnCode = res.GetErrorCode();

                        //Publish to Activity Feed
                        List<ActionLink> actionlinks = new List<ActionLink>();
                        actionlinks.Add(new ActionLink() { text = SNSTemplates.register_actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_actionlink_href) });
                        //mediaItem
                        List<MediaItem> mediaItems = new List<MediaItem>();
                        mediaItems.Add(new MediaItem() { type = SNSTemplates.register_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.register_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_mediaitem_href) });
                        UserAction action = new UserAction()
                        {
                            actorUID = userId.ToString(),
                            userMessage = SNSTemplates.register_usermessage,
                            title = SNSTemplates.register_title,
                            subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_subtitle),
                            linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_linkback),
                            description = String.Format(SNSTemplates.register_description, FirstName),
                            actionLinks = actionlinks,
                            mediaItems = mediaItems
                        };

                        GigyaMethods.PublishUserAction(action, userId, "external");
                        action.userMessage = String.Empty;
                        action.title = String.Empty;
                        action.mediaItems = null;
                        GigyaMethods.PublishUserAction(action, userId, "internal");

                        TempData["qs"] = null; // empty the TempData upon successful registration

                        ReturnCode.StatusCode = (int)ErrorCodes.Success;
                        ReturnCode.info7 = user.EMail;
                        if (user.StatusId == GlobalConfig.Visible)
                        {
                            ReturnCode.StatusHeader = "Your 7-Day Free Trial Starts Now!";
                            ReturnCode.StatusMessage = "Congratulations! You are now registered to TFC.tv.";
                            ReturnCode.StatusMessage2 = "Pwede ka nang manood ng mga piling Kapamilya shows at movies!";
                            ReturnCode.info3 = user.UserId.ToString();

                            //Change to social registration
                            ReturnCode.info = "SocialRegistration";
                            ReturnCode.TransactionType = "SocialRegistration";
                        }
                        else
                        {
                            ReturnCode.StatusHeader = "Email verification sent!";
                            ReturnCode.StatusMessage = "Congratulations! You are one step away from completing your registration.";
                            ReturnCode.StatusMessage2 = "An email has been sent to you.<br> Verify your email address to complete your registration.";
                        }
                        TempData["ErrorMessage"] = ReturnCode;
                        //if(xoom)
                        if (Request.Cookies.AllKeys.Contains("xoom"))
                        {
                            var userPromo = new UserPromo();
                            userPromo.UserId = user.UserId;
                            userPromo.PromoId = GlobalConfig.Xoom2PromoId;
                            userPromo.AuditTrail.CreatedOn = registDt;
                            context.UserPromos.Add(userPromo);
                            context.SaveChanges();
                        }

                        return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); // successful registration
                    }
                }
                else
                    ReturnCode.StatusMessage = "Please fill in all required fields.";

                url = String.Format("{0}?{1}", Request.UrlReferrer.AbsolutePath, MyUtility.DictionaryToQueryString(tmpCollection));
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
        public JsonResult _EnterPromo(FormCollection fc)
        {
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError)
            };
            DateTime registDt = DateTime.Now;
            int promoID = GlobalConfig.TFCtvFirstYearAnniversaryPromoId;
            var userID = new System.Guid(User.Identity.Name);

            try
            {
                var context = new IPTV2Entities();
                Promo promo = context.Promos.FirstOrDefault(p => p.PromoId == promoID && p.StatusId == GlobalConfig.Visible && p.EndDate > registDt && p.StartDate < registDt);
                if (promo != null)
                {
                    UserPromo userPromo = context.UserPromos.FirstOrDefault(u => u.UserId == userID && u.PromoId == promoID);
                    if (userPromo == null)

                        userPromo = new UserPromo()
                        {
                            PromoId = promoID,
                            UserId = userID,
                            AuditTrail = new AuditTrail() { CreatedOn = DateTime.Now }
                        };
                    context.UserPromos.Add(userPromo);
                    if (context.SaveChanges() > 0)
                    {
                        ReturnCode.StatusCode = (int)ErrorCodes.Success;
                        ReturnCode.StatusMessage = "You have successfully joined the promo.";
                        //adds points for each presconnected SNS
                        var providers = GigyaMethods.GetUserInfoByKey(userID, "providers");
                        var providerList = providers.Split(',');
                        foreach (string p in providerList)
                        {
                            if (!(String.Compare(p, "site") == 0))
                            {
                                GigyaActionSingleAttribute actionAttribute = new GigyaActionSingleAttribute();
                                {
                                    actionAttribute.description = new List<string> { "You connected to " + p };
                                }
                                GigyaMethods.NotifyAction(userID, AnniversaryPromo.AnnivPromo_LinkingSNS.ToString(), actionAttribute);
                            }
                        }
                    }
                    else
                    {
                        ReturnCode.StatusCode = (int)ErrorCodes.UnknownError;
                        ReturnCode.StatusMessage = "You have already joined the promo.";
                    }
                }
            }
            catch (Exception e)
            {
                MyUtility.LogException(e);
            }
            return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
        public static bool logProjectBlackUserPromo(IPTV2Entities context, Guid userId, int pid)
        {
            var projectBlackProductIds = MyUtility.StringToIntList(GlobalConfig.ProjectBlackProductIds).ToList();
            var projectBlackPromoIds = MyUtility.StringToIntList(GlobalConfig.ProjectBlackPromoIds).ToList();

            bool success = false;
            if (projectBlackProductIds.Contains(pid))
            {
                try
                {
                    var userpromo = new UserPromo();
                    userpromo.PromoId = projectBlackPromoIds[projectBlackPromoIds.Count - 1];
                    userpromo.UserId = userId;
                    userpromo.AuditTrail.CreatedOn = DateTime.Now;
                    context.UserPromos.Add(userpromo);
                    if (context.SaveChanges() > 0)
                        success = true;
                }
                catch (Exception e)
                {
                    MyUtility.LogException(e);
                };
            }
            return success;
        }
        public JsonResult LogUserToPromo()
        {
            var ReturnCode = new TransactionReturnType()
                       {
                           StatusCode = (int)ErrorCodes.UnknownError,
                           StatusMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError)
                       };

            if (!Request.IsLocal)
                if (!Request.IsAjaxRequest())
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.IsInvalidRequest;
                    ReturnCode.StatusMessage = "Your request is invalid.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

            if (!User.Identity.IsAuthenticated)
            {
                ReturnCode.StatusCode = (int)ErrorCodes.IsInvalidRequest;
                ReturnCode.StatusMessage = "Your request is invalid.";
                return Json(ReturnCode, JsonRequestBehavior.AllowGet);
            }
            try
            {
                var UserId = new Guid(User.Identity.Name);
                var registDt = DateTime.Now;
                var context = new IPTV2Entities();
                var user = context.Users.FirstOrDefault(u => u.UserId == UserId);
                if (user != null)
                {
                    var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.ProjectAirPromoId && p.StartDate < registDt && p.EndDate > registDt && p.StatusId == GlobalConfig.Visible);
                    if (promo != null)
                    {
                        if (context.UserPromos.Count(p => p.PromoId == GlobalConfig.ProjectAirPromoId && p.UserId == user.UserId) <= 0)
                        {
                            var uObj = new UserPromo()
                            {
                                UserId = user.UserId,
                                PromoId = promo.PromoId,
                                AuditTrail = new AuditTrail() { CreatedOn = DateTime.Now }
                            };
                            context.UserPromos.Add(uObj);
                            if (context.SaveChanges() > 0)
                            {
                                ReturnCode.StatusCode = (int)ErrorCodes.Success;
                                ReturnCode.StatusMessage = "Success";
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MyUtility.LogException(e);
                ReturnCode.StatusMessage = e.Message;
            }
            return Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
        //
        // GET: /Offer/

        public ActionResult Index(string id)
        {
            try
            {
                if (!String.IsNullOrEmpty(id))
                {
                    if (String.Compare(id, "survey") == 0)
                    {
                        if (!User.Identity.IsAuthenticated)
                        {
                            TempData["LoginErrorMessage"] = "Please sign in to claim your FREE TFC.tv 1-month subscription.";
                            TempData["RedirectUrl"] = Request.Url.PathAndQuery;
                            return RedirectToAction("Index", "Home");
                        }
                        survey();
                        return RedirectToAction("Index", "Home");
                    }
                    else
                        if (String.Compare(id, "xoom") == 0)
                        {
                            var ReturnCode = new TransactionReturnType()
                            {
                                StatusCode = (int)ErrorCodes.UnknownError,
                                StatusMessage = String.Empty,
                                info = "Promo",
                                TransactionType = "Xoom Promo"
                            };
                            if (!User.Identity.IsAuthenticated)
                            {
                                //drop cookie
                                HttpCookie xoomCookie = new HttpCookie("xoom");
                                xoomCookie.Expires = DateTime.Now.AddDays(1);
                                Response.Cookies.Add(xoomCookie);

                                TempData["LoginErrorMessage"] = "Please register to avail of this promo.";
                                TempData["RedirectUrl"] = Request.Url.PathAndQuery;
                                return RedirectToAction("Register", "User");
                            }
                            else
                            {
                                DateTime registDt = DateTime.Now;
                                var context = new IPTV2Entities();
                                var user = context.Users.Find(new Guid(User.Identity.Name));
                                var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.Xoom2PromoId && p.StatusId == GlobalConfig.Visible && p.StartDate < registDt && p.EndDate > registDt);
                                if (promo != null)
                                {
                                    if (user.StatusId == GlobalConfig.Visible)
                                    {
                                        bool userPurchased = false;
                                        bool isTVE = false;
                                        if (user.IsTVEverywhere != null)
                                            isTVE = (bool)user.IsTVEverywhere;
                                        var entitlements = context.Entitlements.Where(e => e.EndDate > registDt && e.UserId == user.UserId);
                                        if (entitlements != null && entitlements.Count() > 0)
                                        {
                                            foreach (Entitlement e in entitlements)
                                            {
                                                if (e is PackageEntitlement)
                                                {
                                                    var packageEnt = (PackageEntitlement)e;
                                                    if (packageEnt.PackageId == GlobalConfig.PremiumPackageId)
                                                    {
                                                        var product = packageEnt.LatestEntitlementRequest.Product;
                                                        if (product.GetPrice(user.Country) > 0)
                                                            userPurchased = true;
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        if (!userPurchased && !isTVE)
                                        {
                                            var userPromo = context.UserPromos.FirstOrDefault(u => u.UserId == user.UserId && u.PromoId == GlobalConfig.Xoom2PromoId);
                                            if (userPromo == null)
                                            {
                                                userPromo = new UserPromo();
                                                userPromo.UserId = user.UserId;
                                                userPromo.PromoId = GlobalConfig.Xoom2PromoId;
                                                userPromo.AuditTrail.CreatedOn = registDt;
                                                context.UserPromos.Add(userPromo);
                                                context.SaveChanges();

                                            }
                                            return Redirect(String.Format("/Subscribe/Details{0}", Request.Url.Query));
                                        }
                                        else
                                        {
                                            ReturnCode.StatusHeader = "This promo is available only to XOOM Customers";
                                            ReturnCode.StatusMessage = "with no existing TFC.tv Premium subscriptions or TFC Everywhere account.";
                                        }
                                    }
                                    else
                                    {
                                        ReturnCode.StatusHeader = "You have not yet verified your email address";
                                        ReturnCode.StatusMessage = "Please verify your newly registered account via the email address you provided.";
                                    }
                                }
                                else
                                {
                                    ReturnCode.StatusMessage = "Promo is no longer active";
                                }
                                if (!String.IsNullOrEmpty(ReturnCode.StatusMessage))
                                {
                                    TempData["ErrorMessage"] = ReturnCode;
                                }
                                return Redirect(String.Format("/Home/Index/{0}", Request.Url.Query));
                            }
                        }
                        else
                        {
                            if (!User.Identity.IsAuthenticated)
                            {
                                TempData["LoginErrorMessage"] = "Please sign in to avail of this promo.";
                                TempData["RedirectUrl"] = Request.Url.PathAndQuery;
                                return RedirectToAction("Index", "Home");
                            }
                            return Redirect(String.Format("/Subscribe/Details/{0}{1}", id, Request.Url.Query));
                        }
                }
            }
            catch (Exception e)
            {
                MyUtility.LogException(e);
                var ReturnCode = new TransactionReturnType()
                {
                    StatusCode = (int)ErrorCodes.UnknownError,
                    StatusMessage = e.Message,
                    StatusHeader = "Oops! There seems to be a problem."
                };

                TempData["ErrorMessage"] = ReturnCode;
            }
            return RedirectToAction("Index", "Home");
        }