コード例 #1
0
        public ActionResult Details(string id, int? PackageOption, int? ProductOption)
        {
            var profiler = MiniProfiler.Current;
            #region if (!Request.Cookies.AllKeys.Contains("version"))
            if (!Request.Cookies.AllKeys.Contains("version"))
            {
                List<SubscriptionProductA> productList = null;
                try
                {
                    if (!String.IsNullOrEmpty(id))
                        if (String.Compare(id, "mayweather-vs-pacquiao-may-3", true) == 0)
                            id = GlobalConfig.PacMaySubscribeCategoryId.ToString();

                    var context = new IPTV2Entities();
                    string ip = Request.IsLocal ? "78.95.139.99" : Request.GetUserHostAddressFromCloudflare();
                    if (GlobalConfig.isUAT && !String.IsNullOrEmpty(Request.QueryString["ip"]))
                        ip = Request.QueryString["ip"].ToString();
                    var location = MyUtility.GetLocationBasedOnIpAddress(ip);
                    var CountryCode = location.countryCode;
                    //var CountryCode = MyUtility.GetCountryCodeViaIpAddressWithoutProxy();

                    User user = null;
                    Guid? UserId = null;
                    if (User.Identity.IsAuthenticated)
                    {
                        UserId = new Guid(User.Identity.Name);
                        user = context.Users.FirstOrDefault(u => u.UserId == UserId);
                        if (user != null)
                            CountryCode = user.CountryCode;
                    }

                    var country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0);

                    var premium = MyUtility.StringToIntList(GlobalConfig.PremiumProductIds);
                    var lite = MyUtility.StringToIntList(GlobalConfig.LiteProductIds);
                    var movie = MyUtility.StringToIntList(GlobalConfig.MovieProductIds);
                    var litepromo = MyUtility.StringToIntList(GlobalConfig.LitePromoProductIds);
                    var promo2014promo = MyUtility.StringToIntList(GlobalConfig.Promo2014ProductIds);
                    var q22015promo = MyUtility.StringToIntList(GlobalConfig.Q22015ProductId);

                    var productIds = premium;//productids
                    var offering = context.Offerings.Find(GlobalConfig.offeringId);
                    var service = offering.Services.FirstOrDefault(o => o.PackageId == GlobalConfig.serviceId);

                    bool IsAlaCarteProduct = true;
                    #region code for showing product based on id
                    if (!String.IsNullOrEmpty(id))
                    {
                        int pid;
                        if (int.TryParse(id, out pid)) // id is an integer, then it's a show, get ala carte only
                        {
                            var show = (Show)context.CategoryClasses.Find(pid);

                            if (User.Identity.IsAuthenticated)
                            {
                                var allowedEmails = GlobalConfig.EmailsAllowedToBypassIPBlock.Split(',');
                                var isEmailAllowed = allowedEmails.Contains(user.EMail.ToLower());
                                if (!isEmailAllowed)
                                {
                                    if (!ContextHelper.IsCategoryViewableInUserCountry(show, CountryCode))
                                        return RedirectToAction("Index", "Home");

                                    string CountryCodeBasedOnIpAddress = MyUtility.GetCountryCodeViaIpAddressWithoutProxy();
                                    if (!ContextHelper.IsCategoryViewableInUserCountry(show, CountryCodeBasedOnIpAddress))
                                        return RedirectToAction("Index", "Home");
                                }
                            }

                            try
                            {
                                var ShowParentCategories = ContextHelper.GetShowParentCategories(show.CategoryId);
                                if (!String.IsNullOrEmpty(ShowParentCategories))
                                {
                                    ViewBag.ShowParentCategories = ShowParentCategories;
                                    if (!MyUtility.IsWhiteListed(String.Empty))
                                    {
                                        var ids = MyUtility.StringToIntList(ShowParentCategories);
                                        var alaCarteIds = MyUtility.StringToIntList(GlobalConfig.UXAlaCarteParentCategoryIds);
                                        var DoCheckForGeoIPRestriction = ids.Intersect(alaCarteIds).Count() > 0;
                                        if (DoCheckForGeoIPRestriction)
                                        {
                                            var ipx = Request.IsLocal ? "221.121.187.253" : String.Empty;
                                            if (GlobalConfig.isUAT)
                                                ipx = Request["ip"];
                                            if (!MyUtility.CheckIfCategoryIsAllowed(show.CategoryId, context, ipx))
                                            {
                                                var ReturnCode = new TransactionReturnType()
                                                {
                                                    StatusHeader = "Content Advisory",
                                                    StatusMessage = "This content is currently not available in your area.",
                                                    StatusMessage2 = "You may select from among the hundreds of shows and movies that are available on the site."
                                                };
                                                TempData["ErrorMessage"] = ReturnCode;
                                                return RedirectToAction("Index", "Home");
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception) { }

                            productIds = show.GetPackageProductIds(offering, CountryCode, RightsType.Online);
                            var showProductIds = show.GetShowProductIds(offering, CountryCode, RightsType.Online);
                            if (showProductIds != null)
                                productIds = productIds.Union(showProductIds);

                            //Remove premium, lite & movie packages from list
                            productIds = productIds.Except(premium).Except(lite).Except(movie).Except(litepromo);
                            IsAlaCarteProduct = true;

                            if (pid == GlobalConfig.PacMaySubscribeCategoryId)
                            {
                                ViewBag.IsPacMay = true;
                                //add the additional product ids
                                var additional_pacmay_productids = MyUtility.StringToIntList(GlobalConfig.PacMaySubscribeProductIds);
                                productIds = productIds.Union(additional_pacmay_productids);
                                TempData["IsPacPurchase"] = true;
                            }
                        }
                        else // get packages only
                        {
                            if (String.Compare(id, "Lite", true) == 0)
                                productIds = lite;
                            else if (String.Compare(id, "Movie", true) == 0)
                                productIds = movie;
                            else if (String.Compare(id, "LitePromo", true) == 0)
                            {
                                var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.LiteChurnersPromoId);
                                if (promo != null)
                                {
                                    var registDt = DateTime.Now;
                                    if (promo.StatusId == GlobalConfig.Visible && promo.StartDate < registDt && promo.EndDate > registDt)
                                        productIds = litepromo; // discounted lite product Ids
                                }
                            }
                            else if (String.Compare(id, "Promo201410", true) == 0)
                            {
                                var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.Promo201410PromoId);
                                if (promo != null)
                                {
                                    var registDt = DateTime.Now;
                                    if (promo.StatusId == GlobalConfig.Visible && promo.StartDate < registDt && promo.EndDate > registDt)
                                    {
                                        ViewBag.IsPromo2014 = true;
                                        ViewBag.PreventAutoRenewalCheckboxFromUntick = true;
                                        productIds = promo2014promo; // discounted 3month premium
                                        //get amount of 3 month premium
                                        var premium1mo = context.Products.FirstOrDefault(p => p.ProductId == 1);
                                        if (premium1mo != null)
                                            ViewBag.Premium1MonthPrice = premium1mo.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);

                                        //check purchasetry
                                        try
                                        {
                                            var user_purchases = context.PurchaseItems.Where(p => promo2014promo.Contains(p.ProductId) && p.RecipientUserId == user.UserId);
                                            if (user_purchases != null)
                                            {
                                                var purchaseIds = user_purchases.Select(p => p.PurchaseId);
                                                var purchases = context.Purchases.Count(p => purchaseIds.Contains(p.PurchaseId) && p.Date > promo.StartDate && p.Date < promo.EndDate);
                                                if (purchases > 0)
                                                    ViewBag.UserHasAvailedOfPromo201410 = true;
                                            }
                                        }
                                        catch (Exception) { }
                                    }
                                }
                            }
                            else if (String.Compare(id, "lckbprea", true) == 0)
                            {
                                var registDt = DateTime.Now;
                                var preBlackPromo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.PreBlackPromoId && p.StatusId == GlobalConfig.Visible && p.StartDate < registDt && p.EndDate > registDt);
                                if (preBlackPromo != null)
                                {
                                    //productIds = MyUtility.StringToIntList(GlobalConfig.PreBlackPromoProductIds);
                                    var productIdsList = new List<Int32>();
                                    var preBlackPromoIds = MyUtility.StringToIntList(GlobalConfig.PreBlackPromoProductIds).ToList();
                                    var preBlackPurchaseItems = context.PurchaseItems.Where(p => preBlackPromoIds.Contains(p.ProductId) && p.RecipientUserId == user.UserId).Select(p => p.SubscriptionProduct);
                                    List<Int32> preBlackPurchaseItemsList = preBlackPurchaseItems.Select(p => p.Duration).ToList();
                                    var sumDuration = preBlackPurchaseItemsList.Take(preBlackPurchaseItemsList.Count).Sum();
                                    if (sumDuration > 11)
                                    {
                                        var ReturnCode = new TransactionReturnType()
                                        {
                                            StatusCode = (int)ErrorCodes.UnknownError,
                                            StatusMessage = "You have reached the maximum number of purchases for this product.",
                                            info = "pre-black",
                                            TransactionType = "Purchase"
                                        };

                                        TempData["ErrorMessage"] = ReturnCode;
                                        return RedirectToAction("Index", "Home");
                                    }
                                    if (sumDuration < 12)
                                        productIdsList.Add(preBlackPromoIds[0]);
                                    if (sumDuration < 9)
                                        productIdsList.Add(preBlackPromoIds[1]);
                                    if (sumDuration == 0)
                                        productIdsList.Add(preBlackPromoIds[2]);
                                    productIds = productIdsList;
                                }
                            }
                            else if (String.Compare(id, "atra", true) == 0)
                            {
                                var registDt = DateTime.Now;
                                var productIdsList = new List<Int32>();
                                var projectBlackPromoIdsList = MyUtility.StringToIntList(GlobalConfig.ProjectBlackPromoIds);
                                var projectBlackProductIdsList = MyUtility.StringToIntList(GlobalConfig.ProjectBlackProductIds).ToList();
                                var blackProjetPromo = context.Promos.FirstOrDefault(p => projectBlackPromoIdsList.Contains(p.PromoId) && p.StatusId == GlobalConfig.Visible && p.StartDate < registDt && p.EndDate > registDt);
                                if (blackProjetPromo != null)
                                {
                                    if (User.Identity.IsAuthenticated)
                                    {
                                        var userpromo = context.UserPromos.FirstOrDefault(u => u.UserId == UserId && projectBlackPromoIdsList.Contains(u.PromoId));
                                        if (userpromo == null)
                                        {
                                            if (projectBlackProductIdsList.Count > 0)
                                            {
                                                productIdsList.Add(projectBlackProductIdsList[projectBlackProductIdsList.Count - 1]);
                                                productIds = productIdsList;
                                                ViewBag.isProjectBlack = true;
                                                var premium3mo = context.Products.FirstOrDefault(p => p.ProductId == 1);
                                                if (premium3mo != null)
                                                    ViewBag.Premium1MonthPrice = premium3mo.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                            }
                                            else
                                            {
                                                return RedirectToAction("Details", new { id = String.Empty });
                                            }
                                        }
                                        else
                                        {
                                            var ReturnCode = new TransactionReturnType()
                                            {
                                                StatusCode = (int)ErrorCodes.UnknownError,
                                                StatusMessage = "You have already claimed this promo.",
                                                info = "black",
                                                TransactionType = "Purchase"
                                            };

                                            TempData["ErrorMessage"] = ReturnCode;
                                            return RedirectToAction("Index", "Home");
                                        }
                                    }
                                }
                                else
                                {
                                    return RedirectToAction("Details", new { id = String.Empty });
                                }
                            }
                            else if (String.Compare(id, "aintone", true) == 0)
                            {
                                var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.Q22015PromoId);
                                if (promo != null)
                                {
                                    var registDt = DateTime.Now;
                                    if (promo.StatusId == GlobalConfig.Visible && promo.StartDate < registDt && promo.EndDate > registDt)
                                    {
                                        ViewBag.IsPromoQ22015 = true;
                                        ViewBag.PreventAutoRenewalCheckboxFromUntick = true;
                                        productIds = q22015promo; // discounted 1month premium
                                        //get amount of 3 month premium
                                        var premium1mo = context.Products.FirstOrDefault(p => p.ProductId == 1);
                                        if (premium1mo != null)
                                            ViewBag.Premium1MonthPrice = premium1mo.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);

                                        //check purchasetry
                                        try
                                        {
                                            var user_purchases = context.PurchaseItems.Where(p => q22015promo.Contains(p.ProductId) && p.RecipientUserId == user.UserId);
                                            if (user_purchases != null)
                                            {
                                                var purchaseIds = user_purchases.Select(p => p.PurchaseId);
                                                var purchases = context.Purchases.Count(p => purchaseIds.Contains(p.PurchaseId) && p.Date > promo.StartDate && p.Date < promo.EndDate);
                                                if (purchases > 0)
                                                    ViewBag.UserHasAvailedOfQ22015Promo = true;
                                            }
                                        }
                                        catch (Exception) { }
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region code for shwoing all the products
                    else
                    {
                        var premiumProductGroupIds = MyUtility.StringToIntList(GlobalConfig.premiumProductGroupIds);
                        var productGroup = context.ProductGroups.Where(p => premiumProductGroupIds.Contains(p.ProductGroupId));
                        if (productGroup != null)
                        {
                            foreach (var gr in productGroup)
                            {
                                var groupProductIds = gr.SubscriptionProducts.Select(p => p.ProductId);
                                productIds = productIds.Union(groupProductIds);
                            }
                        }
                    }
                    #endregion
                    ViewBag.IsAlaCarteProduct = IsAlaCarteProduct;

                    //Check for Recurring Billing
                    List<int> recurring_packages = null;
                    if (User.Identity.IsAuthenticated)
                    {
                        var recurring = context.RecurringBillings.Where(r => r.UserId == user.UserId && r.StatusId == GlobalConfig.Visible);
                        if (recurring != null)
                            recurring_packages = recurring.Select(r => r.PackageId).ToList();
                    }

                    var products = context.Products.Where(p => productIds.Contains(p.ProductId) && p is SubscriptionProduct);
                    #region products not null
                    if (products != null)
                    {
                        if (products.Count() > 0)
                        {
                            Product freeProduct = null;
                            ProductPrice freeProductPrice = null;
                            productList = new List<SubscriptionProductA>();
                            foreach (SubscriptionProduct item in products)
                            {
                                if (item.IsAllowed(CountryCode) && item.IsForSale && item.StatusId == GlobalConfig.Visible)
                                {
                                    #region pakage subscription
                                    if (item is PackageSubscriptionProduct)
                                    {
                                        var psp = (PackageSubscriptionProduct)item;
                                        var package = psp.Packages.FirstOrDefault();
                                        if (package != null)
                                        {
                                            int counter = package.Package.GetAllOnlineShowIds(CountryCode).Count();
                                            var sItem = new SubscriptionProductA()
                                            {
                                                package = (Package)package.Package,
                                                product = item,
                                                contentCount = counter,
                                                contentDescription = ContentDescriptionFlooring(counter > 1 ? counter - 1 : counter, true),
                                                ListOfDescription = ContextHelper.GetPackageFeatures(CountryCode, package),
                                                IsUserEnrolledToSameRecurringPackage = recurring_packages == null ? false : recurring_packages.Contains(package.PackageId)
                                            };

                                            try
                                            {
                                                if (!String.IsNullOrEmpty(psp.ProductGroup.Description))
                                                    sItem.Blurb = psp.ProductGroup.Blurb;
                                            }
                                            catch (Exception) { }

                                            if (item.RegularProductId != null)
                                            {
                                                try
                                                {
                                                    var regularProduct = context.Products.FirstOrDefault(p => p.ProductId == item.RegularProductId);
                                                    if (regularProduct != null)
                                                        if (regularProduct is SubscriptionProduct)
                                                        {
                                                            sItem.regularProduct = (SubscriptionProduct)regularProduct;
                                                            try
                                                            {
                                                                sItem.regularProductPrice = regularProduct.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                                            }
                                                            catch (Exception) { }

                                                        }
                                                }
                                                catch (Exception) { }
                                            }
                                            else if (IsXoomUser)
                                            {
                                                if (freeProductPrice != null && freeProduct != null)
                                                {
                                                    sItem.freeProduct = (SubscriptionProduct)freeProduct;
                                                    sItem.freeProductPrice = freeProductPrice;
                                                }
                                            }

                                            try
                                            {
                                                sItem.productPrice = item.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                                if (sItem.productPrice != null)
                                                    productList.Add(sItem);
                                            }
                                            catch (Exception) { ViewBag.ProductPriceError = true; }
                                        }
                                    }
                                    #endregion
                                    #region show subscription
                                    else if (item is ShowSubscriptionProduct)
                                    {
                                        var ssp = (ShowSubscriptionProduct)item;
                                        var category = ssp.Categories.FirstOrDefault();
                                        if (category != null)
                                        {
                                            var sItem = new SubscriptionProductA()
                                            {
                                                product = item,
                                                contentCount = 1,
                                                show = category.Show,
                                                ShowDescription = category.Show.Blurb
                                            };
                                            try
                                            {
                                                if (!String.IsNullOrEmpty(ssp.ProductGroup.Description))
                                                    sItem.Blurb = ssp.ProductGroup.Description;
                                            }
                                            catch (Exception) { }

                                            try
                                            {
                                                sItem.productPrice = item.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                                if (sItem.productPrice != null)
                                                    productList.Add(sItem);
                                            }
                                            catch (Exception) { ViewBag.ProductPriceError = true; }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                    #endregion
                    else
                        return RedirectToAction("Index", "Home");
                    //var productPackages = context.ProductPackages.Where(p => productIds.Contains(p.ProductId));
                    //if (productPackages != null)
                    //{
                    //    if (productPackages.Count() > 0)
                    //    {
                    //        productList = new List<SubscriptionProductA>();
                    //        foreach (var item in productPackages)
                    //        {
                    //            if (item.Product.IsAllowed(CountryCode) && item.Product.IsForSale && item.Product.StatusId == GlobalConfig.Visible)
                    //            {
                    //                var package = item.Product.Packages.FirstOrDefault();
                    //                if (package != null)
                    //                {
                    //                    int counter = item.Package.GetAllOnlineShowIds(CountryCode).Count();
                    //                    var sItem = new SubscriptionProductA()
                    //                    {
                    //                        package = (Package)item.Package,
                    //                        product = item.Product,
                    //                        contentCount = counter,
                    //                        contentDescription = ContentDescriptionFlooring(counter > 1 ? counter - 1 : counter, true),
                    //                        ListOfDescription = ContextHelper.GetPackageFeatures(CountryCode, package)
                    //                    };

                    //                    try
                    //                    {
                    //                        sItem.productPrice = item.Product.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                    //                        productList.Add(sItem);
                    //                    }
                    //                    catch (Exception) { ViewBag.ProductPriceError = true; }
                    //                }
                    //            }
                    //        }
                    //    }
                    //}
                    #region product list not null
                    if (productList != null)
                    {
                        if (productList.Count() > 0)
                        {
                            #region productList.Count() > 0
                            //Credit card
                            ViewBag.HasCreditCardEnrolled = false;
                            ViewBag.CreditCardAvailability = true;
                            try
                            {
                                ArrayList list = new ArrayList();
                                for (int i = 0; i < 12; i++)
                                {
                                    SelectListItem item = new SelectListItem()
                                    {
                                        Value = (i + 1).ToString(),
                                        Text = DateTimeFormatInfo.CurrentInfo.GetMonthName(i + 1)
                                    };

                                    list.Add(item);
                                }
                                ViewBag.Months = list;

                                list = new ArrayList();
                                int currentYear = DateTime.Now.Year;
                                for (int i = currentYear; i <= currentYear + 20; i++)
                                {
                                    SelectListItem item = new SelectListItem()
                                    {
                                        Value = i.ToString(),
                                        Text = i.ToString()
                                    };

                                    list.Add(item);
                                }
                                ViewBag.Years = list;

                                if (User.Identity.IsAuthenticated)
                                {
                                    //Get Credit Card List
                                    var ccTypes = user.Country.GetGomsCreditCardTypes();

                                    if (user.Country.GomsSubsidiaryId != GlobalConfig.MiddleEastGomsSubsidiaryId)
                                        ccTypes = user.Country.GetGomsCreditCardTypes();
                                    else
                                    {
                                        var listOfMiddleEastAllowedCountries = GlobalConfig.MECountriesAllowedForCreditCard.Split(',');
                                        if (listOfMiddleEastAllowedCountries.Contains(user.Country.Code))
                                            ccTypes = user.Country.GetGomsCreditCardTypes();
                                        else
                                            ccTypes = null;
                                    }

                                    if (ccTypes == null)
                                        ViewBag.CreditCardAvailability = false;
                                    else
                                    {
                                        List<TFCTV.Helpers.CreditCard> clist = new List<TFCTV.Helpers.CreditCard>();
                                        foreach (var item in ccTypes)
                                            clist.Add(new TFCTV.Helpers.CreditCard() { value = ((int)item).ToString(), text = item.ToString().Replace('_', ' ') });
                                        ViewBag.CreditCardList = clist;
                                    }
                                    if (GlobalConfig.IsRecurringBillingEnabled)
                                    {
                                        var UserCreditCard = user.CreditCards.FirstOrDefault(c => c.StatusId == GlobalConfig.Visible && c.OfferingId == offering.OfferingId);
                                        if (UserCreditCard != null)
                                        {
                                            ViewBag.HasCreditCardEnrolled = true;
                                            ViewBag.UserCreditCard = UserCreditCard;
                                        }
                                    }
                                }
                                else
                                {
                                    var cCountry = context.Countries.FirstOrDefault(c => String.Compare(c.Code, location.countryCode, true) == 0);
                                    if (cCountry != null)
                                    {
                                        var ccTypes = cCountry.GetGomsCreditCardTypes();
                                        if (cCountry.GomsSubsidiaryId != GlobalConfig.MiddleEastGomsSubsidiaryId)
                                            ccTypes = cCountry.GetGomsCreditCardTypes();
                                        else
                                        {
                                            var listOfMiddleEastAllowedCountries = GlobalConfig.MECountriesAllowedForCreditCard.Split(',');
                                            if (listOfMiddleEastAllowedCountries.Contains(cCountry.Code))
                                                ccTypes = cCountry.GetGomsCreditCardTypes();
                                            else
                                                ccTypes = null;
                                        }

                                        if (ccTypes == null)
                                            ViewBag.CreditCardAvailability = false;
                                        else
                                        {
                                            List<TFCTV.Helpers.CreditCard> clist = new List<TFCTV.Helpers.CreditCard>();
                                            foreach (var item in ccTypes)
                                                clist.Add(new TFCTV.Helpers.CreditCard() { value = ((int)item).ToString(), text = item.ToString().Replace('_', ' ') });
                                            ViewBag.CreditCardList = clist;
                                        }
                                    }
                                }
                            }
                            catch (Exception) { }

                            if (User.Identity.IsAuthenticated)
                            {
                                //E-Wallet                         
                                ViewBag.InsufficientWalletBalance = false;
                                try
                                {
                                    var userWallet = user.UserWallets.FirstOrDefault(u => String.Compare(u.Currency, user.Country.CurrencyCode, true) == 0 && u.IsActive == true);
                                    if (userWallet != null)
                                    {
                                        var UserCurrencyCode = user.Country.CurrencyCode;
                                        var productPrice = productList.First().product.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, UserCurrencyCode, true) == 0);
                                        if (productPrice == null)
                                            productPrice = productList.First().product.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, GlobalConfig.DefaultCurrency, true) == 0);
                                        ViewBag.ProductPrice = productPrice;
                                        if (productPrice.Amount > userWallet.Balance)
                                            ViewBag.InsufficientWalletBalance = true;
                                    }
                                }
                                catch (Exception) { }

                                //check if user is first time subscriber
                                ViewBag.IsFirstTimeSubscriber = user.IsFirstTimeSubscriber(offering);
                            }
                            #endregion
                        }

                    }


                    if (productList != null)
                        if (productList.Count() > 0)
                        {
                            if (String.Compare(id, GlobalConfig.PacMaySubscribeCategoryId.ToString(), true) == 0 && !User.Identity.IsAuthenticated)
                                return View("DetailsPacMay2", productList);
                            else
                            {
                                if (ProductOption != null)
                                    ViewBag.ProductOption = (int)ProductOption;
                                return View("Details5", productList);
                            }
                        }

                    return RedirectToAction("Details", new { id = String.Empty });
                    #endregion
            #endregion
                }
                catch (Exception e) { MyUtility.LogException(e); }
                return RedirectToAction("Index", "Home");
            }
        }
コード例 #2
0
        public ActionResult Details(string id, int? PackageOption, int? ProductOption)
        {
            var profiler = MiniProfiler.Current;
            #region if (!Request.Cookies.AllKeys.Contains("version"))
            if (!Request.Cookies.AllKeys.Contains("version"))
            {
                List<SubscriptionProductA> productList = null;
                try
                {
                    #region   if user is not loggedin
                    if (!User.Identity.IsAuthenticated)
                    {
                        if (!String.IsNullOrEmpty(id))
                        {
                            if (String.Compare(id, "mayweather-vs-pacquiao-may-3", true) == 0)
                            {
                                HttpCookie pacMayCookie = new HttpCookie("redirect3178");
                                pacMayCookie.Expires = DateTime.Now.AddDays(1);
                                Response.Cookies.Add(pacMayCookie);
                                id = GlobalConfig.PacMaySubscribeCategoryId.ToString();
                            }

                            if (String.Compare(id, GlobalConfig.PacMaySubscribeCategoryId.ToString(), true) != 0)
                            {
                                TempData["LoginErrorMessage"] = "Please register or sign in to avail of this promo.";
                                TempData["RedirectUrl"] = Request.Url.PathAndQuery;

                                if (String.Compare(id, "lckbprea", true) == 0)
                                {
                                    HttpCookie preBlackCookie = new HttpCookie("redirectlckbprea");
                                    preBlackCookie.Expires = DateTime.Now.AddDays(1);
                                    Response.Cookies.Add(preBlackCookie);
                                }
                                else if (String.Compare(id, "Promo201410", true) == 0)
                                {
                                    HttpCookie promo2014010 = new HttpCookie("promo2014cok");
                                    promo2014010.Expires = DateTime.Now.AddDays(1);
                                    Response.Cookies.Add(promo2014010);
                                }
                                else if (String.Compare(id, "aintone", true) == 0)
                                {
                                    HttpCookie preBlackCookie = new HttpCookie("redirectaintone");
                                    preBlackCookie.Expires = DateTime.Now.AddDays(1);
                                    Response.Cookies.Add(preBlackCookie);
                                }

                                //check if id is integer
                                try
                                {
                                    int tempId = 0;
                                    if (Int32.TryParse(id, out tempId))
                                    {
                                        TempData["LoginErrorMessage"] = "Please sign in to purchase this product.";
                                        TempData["RedirectUrl"] = Request.Url.PathAndQuery;

                                        if (Request.Browser.IsMobileDevice)
                                            return RedirectToAction("MobileSignin", "User", new { ReturnUrl = Server.UrlEncode(Request.Url.PathAndQuery) });
                                        else
                                            return RedirectToAction("Login", "User", new { ReturnUrl = Server.UrlEncode(Request.Url.PathAndQuery) });
                                    }
                                }
                                catch (Exception) { }

                                if (Request.Browser.IsMobileDevice)
                                    return RedirectToAction("MobileSignin", "User");
                                else
                                    return RedirectToAction("Login", "User");
                            }
                        }
                        else
                        {
                            TempData["LoginErrorMessage"] = "Please register or sign in to subscribe.";
                            TempData["RedirectUrl"] = Request.Url.PathAndQuery;

                            if (Request.Browser.IsMobileDevice)
                                return RedirectToAction("MobileSignin", "User");
                            else
                                return RedirectToAction("Login", "User");
                        }
                    }
                    #endregion
                    #region user authenticated flow
                    else
                        if (!String.IsNullOrEmpty(id))
                            if (String.Compare(id, "mayweather-vs-pacquiao-may-3", true) == 0)
                                id = GlobalConfig.PacMaySubscribeCategoryId.ToString();

                    var context = new IPTV2Entities();
              
                    string ip = Request.IsLocal ? "78.95.139.99" : Request.GetUserHostAddressFromCloudflare();
                    if (GlobalConfig.isUAT && !String.IsNullOrEmpty(Request.QueryString["ip"]))
                        ip = Request.QueryString["ip"].ToString();
                    var location = MyUtility.GetLocationBasedOnIpAddress(ip);
                    var CountryCode = location.countryCode;
                    //var CountryCode = MyUtility.GetCountryCodeViaIpAddressWithoutProxy();


                    User user = null;
                    Guid? UserId = null;
                    if (User.Identity.IsAuthenticated)
                    {
                        UserId = new Guid(User.Identity.Name);
                        user = context.Users.FirstOrDefault(u => u.UserId == UserId);
                        if (user != null)
                            CountryCode = user.CountryCode;
                    }


                    var country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0);
                    
                    var premium          = MyUtility.StringToIntList(GlobalConfig.PremiumProductIds);
                    var lite            = MyUtility.StringToIntList(GlobalConfig.LiteProductIds);
                    var movie           = MyUtility.StringToIntList(GlobalConfig.MovieProductIds);
                    var litepromo       = MyUtility.StringToIntList(GlobalConfig.LitePromoProductIds);
                    var promo2014promo  = MyUtility.StringToIntList(GlobalConfig.Promo2014ProductIds);
                    var q22015promo  = MyUtility.StringToIntList(GlobalConfig.Q22015ProductId);

                    var productIds = premium;//productids
                    var offering = context.Offerings.Find(GlobalConfig.offeringId);
                    var service = offering.Services.FirstOrDefault(o => o.PackageId == GlobalConfig.serviceId);

                    bool IsAlaCarteProduct = true;
                    #region code for showing product based on id
                    if (!String.IsNullOrEmpty(id))
                    {
                        int pid;
                        #region if id is integer
                        if (int.TryParse(id, out pid)) // id is an integer, then it's a show, get ala carte only
                        {
                            var show = (Show)context.CategoryClasses.Find(pid);
                            #region check user is blocked on IP by his email
                            if (User.Identity.IsAuthenticated)
                            {
                                var allowedEmails = GlobalConfig.EmailsAllowedToBypassIPBlock.Split(',');
                                var isEmailAllowed = allowedEmails.Contains(user.EMail.ToLower());
                                if (!isEmailAllowed)
                                {
                                    if (!ContextHelper.IsCategoryViewableInUserCountry(show, CountryCode))
                                        return RedirectToAction("Index", "Home");

                                    string CountryCodeBasedOnIpAddress = MyUtility.GetCountryCodeViaIpAddressWithoutProxy();
                                    if (!ContextHelper.IsCategoryViewableInUserCountry(show, CountryCodeBasedOnIpAddress))
                                        return RedirectToAction("Index", "Home");
                                }
                            }
                            #endregion

                            try
                            {
                                #region show parent categories based on show category id
                                var ShowParentCategories = ContextHelper.GetShowParentCategories(show.CategoryId);
                                if (!String.IsNullOrEmpty(ShowParentCategories))
                                {
                                    ViewBag.ShowParentCategories = ShowParentCategories;
                                    if (!MyUtility.IsWhiteListed(String.Empty))
                                    {
                                        #region if not ip whitelisted
                                        var ids = MyUtility.StringToIntList(ShowParentCategories);
                                        var alaCarteIds = MyUtility.StringToIntList(GlobalConfig.UXAlaCarteParentCategoryIds);
                                        var DoCheckForGeoIPRestriction = ids.Intersect(alaCarteIds).Count() > 0;
                                        if (DoCheckForGeoIPRestriction)
                                        {
                                            var ipx = Request.IsLocal ? "221.121.187.253" : String.Empty;
                                            if (GlobalConfig.isUAT)
                                                ipx = Request["ip"];
                                            if (!MyUtility.CheckIfCategoryIsAllowed(show.CategoryId, context, ipx))
                                            {
                                                var ReturnCode = new TransactionReturnType()
                                                {
                                                    StatusHeader = "Content Advisory",
                                                    StatusMessage = "This content is currently not available in your area.",
                                                    StatusMessage2 = "You may select from among the hundreds of shows and movies that are available on the site."
                                                };
                                                TempData["ErrorMessage"] = ReturnCode;
                                                return RedirectToAction("Index", "Home");
                                            }
                                        }
                                        #endregion
                                    }
                                }
                                #endregion
                            }
                            catch (Exception) { }

                            productIds = show.GetPackageProductIds(offering, CountryCode, RightsType.Online);//*
                            var showProductIds = show.GetShowProductIds(offering, CountryCode, RightsType.Online);//*
                            if (showProductIds != null)
                                productIds = productIds.Union(showProductIds);//*

                            //Remove premium, lite & movie packages from list
                            productIds = productIds.Except(premium).Except(lite).Except(movie).Except(litepromo);
                            IsAlaCarteProduct = true;

                            if (pid == GlobalConfig.PacMaySubscribeCategoryId)
                            {
                                ViewBag.IsPacMay = true;
                                //add the additional product ids
                                var additional_pacmay_productids = MyUtility.StringToIntList(GlobalConfig.PacMaySubscribeProductIds);
                                productIds = productIds.Union(additional_pacmay_productids);
                                TempData["IsPacPurchase"] = true;
                            }
                        }
                        #endregion
                        #region if id is not integer
                        else // get packages only
                        {
                            #region if id is Lite
                            if (String.Compare(id, "Lite", true) == 0)
                                productIds = lite;
                                #endregion
                            #region if id is Movie
                            else if (String.Compare(id, "Movie", true) == 0)
                                productIds = movie;
                            #endregion
                            #region if id is LitePromo
                            else if (String.Compare(id, "LitePromo", true) == 0)
                            {
                                var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.LiteChurnersPromoId);
                                if (promo != null)
                                {
                                    var registDt = DateTime.Now;
                                    if (promo.StatusId == GlobalConfig.Visible && promo.StartDate < registDt && promo.EndDate > registDt)
                                        productIds = litepromo; // discounted lite product Ids
                                }
                            }
                            #endregion
                            #region if id is Promo201410
                            else if (String.Compare(id, "Promo201410", true) == 0)
                            {
                                var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.Promo201410PromoId);
                                if (promo != null)
                                {
                                    var registDt = DateTime.Now;
                                    if (promo.StatusId == GlobalConfig.Visible && promo.StartDate < registDt && promo.EndDate > registDt)
                                    {
                                        ViewBag.IsPromo2014 = true;
                                        ViewBag.PreventAutoRenewalCheckboxFromUntick = true;
                                        productIds = promo2014promo; // discounted 3month premium
                                        //get amount of 3 month premium
                                        var premium1mo = context.Products.FirstOrDefault(p => p.ProductId == 1);
                                        if (premium1mo != null)
                                            ViewBag.Premium1MonthPrice = premium1mo.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);

                                        //check purchasetry
                                        try
                                        {
                                            var user_purchases = context.PurchaseItems.Where(p => promo2014promo.Contains(p.ProductId) && p.RecipientUserId == user.UserId);
                                            if (user_purchases != null)
                                            {
                                                var purchaseIds = user_purchases.Select(p => p.PurchaseId);
                                                var purchases = context.Purchases.Count(p => purchaseIds.Contains(p.PurchaseId) && p.Date > promo.StartDate && p.Date < promo.EndDate);
                                                if (purchases > 0)
                                                    ViewBag.UserHasAvailedOfPromo201410 = true;
                                            }
                                        }
                                        catch (Exception) { }
                                    }
                                }
                            }
                            #endregion
                            #region if id is lckbprea
                            else if (String.Compare(id, "lckbprea", true) == 0)
                            {
                                var registDt = DateTime.Now;
                                var preBlackPromo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.PreBlackPromoId && p.StatusId == GlobalConfig.Visible && p.StartDate < registDt && p.EndDate > registDt);
                                if (preBlackPromo != null)
                                {
                                    //productIds = MyUtility.StringToIntList(GlobalConfig.PreBlackPromoProductIds);
                                    var productIdsList = new List<Int32>();
                                    var preBlackPromoIds = MyUtility.StringToIntList(GlobalConfig.PreBlackPromoProductIds).ToList();
                                    var preBlackPurchaseItems = context.PurchaseItems.Where(p => preBlackPromoIds.Contains(p.ProductId) && p.RecipientUserId == user.UserId).Select(p => p.SubscriptionProduct);
                                    List<Int32> preBlackPurchaseItemsList = preBlackPurchaseItems.Select(p => p.Duration).ToList();
                                    var sumDuration = preBlackPurchaseItemsList.Take(preBlackPurchaseItemsList.Count).Sum();
                                    if (sumDuration > 11)
                                    {
                                        var ReturnCode = new TransactionReturnType()
                                        {
                                            StatusCode = (int)ErrorCodes.UnknownError,
                                            StatusMessage = "You have reached the maximum number of purchases for this product.",
                                            info = "pre-black",
                                            TransactionType = "Purchase"
                                        };

                                        TempData["ErrorMessage"] = ReturnCode;
                                        return RedirectToAction("Index", "Home");
                                    }
                                    if (sumDuration < 12)
                                        productIdsList.Add(preBlackPromoIds[0]);
                                    if (sumDuration < 9)
                                        productIdsList.Add(preBlackPromoIds[1]);
                                    if (sumDuration == 0)
                                        productIdsList.Add(preBlackPromoIds[2]);
                                    productIds = productIdsList;
                                }
                            }
                            #endregion
                            #region if id is atra
                            else if (String.Compare(id, "atra", true) == 0)
                            {
                                var registDt = DateTime.Now;
                                var productIdsList = new List<Int32>();
                                var projectBlackPromoIdsList = MyUtility.StringToIntList(GlobalConfig.ProjectBlackPromoIds);
                                var projectBlackProductIdsList = MyUtility.StringToIntList(GlobalConfig.ProjectBlackProductIds).ToList();
                                var blackProjetPromo = context.Promos.FirstOrDefault(p => projectBlackPromoIdsList.Contains(p.PromoId) && p.StatusId == GlobalConfig.Visible && p.StartDate < registDt && p.EndDate > registDt);
                                if (blackProjetPromo != null)
                                {
                                    if (User.Identity.IsAuthenticated)
                                    {
                                        var userpromo = context.UserPromos.FirstOrDefault(u => u.UserId == UserId && projectBlackPromoIdsList.Contains(u.PromoId));
                                        if (userpromo == null)
                                        {
                                            if (projectBlackProductIdsList.Count > 0)
                                            {
                                                productIdsList.Add(projectBlackProductIdsList[projectBlackProductIdsList.Count - 1]);
                                                productIds = productIdsList;
                                                ViewBag.isProjectBlack = true;
                                                var premium3mo = context.Products.FirstOrDefault(p => p.ProductId == 1);
                                                if (premium3mo != null)
                                                    ViewBag.Premium1MonthPrice = premium3mo.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                            }
                                            else
                                            {
                                                return RedirectToAction("Details", new { id = String.Empty });
                                            }
                                        }
                                        else
                                        {
                                            var ReturnCode = new TransactionReturnType()
                                            {
                                                StatusCode = (int)ErrorCodes.UnknownError,
                                                StatusMessage = "You have already claimed this promo.",
                                                info = "black",
                                                TransactionType = "Purchase"
                                            };

                                            TempData["ErrorMessage"] = ReturnCode;
                                            return RedirectToAction("Index", "Home");
                                        }
                                    }
                                }
                                else
                                {
                                    return RedirectToAction("Details", new { id = String.Empty });
                                }
                            }
                            #endregion
                            #region id id is aintone
                            else if (String.Compare(id, "aintone", true) == 0)
                            {
                                var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.Q22015PromoId);
                                if (promo != null)
                                {
                                    var registDt = DateTime.Now;
                                    if (promo.StatusId == GlobalConfig.Visible && promo.StartDate < registDt && promo.EndDate > registDt)
                                    {
                                        ViewBag.IsPromoQ22015 = true;
                                        ViewBag.PreventAutoRenewalCheckboxFromUntick = true;
                                        productIds = q22015promo; // discounted 1month premium
                                        //get amount of 3 month premium
                                        var premium1mo = context.Products.FirstOrDefault(p => p.ProductId == 1);
                                        if (premium1mo != null)
                                            ViewBag.Premium1MonthPrice = premium1mo.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);

                                        //check purchasetry
                                        try
                                        {
                                            var user_purchases = context.PurchaseItems.Where(p => q22015promo.Contains(p.ProductId) && p.RecipientUserId == user.UserId);
                                            if (user_purchases != null)
                                            {
                                                var purchaseIds = user_purchases.Select(p => p.PurchaseId);
                                                var purchases = context.Purchases.Count(p => purchaseIds.Contains(p.PurchaseId) && p.Date > promo.StartDate && p.Date < promo.EndDate);
                                                if (purchases > 0)
                                                    ViewBag.UserHasAvailedOfQ22015Promo = true;
                                            }
                                        }
                                        catch (Exception) { }
                                    }
                                }
                            }
                            #endregion
                        }
                        #endregion
                    }
                    #endregion

                    #region code for shwoing all the products
                    else
                    {
                        var premiumProductGroupIds = MyUtility.StringToIntList(GlobalConfig.premiumProductGroupIds);
                        var productGroup = context.ProductGroups.Where(p => premiumProductGroupIds.Contains(p.ProductGroupId));
                        if (productGroup != null)
                        {
                            foreach (var gr in productGroup)
                            {
                                var groupProductIds = gr.SubscriptionProducts.Select(p => p.ProductId);
                                productIds = productIds.Union(groupProductIds);
                            }
                        }
                    }
                    #endregion
                    ViewBag.IsAlaCarteProduct = IsAlaCarteProduct;

                    //Check for Recurring Billing
                    List<int> recurring_packages = null;
                    if (User.Identity.IsAuthenticated)
                    {
                        var recurring = context.RecurringBillings.Where(r => r.UserId == user.UserId && r.StatusId == GlobalConfig.Visible);
                        if (recurring != null)
                            recurring_packages = recurring.Select(r => r.PackageId).ToList();
                    }
                    
                    var products = context.Products.Where(p => productIds.Contains(p.ProductId) && p is SubscriptionProduct);
                   
                    #region products not null
                    if (products != null)
                    {
                        if (products.Count() > 0)
                        {
                            Product freeProduct = null;
                            ProductPrice freeProductPrice = null;
                            #region not required according to Albin
                            bool IsXoomUser = false;
                            if (User.Identity.IsAuthenticated)
                            {
                                //XOOM 2 Promo
                                IsXoomUser = ContextHelper.IsXoomEligible(context, user);
                                if (IsXoomUser)
                                {
                                    var freeProductId = context.Products.FirstOrDefault(p => p.ProductId == GlobalConfig.Xoom2FreeProductId);
                                    if (freeProductId != null)
                                        if (freeProductId is SubscriptionProduct)
                                        {
                                            freeProduct = (SubscriptionProduct)freeProductId;
                                            try
                                            {
                                                freeProductPrice = freeProductId.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                                ViewBag.IsAPRBoxDisabled = true;
                                                ViewBag.PageDescription = "Choose a package and provide your credit card or PayPal details to finish your registration and get your 1st month FREE!";
                                                TempData["xoom"] = true;
                                            }
                                            catch (Exception) { }

                                        }
                                }
                            }
                            #endregion
                            productList = new List<SubscriptionProductA>();

                            foreach (SubscriptionProduct item in products)
                            {
                                if (item.IsAllowed(CountryCode) && item.IsForSale && item.StatusId == GlobalConfig.Visible)
                                {
                                    #region pakage subscription
                                    if (item is PackageSubscriptionProduct)
                                    {
                                        var psp = (PackageSubscriptionProduct)item;
                                        var package = psp.Packages.FirstOrDefault();    
                                        if (package != null)
                                        {
                                            int counter = package.Package.GetAllOnlineShowIds(CountryCode).Count();
                                            var sItem = new SubscriptionProductA()
                                            {
                                                package = (Package)package.Package,
                                                product = item,
                                                contentCount = counter,
                                                contentDescription = ContentDescriptionFlooring(counter > 1 ? counter - 1 : counter, true),
                                                ListOfDescription = ContextHelper.GetPackageFeatures(CountryCode, package),
                                                IsUserEnrolledToSameRecurringPackage = recurring_packages == null ? false : recurring_packages.Contains(package.PackageId)
                                            };

                                            try
                                            {
                                                if (!String.IsNullOrEmpty(psp.ProductGroup.Description))
                                                    sItem.Blurb = psp.ProductGroup.Blurb;
                                            }
                                            catch (Exception) { }

                                            if (item.RegularProductId != null)
                                            {
                                                try
                                                {
                                                    var regularProduct = context.Products.FirstOrDefault(p => p.ProductId == item.RegularProductId);
                                                    if (regularProduct != null)
                                                        if (regularProduct is SubscriptionProduct)
                                                        {
                                                            sItem.regularProduct = (SubscriptionProduct)regularProduct;
                                                            try
                                                            {
                                                                sItem.regularProductPrice = regularProduct.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                                            }
                                                            catch (Exception) { }

                                                        }
                                                }
                                                catch (Exception) { }
                                            }
                                            #region xoom user not required
                                            else if (IsXoomUser)
                                            {
                                                if (freeProductPrice != null && freeProduct != null)
                                                {
                                                    sItem.freeProduct = (SubscriptionProduct)freeProduct;
                                                    sItem.freeProductPrice = freeProductPrice;
                                                }
                                            }
                                            #endregion
                                            try
                                            {
                                                sItem.productPrice = item.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                                if (sItem.productPrice != null)
                                                    productList.Add(sItem);
                                            }
                                            catch (Exception) { ViewBag.ProductPriceError = true; }
                                        }
                                    }
                                    #endregion
                                    #region show subscription
                                    else if (item is ShowSubscriptionProduct)
                                    {
                                        var ssp = (ShowSubscriptionProduct)item;
                                        var category = ssp.Categories.FirstOrDefault();
                                        if (category != null)
                                        {
                                            var sItem = new SubscriptionProductA()
                                            {
                                                product = item,
                                                contentCount = 1,
                                                show = category.Show,
                                                ShowDescription = category.Show.Blurb
                                            };
                                            try
                                            {
                                                if (!String.IsNullOrEmpty(ssp.ProductGroup.Description))
                                                    sItem.Blurb = ssp.ProductGroup.Description;
                                            }
                                            catch (Exception) { }

                                            try
                                            {
                                                sItem.productPrice = item.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                                                if (sItem.productPrice != null)
                                                    productList.Add(sItem);
                                            }
                                            catch (Exception) { ViewBag.ProductPriceError = true; }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                    #endregion
                    else
                        return RedirectToAction("Index", "Home");
                    #region
                    //var productPackages = context.ProductPackages.Where(p => productIds.Contains(p.ProductId));
                    //if (productPackages != null)
                    //{
                    //    if (productPackages.Count() > 0)
                    //    {
                    //        productList = new List<SubscriptionProductA>();
                    //        foreach (var item in productPackages)
                    //        {
                    //            if (item.Product.IsAllowed(CountryCode) && item.Product.IsForSale && item.Product.StatusId == GlobalConfig.Visible)
                    //            {
                    //                var package = item.Product.Packages.FirstOrDefault();
                    //                if (package != null)
                    //                {
                    //                    int counter = item.Package.GetAllOnlineShowIds(CountryCode).Count();
                    //                    var sItem = new SubscriptionProductA()
                    //                    {
                    //                        package = (Package)item.Package,
                    //                        product = item.Product,
                    //                        contentCount = counter,
                    //                        contentDescription = ContentDescriptionFlooring(counter > 1 ? counter - 1 : counter, true),
                    //                        ListOfDescription = ContextHelper.GetPackageFeatures(CountryCode, package)
                    //                    };

                    //                    try
                    //                    {
                    //                        sItem.productPrice = item.Product.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, country.CurrencyCode, true) == 0);
                    //                        productList.Add(sItem);
                    //                    }
                    //                    catch (Exception) { ViewBag.ProductPriceError = true; }
                    //                }
                    //            }
                    //        }
                    //    }
                    //}
                    #endregion
                    #region product list not null
                    if (productList != null)
                    {
                        if (productList.Count() > 0)
                        {
                            #region productList.Count() > 0
                            //Credit card
                            ViewBag.HasCreditCardEnrolled = false;
                            ViewBag.CreditCardAvailability = true;
                            try
                            {
                                ArrayList list = new ArrayList();
                                for (int i = 0; i < 12; i++)
                                {
                                    SelectListItem item = new SelectListItem()
                                    {
                                        Value = (i + 1).ToString(),
                                        Text = DateTimeFormatInfo.CurrentInfo.GetMonthName(i + 1)
                                    };

                                    list.Add(item);
                                }
                                ViewBag.Months = list;

                                list = new ArrayList();
                                int currentYear = DateTime.Now.Year;
                                for (int i = currentYear; i <= currentYear + 20; i++)
                                {
                                    SelectListItem item = new SelectListItem()
                                    {
                                        Value = i.ToString(),
                                        Text = i.ToString()
                                    };

                                    list.Add(item);
                                }
                                ViewBag.Years = list;

                                if (User.Identity.IsAuthenticated)
                                {
                                    //Get Credit Card List
                                    var ccTypes = user.Country.GetGomsCreditCardTypes();

                                    if (user.Country.GomsSubsidiaryId != GlobalConfig.MiddleEastGomsSubsidiaryId)
                                        ccTypes = user.Country.GetGomsCreditCardTypes();
                                    else
                                    {
                                        var listOfMiddleEastAllowedCountries = GlobalConfig.MECountriesAllowedForCreditCard.Split(',');
                                        if (listOfMiddleEastAllowedCountries.Contains(user.Country.Code))
                                            ccTypes = user.Country.GetGomsCreditCardTypes();
                                        else
                                            ccTypes = null;
                                    }

                                    if (ccTypes == null)
                                        ViewBag.CreditCardAvailability = false;
                                    else
                                    {
                                        List<TFCTV.Helpers.CreditCard> clist = new List<TFCTV.Helpers.CreditCard>();
                                        foreach (var item in ccTypes)
                                            clist.Add(new TFCTV.Helpers.CreditCard() { value = ((int)item).ToString(), text = item.ToString().Replace('_', ' ') });
                                        ViewBag.CreditCardList = clist;
                                    }
                                    if (GlobalConfig.IsRecurringBillingEnabled)
                                    {
                                        var UserCreditCard = user.CreditCards.FirstOrDefault(c => c.StatusId == GlobalConfig.Visible && c.OfferingId == offering.OfferingId);
                                        if (UserCreditCard != null)
                                        {
                                            ViewBag.HasCreditCardEnrolled = true;
                                            ViewBag.UserCreditCard = UserCreditCard;
                                        }
                                    }
                                }
                                else
                                {
                                    var cCountry = context.Countries.FirstOrDefault(c => String.Compare(c.Code, location.countryCode, true) == 0);
                                    if (cCountry != null)
                                    {
                                        var ccTypes = cCountry.GetGomsCreditCardTypes();
                                        if (cCountry.GomsSubsidiaryId != GlobalConfig.MiddleEastGomsSubsidiaryId)
                                            ccTypes = cCountry.GetGomsCreditCardTypes();
                                        else
                                        {
                                            var listOfMiddleEastAllowedCountries = GlobalConfig.MECountriesAllowedForCreditCard.Split(',');
                                            if (listOfMiddleEastAllowedCountries.Contains(cCountry.Code))
                                                ccTypes = cCountry.GetGomsCreditCardTypes();
                                            else
                                                ccTypes = null;
                                        }

                                        if (ccTypes == null)
                                            ViewBag.CreditCardAvailability = false;
                                        else
                                        {
                                            List<TFCTV.Helpers.CreditCard> clist = new List<TFCTV.Helpers.CreditCard>();
                                            foreach (var item in ccTypes)
                                                clist.Add(new TFCTV.Helpers.CreditCard() { value = ((int)item).ToString(), text = item.ToString().Replace('_', ' ') });
                                            ViewBag.CreditCardList = clist;
                                        }
                                    }
                                }
                            }
                            catch (Exception) { }

                            if (User.Identity.IsAuthenticated)
                            {
                                //E-Wallet                         
                                ViewBag.InsufficientWalletBalance = false;
                                try
                                {
                                    var userWallet = user.UserWallets.FirstOrDefault(u => String.Compare(u.Currency, user.Country.CurrencyCode, true) == 0 && u.IsActive == true);
                                    if (userWallet != null)
                                    {
                                        var UserCurrencyCode = user.Country.CurrencyCode;
                                        var productPrice = productList.First().product.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, UserCurrencyCode, true) == 0);
                                        if (productPrice == null)
                                            productPrice = productList.First().product.ProductPrices.FirstOrDefault(p => String.Compare(p.CurrencyCode, GlobalConfig.DefaultCurrency, true) == 0);
                                        ViewBag.ProductPrice = productPrice;
                                        if (productPrice.Amount > userWallet.Balance)
                                            ViewBag.InsufficientWalletBalance = true;
                                    }
                                }
                                catch (Exception) { }

                                //check if user is first time subscriber
                                ViewBag.IsFirstTimeSubscriber = user.IsFirstTimeSubscriber(offering);
                            }
                            #endregion
                        }
                           
                    }
                   

                    if (productList != null)
                        if (productList.Count() > 0)
                        {
                            if (String.Compare(id, GlobalConfig.PacMaySubscribeCategoryId.ToString(), true) == 0 && !User.Identity.IsAuthenticated)
                                return View("DetailsPacMay2", productList);
                            else
                            {
                                if (ProductOption != null)
                                    ViewBag.ProductOption = (int)ProductOption;
                                return View("Details5", productList);
                            }
                        }

                    return RedirectToAction("Details", new { id = String.Empty });
                    #endregion
                    #endregion
                }
                catch (Exception e) { MyUtility.LogException(e); }
                return RedirectToAction("Index", "Home");
            }
            #endregion
            #region else for the above if
            else
            {
                List<SubscriptionProductA> productList = null;
                try
                {
                    var countryCode = MyUtility.GetCurrentCountryCodeOrDefault();
                    var context = new IPTV2Entities();
                    var country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, countryCode, true) == 0);
                    var offering = context.Offerings.Find(GlobalConfig.offeringId);
                    var service = offering.Services.FirstOrDefault(o => o.PackageId == GlobalConfig.serviceId);
                    var listOfPackagesInProductGroup = MyUtility.StringToIntList(GlobalConfig.PackagesInProductGroup);

                    if (!String.IsNullOrEmpty(id))
                    {
                        int pid = 0;
                        try
                        {
                            pid = Int32.Parse(id);
                        }
                        catch (Exception) { }
                        ViewBag.id = pid;
                        using (profiler.Step("Get Subscription (w/ parameter)"))
                        {
                            var show = (Show)context.CategoryClasses.Find(pid);

                            /******* CHECK IF SHOW IS VIEWABLE VIA USER'S COUNTRY CODE & COUNTRY CODE BASED ON IP ADDRESS *****/
                            if (!ContextHelper.IsCategoryViewableInUserCountry(show, countryCode))
                                return RedirectToAction("Index", "Home");
                            string CountryCodeBasedOnIpAddress = MyUtility.GetCountryCodeViaIpAddressWithoutProxy();
                            if (!ContextHelper.IsCategoryViewableInUserCountry(show, CountryCodeBasedOnIpAddress))
                                return RedirectToAction("Index", "Home");

                            ViewBag.ShowName = show.Description;
                            SortedSet<Int32> productIds = new SortedSet<int>();
                            var packageProductIds = show.GetPackageProductIds(offering, countryCode, RightsType.Online);
                            if (packageProductIds != null)
                                productIds.UnionWith(packageProductIds);
                            var showProductIds = show.GetShowProductIds(offering, countryCode, RightsType.Online);
                            if (showProductIds != null)
                                productIds.UnionWith(showProductIds);
                            ViewBag.PackageProductIds = packageProductIds;
                            ViewBag.ShowProductIds = showProductIds;
                            var products = context.Products.Where(p => productIds.Contains(p.ProductId));
                            List<PackageContentSummary> contentSummary = new List<PackageContentSummary>();
                            if (products != null)
                            {
                                productList = new List<SubscriptionProductA>();
                                foreach (var product in products)
                                {
                                    if (product.IsForSale && product.StatusId == GlobalConfig.Visible)
                                    {
                                        if (product is SubscriptionProduct)
                                        {
                                            if (product is PackageSubscriptionProduct)
                                            {
                                                var pkgSubscriptionProduct = (PackageSubscriptionProduct)product;
                                                var package = pkgSubscriptionProduct.Packages.FirstOrDefault();
                                                var counter = 0;
                                                var item = new SubscriptionProductA() { product = (SubscriptionProduct)product, productGroup = pkgSubscriptionProduct.ProductGroup, isPackage = true };

                                                //SET DEFAULT PRODUCT ID VIA PARAM                                            
                                                if (PackageOption != null)
                                                {
                                                    if (listOfPackagesInProductGroup.Contains((int)PackageOption))
                                                        if (pkgSubscriptionProduct.ProductGroupId == PackageOption)
                                                            if (ProductOption != null)
                                                                item.productGroup.DefaultProductId = ProductOption;
                                                }

                                                if (package != null)
                                                {
                                                    // make sure that this doesnt repeat. save data in list
                                                    if (!contentSummary.Select(s => s.PackageId).Contains(package.PackageId))
                                                    {
                                                        foreach (var cat in package.Package.Categories)
                                                        {
                                                            if (cat.Category is Category)
                                                                counter += service.GetAllOnlineShowIds(countryCode, (Category)cat.Category).Count();
                                                        }
                                                        contentSummary.Add(new PackageContentSummary() { PackageId = package.PackageId, ContentCount = counter });
                                                    }
                                                    else
                                                        counter = contentSummary.FirstOrDefault(s => s.PackageId == package.PackageId).ContentCount;
                                                    item.contentCount = counter;
                                                    //for description of content
                                                    item.contentDescription = ContentDescriptionFlooring(counter > 1 ? counter - 1 : counter, true);
                                                    item.package = (Package)package.Package;
                                                    item.ListOfDescription = ContextHelper.GetPackageFeatures(countryCode, package);
                                                    if (item.productGroup.ProductSubscriptionTypeId != null)
                                                        item.ShowDescription = show.Blurb;
                                                }

                                                try
                                                {
                                                    item.productPrice = pkgSubscriptionProduct.ProductPrices.FirstOrDefault(p => p.CurrencyCode == country.CurrencyCode);
                                                    productList.Add(item);
                                                }
                                                catch (Exception) { ViewBag.ProductPriceError = true; }

                                            }
                                            else if (product is ShowSubscriptionProduct)
                                            {
                                                var shwSubscriptionProduct = (ShowSubscriptionProduct)product;
                                                var category = shwSubscriptionProduct.Categories.FirstOrDefault();
                                                var item = new SubscriptionProductA() { product = (SubscriptionProduct)product, productGroup = shwSubscriptionProduct.ProductGroup, contentCount = 1 };

                                                if (category != null)
                                                {
                                                    item.show = category.Show;
                                                    item.ShowDescription = category.Show.Blurb;
                                                }

                                                try
                                                {
                                                    item.productPrice = shwSubscriptionProduct.ProductPrices.FirstOrDefault(p => p.CurrencyCode == country.CurrencyCode);
                                                    productList.Add(item);
                                                }
                                                catch (Exception) { ViewBag.ProductPriceError = true; }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        using (profiler.Step("Get Subscription (no parameter)"))
                        {
                            var groups = context.ProductGroups.Where(p => listOfPackagesInProductGroup.Contains(p.ProductGroupId));
                            if (groups != null)
                            {
                                List<PackageContentSummary> contentSummary = new List<PackageContentSummary>();
                                productList = new List<SubscriptionProductA>();
                                foreach (var grp in groups)
                                {
                                    foreach (var product in grp.SubscriptionProducts)
                                    {
                                        if (product.IsAllowed(countryCode))
                                        {
                                            if (product.IsForSale && product.StatusId == GlobalConfig.Visible)
                                            {
                                                if (product is PackageSubscriptionProduct)
                                                {
                                                    var pkgSubscriptionProduct = (PackageSubscriptionProduct)product;
                                                    var package = pkgSubscriptionProduct.Packages.FirstOrDefault();
                                                    var counter = 0;
                                                    var item = new SubscriptionProductA() { product = product, productGroup = pkgSubscriptionProduct.ProductGroup, isPackage = true };
                                                    //SET DEFAULT PRODUCT ID VIA PARAM                                            
                                                    if (PackageOption != null)
                                                    {
                                                        if (listOfPackagesInProductGroup.Contains((int)PackageOption))
                                                            if (pkgSubscriptionProduct.ProductGroupId == PackageOption)
                                                                if (ProductOption != null)
                                                                    item.productGroup.DefaultProductId = ProductOption;
                                                    }
                                                    if (package != null)
                                                    {
                                                        // make sure that this doesnt repeat. save data in list
                                                        if (!contentSummary.Select(s => s.PackageId).Contains(package.PackageId))
                                                        {
                                                            foreach (var cat in package.Package.Categories)
                                                            {
                                                                if (cat.Category is Category)
                                                                    counter += service.GetAllOnlineShowIds(countryCode, (Category)cat.Category).Count();
                                                            }
                                                            contentSummary.Add(new PackageContentSummary() { PackageId = package.PackageId, ContentCount = counter });
                                                        }
                                                        else
                                                            counter = contentSummary.FirstOrDefault(s => s.PackageId == package.PackageId).ContentCount;
                                                        item.contentCount = counter;
                                                        item.contentDescription = ContentDescriptionFlooring(counter, true);
                                                        item.package = (Package)package.Package;
                                                        item.ListOfDescription = ContextHelper.GetPackageFeatures(countryCode, package);
                                                    }
                                                    try
                                                    {
                                                        item.productPrice = pkgSubscriptionProduct.ProductPrices.FirstOrDefault(p => p.CurrencyCode == country.CurrencyCode);
                                                        productList.Add(item);
                                                    }
                                                    catch (Exception) { ViewBag.ProductPriceError = true; }

                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // SET DEFAULT PACKAGE. Position Swap!                            
                    if (productList != null)
                    {
                        if (productList.Count() > 0)
                        {
                            if (PackageOption != null)
                            {
                                int index = 0;
                                if (listOfPackagesInProductGroup.Contains((int)PackageOption))
                                    index = productList.FindIndex(x => x.productGroup.ProductGroupId == PackageOption);
                                else
                                    index = productList.FindIndex(x => !listOfPackagesInProductGroup.Contains(x.productGroup.ProductGroupId));
                                if (index > 0)
                                {
                                    var item = productList[index];
                                    productList[index] = productList[0];
                                    productList[0] = item;
                                }
                            }
                        }
                    }

                    //Only return if productList is not empty and count > 0
                    if (productList != null)
                        if (productList.Count() > 0)
                            return View("Details5", productList);

                }
                catch (Exception e) { MyUtility.LogException(e); }
                return RedirectToAction("Index", "Home");
            }
            #endregion
        }