//recursively get all the types this object represents. private SortedSet<Type> GetTypesForImport(Object value) { Type valueType = value.GetType(); SortedSet<Type> set = new SortedSet<Type>(); IEnumerable collection = value as IEnumerable; if (collection != null) { foreach (var item in collection) { set.UnionWith(GetTypesForImport(item)); } } else if (valueType.IsGenericType) { Type generictype = valueType.GetGenericTypeDefinition(); set.UnionWith(generictype.GetGenericArguments()); //also add the valueType to be used as raw data set.Add(valueType); } else set.Add(CLRObjectMarshler.GetPublicType(valueType)); return set; }
public ActionResult GetAllVideosBasedOnEntitlements() { List<ShowLookUpObject> list = null; if (!GlobalConfig.IsSynapseEnabled) return Json(list, JsonRequestBehavior.AllowGet); var registDt = DateTime.Now; if (MyUtility.isUserLoggedIn()) { try { //var cache = DataCache.Cache; //string cacheKey = "MOBILEGAV:U:" + User.Identity.Name; //list = (List<ShowLookUpObject>)cache[cacheKey]; if (list == null) { list = new List<ShowLookUpObject>(); var context = new IPTV2Entities(); var UserId = new Guid(User.Identity.Name); var user = context.Users.FirstOrDefault(u => u.UserId == UserId); if (user != null) { SortedSet<Int32> ShowIds = new SortedSet<int>(); var service = context.Offerings.Find(GlobalConfig.offeringId).Services.FirstOrDefault(s => s.StatusId == GlobalConfig.Visible); foreach (var entitlement in user.Entitlements.Where(e => e.EndDate > registDt)) { if (entitlement is PackageEntitlement) { var packageEntitlement = (PackageEntitlement)entitlement; var pkgCat = context.PackageCategories.Where(p => p.PackageId == packageEntitlement.PackageId).Select(p => p.Category); var pkgCatSubCategories = pkgCat.Select(p => p.SubCategories); foreach (var categories in pkgCatSubCategories) { foreach (var category in categories) { var listOfIds = service.GetAllMobileShowIds(MyUtility.GetCurrentCountryCodeOrDefault(), category); var showList = context.CategoryClasses.Where(c => listOfIds.Contains(c.CategoryId) && c.StatusId == GlobalConfig.Visible); foreach (var show in showList) { if (show != null) { if (!(ShowIds.Contains(show.CategoryId))) { if (show.StartDate < registDt && show.EndDate > registDt) { if (show is Show) { if (!(show is LiveEvent)) { ShowLookUpObject data = new ShowLookUpObject(); data.Show = show.Description; data.ShowId = show.CategoryId; data.MainCategory = category.Description; data.MainCategoryId = category.CategoryId; data.ShowType = (show is Movie) ? "MOVIE" : "SHOW"; if (!(show is Movie)) list.Add(data); } } } } } } ShowIds.UnionWith(listOfIds); //For checking } } } else if (entitlement is ShowEntitlement) { var showEntitlement = (ShowEntitlement)entitlement; if (!(ShowIds.Contains(showEntitlement.CategoryId))) { if (!(showEntitlement.Show is LiveEvent)) { ShowLookUpObject data = new ShowLookUpObject(); var show = showEntitlement.Show; if (show != null) { if (show.StartDate < registDt && show.EndDate > registDt) { var CacheDuration = new TimeSpan(0, GlobalConfig.GetParentCategoriesCacheDuration, 0); var parentCategories = show.GetAllParentCategories(CacheDuration); var parent = context.CategoryClasses.Where(c => parentCategories.Contains(c.CategoryId) && c.StatusId == GlobalConfig.Visible && c is Category); data.Show = show.Description; data.ShowId = show.CategoryId; data.MainCategory = parent.First().Description; data.MainCategoryId = parent.First().CategoryId; data.ShowType = (show is Movie) ? "MOVIE" : "SHOW"; if (!(show is Movie)) ShowIds.Add(show.CategoryId); list.Add(data); } } } } } else if (entitlement is EpisodeEntitlement) { var episodeEntitlement = (EpisodeEntitlement)entitlement; var eCacheDuration = new TimeSpan(0, GlobalConfig.GetParentShowsForEpisodeCacheDuration, 0); var listOfShows = episodeEntitlement.Episode.GetParentShows(eCacheDuration); var parentShow = context.CategoryClasses.FirstOrDefault(c => listOfShows.Contains(c.CategoryId) && c.StatusId == GlobalConfig.Visible && c is Show); if (parentShow != null) { if (!(ShowIds.Contains(parentShow.CategoryId))) { if (!(parentShow is LiveEvent)) { if (parentShow.StartDate < registDt && parentShow.EndDate > registDt) { ShowLookUpObject data = new ShowLookUpObject(); var CacheDuration = new TimeSpan(0, GlobalConfig.GetParentCategoriesCacheDuration, 0); var parentCategories = ((Show)parentShow).GetAllParentCategories(CacheDuration); var parent = context.CategoryClasses.Where(c => parentCategories.Contains(c.CategoryId) && c.StatusId == GlobalConfig.Visible && c is Category); data.EpisodeId = episodeEntitlement.Episode.EpisodeId; data.EpisodeName = episodeEntitlement.Episode.Description + ", " + episodeEntitlement.Episode.DateAired.Value.ToString("MMMM d, yyyy"); data.Show = parentShow.Description; data.ShowId = parentShow.CategoryId; data.MainCategory = parent.First().Description; data.MainCategoryId = parent.First().CategoryId; data.ShowType = (parentShow is Movie) ? "MOVIE" : "SHOW"; if (!(parentShow is Movie)) { ShowIds.Add(parentShow.CategoryId); list.Add(data); } } } } } } } list = list.OrderBy(c => c.Show).ToList(); //cache.Put(cacheKey, list, DataCache.CacheDuration); } } } catch (Exception e) { MyUtility.LogException(e); } } return Json(list, JsonRequestBehavior.AllowGet); }
public void UnionWith () { var set = new SortedSet<int> { 1, 3, 5, 7, 9 }; set.UnionWith (new [] { 5, 7, 3, 7, 11, 7, 5, 2 }); Assert.IsTrue (set.SequenceEqual (new [] { 1, 2, 3, 5, 7, 9, 11 })); }
public void UnionWith_Null () { var set = new SortedSet<int> (); set.UnionWith (null); }
public override Outcome CheckOutcomeCore(ErrorHandler handler, int taskID = -1) { Contract.EnsuresOnThrow<UnexpectedProverOutputException>(true); var result = Outcome.Undetermined; if (Process == null) return result; try { currentErrorHandler = handler; FlushProverWarnings(); int errorLimit; if (CommandLineOptions.Clo.ConcurrentHoudini) { Contract.Assert(taskID >= 0); errorLimit = CommandLineOptions.Clo.Cho[taskID].ProverCCLimit; } else { errorLimit = CommandLineOptions.Clo.ProverCCLimit; } if (errorLimit < 1) errorLimit = 1; int errorsLeft = errorLimit; var globalResult = Outcome.Undetermined; while (true) { string[] labels = null; bool popLater = false; try { errorsLeft--; result = GetResponse(); var reporter = handler as VC.VCGen.ErrorReporter; // TODO(wuestholz): Is the reporter ever null? if (usingUnsatCore && result == Outcome.Valid && reporter != null && 0 < NamedAssumes.Count) { if (usingUnsatCore) { UsedNamedAssumes = new HashSet<string>(); SendThisVC("(get-unsat-core)"); var resp = Process.GetProverResponse(); if (resp.Name != "") { UsedNamedAssumes.Add(resp.Name); if (CommandLineOptions.Clo.PrintNecessaryAssumes) { reporter.AddNecessaryAssume(resp.Name.Substring("aux$$assume$$".Length)); } } foreach (var arg in resp.Arguments) { UsedNamedAssumes.Add(arg.Name); if (CommandLineOptions.Clo.PrintNecessaryAssumes) { reporter.AddNecessaryAssume(arg.Name.Substring("aux$$assume$$".Length)); } } } else { UsedNamedAssumes = null; } } if (CommandLineOptions.Clo.RunDiagnosticsOnTimeout && result == Outcome.TimeOut) { #region Run timeout diagnostics if (CommandLineOptions.Clo.TraceDiagnosticsOnTimeout) { Console.Out.WriteLine("Starting timeout diagnostics with initial time limit {0}.", options.TimeLimit); } SendThisVC("; begin timeout diagnostics"); var start = DateTime.UtcNow; var unverified = new SortedSet<int>(ctx.TimeoutDiagnosticIDToAssertion.Keys); var timedOut = new SortedSet<int>(); int frac = 2; int queries = 0; int timeLimitPerAssertion = 0 < options.TimeLimit ? (options.TimeLimit / 100) * CommandLineOptions.Clo.TimeLimitPerAssertionInPercent : 1000; while (true) { int rem = unverified.Count; if (rem == 0) { if (0 < timedOut.Count) { result = CheckSplit(timedOut, ref popLater, options.TimeLimit, timeLimitPerAssertion, ref queries); if (result == Outcome.Valid) { timedOut.Clear(); } else if (result == Outcome.TimeOut) { // Give up and report which assertions were not verified. var cmds = timedOut.Select(id => ctx.TimeoutDiagnosticIDToAssertion[id]); if (cmds.Any()) { handler.OnResourceExceeded("timeout after running diagnostics", cmds); } } } else { result = Outcome.Valid; } break; } // TODO(wuestholz): Try out different ways for splitting up the work (e.g., randomly). var cnt = Math.Max(1, rem / frac); // It seems like assertions later in the control flow have smaller indexes. var split = new SortedSet<int>(unverified.Where((val, idx) => (rem - idx - 1) < cnt)); Contract.Assert(0 < split.Count); var splitRes = CheckSplit(split, ref popLater, timeLimitPerAssertion, timeLimitPerAssertion, ref queries); if (splitRes == Outcome.Valid) { unverified.ExceptWith(split); frac = 1; } else if (splitRes == Outcome.Invalid) { result = splitRes; break; } else if (splitRes == Outcome.TimeOut) { if (2 <= frac && (4 <= (rem / frac))) { frac *= 4; } else if (2 <= (rem / frac)) { frac *= 2; } else { timedOut.UnionWith(split); unverified.ExceptWith(split); frac = 1; } } else { break; } } unverified.UnionWith(timedOut); var end = DateTime.UtcNow; SendThisVC("; end timeout diagnostics"); if (CommandLineOptions.Clo.TraceDiagnosticsOnTimeout) { Console.Out.WriteLine("Terminated timeout diagnostics after {0:F0} ms and {1} prover queries.", end.Subtract(start).TotalMilliseconds, queries); Console.Out.WriteLine("Outcome: {0}", result); Console.Out.WriteLine("Unverified assertions: {0} (of {1})", unverified.Count, ctx.TimeoutDiagnosticIDToAssertion.Keys.Count); string filename = "unknown"; var assertion = ctx.TimeoutDiagnosticIDToAssertion.Values.Select(t => t.Item1).FirstOrDefault(a => a.tok != null && a.tok != Token.NoToken && a.tok.filename != null); if (assertion != null) { filename = assertion.tok.filename; } File.AppendAllText("timeouts.csv", string.Format(";{0};{1};{2:F0};{3};{4};{5};{6}\n", filename, options.TimeLimit, end.Subtract(start).TotalMilliseconds, queries, result, unverified.Count, ctx.TimeoutDiagnosticIDToAssertion.Keys.Count)); } #endregion } if (globalResult == Outcome.Undetermined) globalResult = result; if (result == Outcome.Invalid || result == Outcome.TimeOut || result == Outcome.OutOfMemory) { IList<string> xlabels; if (CommandLineOptions.Clo.UseLabels) { labels = GetLabelsInfo(); if (labels == null) { xlabels = new string[] { }; } else { xlabels = labels.Select(a => a.Replace("@", "").Replace("+", "")).ToList(); } } else if(CommandLineOptions.Clo.SIBoolControlVC) { labels = new string[0]; xlabels = labels; } else { labels = CalculatePath(handler.StartingProcId()); xlabels = labels; } Model model = (result == Outcome.TimeOut || result == Outcome.OutOfMemory) ? null : GetErrorModel(); handler.OnModel(xlabels, model, result); } if (labels == null || !labels.Any() || errorsLeft == 0) break; } finally { if (popLater) { SendThisVC("(pop 1)"); } } if (CommandLineOptions.Clo.UseLabels) { var negLabels = labels.Where(l => l.StartsWith("@")).ToArray(); var posLabels = labels.Where(l => !l.StartsWith("@")); Func<string, string> lbl = (s) => SMTLibNamer.QuoteId(SMTLibNamer.LabelVar(s)); if (!options.MultiTraces) posLabels = Enumerable.Empty<string>(); var conjuncts = posLabels.Select(s => "(not " + lbl(s) + ")").Concat(negLabels.Select(lbl)).ToArray(); string expr = conjuncts.Length == 1 ? conjuncts[0] : ("(or " + conjuncts.Concat(" ") + ")"); ; if (!conjuncts.Any()) { expr = "false"; } SendThisVC("(assert " + expr + ")"); SendCheckSat(); } else { string source = labels[labels.Length - 2]; string target = labels[labels.Length - 1]; SendThisVC("(assert (not (= (ControlFlow 0 " + source + ") (- " + target + "))))"); SendCheckSat(); } } FlushLogFile(); if (CommandLineOptions.Clo.RestartProverPerVC && Process != null) Process.NeedsRestart = true; return globalResult; } finally { currentErrorHandler = null; } }
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 }