Beispiel #1
0
        public SortedSet<Package> GetPackages(Offering offering, String countryCode, RightsType rightsType)
        {
            var packages = new SortedSet<Package>();

            foreach (var p in offering.PackageSubscriptionProducts)
            {
                if (p.IsAllowed(countryCode))
                {
                    foreach (var package in p.Packages)
                    {
                        bool isInPackage = false;
                        switch (rightsType)
                        {
                            case RightsType.IPTV:
                                isInPackage = package.Package.GetAllIptvShowIds(countryCode).Contains(CategoryId);
                                break;
                            case RightsType.Online:
                                isInPackage = package.Package.GetAllOnlineShowIds(countryCode).Contains(CategoryId);
                                break;
                            case RightsType.Mobile:
                                isInPackage = package.Package.GetAllMobileShowIds(countryCode).Contains(CategoryId);
                                break;
                            default:
                                throw new Exception("Invalid RightsType.");
                        }
                        if (isInPackage && package.Package is Package)
                        {
                            packages.Add((Package)package.Package);
                        }
                    }
                }

            }
            return (packages.Count > 0 ? packages : null);
        }
Beispiel #2
0
        public SortedSet<int> GetShowProductIds(Offering offering, String countryCode, RightsType rightsType, bool useCache)
        {
            SortedSet<int> showProductList = null;
            var cache = DataCache.Cache;
            var cacheKey = GetShowProductIdsCacheKey(offering.OfferingId, countryCode, rightsType);
            if (useCache)
            {
                showProductList = (SortedSet<int>)cache[cacheKey];
            }
            if (showProductList == null)
            {
                showProductList = new SortedSet<int>();
                var showProducts = GetShowProducts(offering, countryCode, rightsType);
                if (showProducts != null)
                    foreach (var showProduct in showProducts)
                    {
                        showProductList.Add(showProduct.ProductId);
                    }
                showProductList = showProductList.Count > 0 ? showProductList : null;

                if (useCache && showProductList != null)
                {
                    cache.Put(cacheKey, showProductList, DataCache.CacheDuration);
                }

            }
            return showProductList;
        }
Beispiel #3
0
 public SortedSet<int> GetShowProductIds(Offering offering, String countryCode, RightsType rightsType)
 {
     return GetShowProductIds(offering, countryCode, rightsType, true);
 }
Beispiel #4
0
        public SortedSet<int> GetPackageProductIds(Offering offering, String countryCode, RightsType rightsType, bool useCache)
        {
            SortedSet<int> packageProductList = null;
            var cache = DataCache.Cache;
            var cacheKey = GetPackageProductIdsCacheKey(offering.OfferingId, countryCode, rightsType);
            if (useCache)
            {
                packageProductList = (SortedSet<int>)cache[cacheKey];
            }
            if (packageProductList == null)
            {
                packageProductList = new SortedSet<int>();
                var packageProducts = GetPackageProducts(offering, countryCode, rightsType);
                if (packageProducts != null)
                {
                    foreach (var packageProduct in packageProducts)
                    {
                        packageProductList.Add(packageProduct.ProductId);
                    }
                }
                packageProductList = packageProductList.Count > 0 ? packageProductList : null;

                if (useCache && packageProductList != null)
                {
                    cache.Put(cacheKey, packageProductList, DataCache.CacheDuration);
                }

            }

            return packageProductList;
        }
        private RecurringBillingReturnValue CheckIfUserIsEnrolledToSameRecurringProductGroup(IPTV2Entities context, Offering offering, User user, Product product)
        {
            RecurringBillingReturnValue returnValue = new RecurringBillingReturnValue()
            {
                container = null,
                value = false
            };
            var profiler = MiniProfiler.Current;
            using (profiler.Step("Check Recurring Enrolment"))
            {
                try
                {

                    if (product is SubscriptionProduct)
                    {
                        // check if user is part of recurring
                        var subscriptionProduct = (SubscriptionProduct)product;
                        //Get user's recurring productGroups
                        var recurringProductGroups = user.GetRecurringProductGroups(offering);
                        if (recurringProductGroups.Contains(subscriptionProduct.ProductGroup))
                        {
                            var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId);
                            if (productPackage != null)
                            {
                                var entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == productPackage.PackageId);
                                if (entitlement != null)
                                {
                                    var container = new RecurringBillingContainer()
                                    {
                                        user = user,
                                        product = product,
                                        entitlement = entitlement,
                                        package = (Package)productPackage.Package
                                    };
                                    returnValue.value = true;
                                    returnValue.container = container;
                                }
                            }
                        }
                    }
                }
                catch (Exception e) { MyUtility.LogException(e); }
            }
            return returnValue;
        }
        public static CheckSubscriptionReturnObject HasActiveSubscriptionBasedOnProducts(IPTV2Entities context, User user, Offering offering, Product product)
        {
            var returnObject = new CheckSubscriptionReturnObject() { HasSubscription = false, Within5DaysOrLess = false };
            try
            {
                var subProducts = user.GetSubscribedProducts(offering);
                if (product != null)
                {
                    if (product is SubscriptionProduct)
                    {
                        if (product is PackageSubscriptionProduct)
                        {
                            var packageProduct = (PackageSubscriptionProduct)product;
                            returnObject.SubscriptionEndDate = user.PackageEntitlements.FirstOrDefault(u => u.PackageId == packageProduct.Packages.First().PackageId).EndDate;
                        }
                        else if (product is ShowSubscriptionProduct)
                        {
                            var showProduct = (ShowSubscriptionProduct)product;
                            returnObject.SubscriptionEndDate = user.ShowEntitlements.FirstOrDefault(u => u.CategoryId == showProduct.Categories.First().CategoryId).EndDate;
                        }
                        returnObject.HasSubscription = subProducts.Select(s => s.ProductId).Contains(product.ProductId);
                    }
                }

            }
            catch (Exception e) { MyUtility.LogException(e); }
            return returnObject;
        }
Beispiel #7
0
        public void ProcessAllPendingTransactionsInGoms(IPTV2Entities context, Offering offering, User user)
        {
            string transactiontype = String.Empty;
            bool errorOccured = false; //added var errorOccured to force termination of loop if error occurs.
            var transactions = context.Transactions.Where(t => (t.GomsTransactionId == null || t.GomsTransactionId == 0) && t.OfferingId == offering.OfferingId && t.UserId == user.UserId).OrderBy(t => t.TransactionId).ToList();
            foreach (var t in transactions)
            {
                Console.WriteLine("Processing transaction:" + t.TransactionId.ToString() + " for " + t.User.EMail);
                try
                {
                    if (t is ReloadTransaction)
                    {
                        transactiontype = "Reload";
                        ProcessReloadTransactionInGoms(context, (ReloadTransaction)t);
                    }
                    else if (t is PaymentTransaction)
                    {
                        transactiontype = "Payment";
                        ProcessPaymentTransactionInGoms(context, (PaymentTransaction)t);
                    }
                    else if (t is UpgradeTransaction)
                    {
                        transactiontype = "Upgrade";
                        ProcessUpgradeTransactionInGoms(context, (UpgradeTransaction)t);
                    }
                    else if (t is MigrationTransaction)
                    {
                        transactiontype = "Migration";
                        ProcessMigrationTransactionInGoms(context, (MigrationTransaction)t);
                    }
                    else if (t is ChangeCountryTransaction)
                    {
                        transactiontype = "ChangeCountry";
                        ProcessChangeCountryTransactionInGoms(context, (ChangeCountryTransaction)t);
                    }
                    else if (t is RegistrationTransaction)
                    {
                        transactiontype = "Registration";
                        ProcessRegistrationTransactionInGoms(context, (RegistrationTransaction)t);
                    }
                    else
                    {
                        throw new Exception("Invalid transaction.");
                    }
                }
                catch (EntityCommandExecutionException) { throw; }
                catch (Exception e)
                {
                    var message = e.Message;
                    if (e is GomsException)
                        message = ((GomsException)e).StatusMessage;

                    // TODO: exception processing, put in error digest
                    Console.WriteLine(String.Format("{0}: {1}", transactiontype, message));
                    // update GomsRemarks in transaction
                    try
                    {
                        t.GomsRemarks = message;
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error in saving GomsRemarks:" + ex.Message);
                    }
                    errorOccured = true;
                }
                if (errorOccured) break;
            }
        }
Beispiel #8
0
 public SortedSet<ShowSubscriptionProduct> GetIptvShowProducts(Offering offering, String countryCode)
 {
     return GetShowProducts(offering, countryCode, RightsType.IPTV);
 }
 public static bool HasEnrolledCreditCard(Offering offering, User user)
 {
     return user.CreditCards.Count(c => c.StatusId == GlobalConfig.Visible && c.OfferingId == offering.OfferingId) > 0;
 }
Beispiel #10
0
 public static bool EnrollCreditCard(IPTV2Entities context, Offering offering, User user, DateTime registDt, CreditCardInfo info)
 {
     var retVal = false;
     if (GlobalConfig.IsRecurringBillingEnabled)
     {
         var CreditCardHash = MyUtility.GetSHA1(info.Number);
         if (user.CreditCards.Count(c => c.CreditCardHash == CreditCardHash && c.StatusId == GlobalConfig.Visible && c.OfferingId == offering.OfferingId) > 0)
         {
             // there is an active credit card attached to user
         }
         else
         {
             var paymentMethod = context.GomsPaymentMethods.FirstOrDefault(p => (p.GomsSubsidiaryId == user.GomsSubsidiaryId) && (p.Name == info.CardTypeString));
             if (paymentMethod != null)
             {
                 var creditCard = new IPTV2_Model.CreditCard()
                 {
                     CreditCardHash = CreditCardHash,
                     StatusId = GlobalConfig.Visible,
                     User = user,
                     Offering = offering,
                     LastDigits = info.Number.Right(4),
                     CreatedOn = registDt,
                     UpdatedOn = registDt,
                     GomsPaymentMethod = paymentMethod,
                     CardType = info.CardType.ToString().Replace("_", " ").ToUpper()
                 };
                 context.CreditCards.Add(creditCard);
                 if (context.SaveChanges() > 0)
                     retVal = true;
             }
         }
     }
     return retVal;
 }
Beispiel #11
0
        public static void AddToRecurringBilling(IPTV2Entities context, Product product, Offering offering, User user, DateTime registDt, CreditCardInfo info)
        {
            //Check if product is subscription product
            if (product is SubscriptionProduct)
            {
                //check if there are any recurring products that have the same productgroup
                SubscriptionProduct subscriptionProduct = (SubscriptionProduct)product;

                //Get user's recurring productGroups
                var recurringProductGroups = user.GetRecurringProductGroups(offering);
                if (!recurringProductGroups.Contains(subscriptionProduct.ProductGroup))
                {
                    var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId);
                    if (productPackage != null)
                    {
                        var entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == productPackage.PackageId);
                        if (entitlement != null)
                        {
                            var billing = new CreditCardRecurringBilling()
                            {
                                CreatedOn = registDt,
                                Product = product,
                                User = user,
                                UpdatedOn = registDt,
                                EndDate = entitlement.EndDate,
                                NextRun = entitlement.EndDate.AddDays(-3).Date, // Run day before expiry
                                StatusId = GlobalConfig.Visible,
                                Offering = offering,
                                Package = (Package)productPackage.Package,
                                CreditCardHash = MyUtility.GetSHA1(info.Number),
                                NumberOfAttempts = 0
                            };
                            context.RecurringBillings.Add(billing);
                            context.SaveChanges();
                        }
                    }
                }
            }
        }
Beispiel #12
0
        public static string GetCurrentSubscribeProduct(IPTV2Entities context, Product product, System.Guid userId, Offering offering)
        {
            if (product is SubscriptionProduct)
            {
                SubscriptionProduct sproduct = (SubscriptionProduct)product;
                User user = context.Users.FirstOrDefault(u => u.UserId == userId);
                var subscribedproducts = user.GetSubscribedProductGroups(offering);
                foreach (var item in subscribedproducts)
                {
                    return item.Name;
                    //if (item.ProductGroup.UpgradeableFromProductGroups().Contains(sproduct.ProductGroup))
                    //{
                    //    //Product CurrentProduct = context.Products.FirstOrDefault(p => p.ProductId == item.ProductId);
                    //    //return CurrentProduct.Name;
                    //    return item.Name;
                    //}
                }
            }

            return String.Empty;
        }
Beispiel #13
0
        public static bool CanPlayVideo(IPTV2Entities context, Offering offering, Episode episode, Asset asset, System.Security.Principal.IPrincipal thisUser, HttpRequestBase req)
        {
            bool IsUserEntitled = false;

            var profiler = MiniProfiler.Current;

            using (profiler.Step("ContextHelper.CanPlayVideo"))
            {
                string CountryCode = GlobalConfig.DefaultCountry;
                try
                {
                    CountryCode = MyUtility.getCountry(req.GetUserHostAddressFromCloudflare()).getCode();
                }
                catch (Exception) { }

                var packageId = GlobalConfig.AnonymousDefaultPackageId;

                if (!IsUserEntitled)
                    IsUserEntitled = User.IsAssetEntitled(context, offering.OfferingId, packageId, episode.EpisodeId, asset.AssetId, CountryCode, RightsType.Online);
                else
                    IsUserEntitled = true;

                // check user's access rights
                if (!IsUserEntitled && thisUser.Identity.IsAuthenticated)
                {
                    var user = context.Users.FirstOrDefault(u => u.UserId == new System.Guid(thisUser.Identity.Name));
                    if (user != null)
                    {
                        // check access from default logged in user package
                        packageId = GlobalConfig.LoggedInDefaultPackageId;
                        IsUserEntitled = User.IsAssetEntitled(context, offering.OfferingId, packageId, episode.EpisodeId, asset.AssetId, user.CountryCode, RightsType.Online);

                        if (!IsUserEntitled)
                        {
                            if (GlobalConfig.IsTVERegionBlockingEnabled)
                            {
                                var userCountryCode = MyUtility.GetCountryCodeViaIp();
                                int GomsSubsidiaryId = 0;
                                if (GlobalConfig.UseGomsSubsidiaryForTVECheck)
                                    GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
                                else
                                    GomsSubsidiaryId = -1;
                                //var GomsSubsidiaryId = ContextHelper.GetGomsSubsidiaryIdOfCountry(context, userCountryCode);
                                //IsUserEntitled = user.CanPlayVideo(offering, episode, asset, RightsType.Online); // check if user has entitlements that can play the video
                                var IncludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayIncludedPackageIds);
                                var ExcludePackageIds = MyUtility.StringToIntList(GlobalConfig.CanPlayExcludedPackageIds);
                                IsUserEntitled = user.CanPlayVideo(offering, episode, asset, RightsType.Online, ExcludePackageIds, IncludePackageIds, userCountryCode, GomsSubsidiaryId);
                                if (GlobalConfig.IsTVEIpCheckEnabled)
                                {
                                    try
                                    {
                                        string ip = GlobalConfig.IpWhiteList;
                                        string[] IpAddresses = ip.Split(';');
                                        if (IpAddresses.Contains(req.GetUserHostAddressFromCloudflare()))
                                            IsUserEntitled = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
                                    }
                                    catch (Exception e) { MyUtility.LogException(e, "ContextHelper IsUserEntitled IP Whitelisting"); }
                                }
                            }
                            else
                                IsUserEntitled = user.CanPlayVideo(offering, episode, asset, RightsType.Online);
                        }
                        else
                            IsUserEntitled = true;
                    }
                }
            }

            ////Check for subclips
            //int snippetStart = 0;
            //int snippetEnd = 0;
            //AkamaiFlowPlayerPluginClipDetails clipDetails = null;

            //if (!IsUserEntitled)
            //{
            //    if ((asset.SnippetStart != null) && (asset.SnippetEnd != null) && (asset.SnippetEnd > asset.SnippetStart))
            //    {
            //        snippetStart = Convert.ToInt32(asset.SnippetStart.Value.TotalSeconds);
            //        snippetEnd = Convert.ToInt32(asset.SnippetEnd.Value.TotalSeconds);
            //    }
            //    else
            //    {
            //        snippetStart = 0;
            //        snippetEnd = GlobalConfig.snippetEnd;
            //    }
            //    clipDetails.PromptToSubscribe = true;
            //}
            //else
            //    clipDetails.PromptToSubscribe = false;

            //clipDetails.SubClip = (snippetStart + snippetEnd > 0) ? new SubClip { Start = snippetStart, End = snippetEnd } : null;
            //if (clipDetails.SubClip != null)
            //    IsUserEntitled = false;
            //else
            //    IsUserEntitled = true;

            return IsUserEntitled;
        }
Beispiel #14
0
 public static bool IsProductPurchaseable(IPTV2Entities context, Product product, User user, Offering offering)
 {
     PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product;
     var subscribedProducts = user.GetSubscribedProductGroups(offering);
     foreach (var item in subscribedProducts)
     {
         //checks if product to be bought and subscribed product belong to the same group
         if (item.ProductGroupId != subscription.ProductGroupId) //does not belong to same group
         {
             if (item.UpgradeableFromProductGroups().Contains(subscription.ProductGroup))
                 return false;
         }
     }
     return true;
 }
Beispiel #15
0
 public SortedSet<PackageSubscriptionProduct> GetIptvPackageProducts(Offering offering, String countryCode)
 {
     return GetPackageProducts(offering, countryCode, RightsType.IPTV);
 }
Beispiel #16
0
        public SortedSet<ShowSubscriptionProduct> GetShowProducts(Offering offering, String countryCode, RightsType rightsType)
        {
            var products = new SortedSet<ShowSubscriptionProduct>();

            if (StatusId == 1)
            {
                bool isAllowed = false;
                switch (rightsType)
                {
                    case RightsType.IPTV:
                        isAllowed = IsIptvAllowed(countryCode);
                        break;
                    case RightsType.Mobile:
                        isAllowed = IsMobileAllowed(countryCode);
                        break;
                    case RightsType.Online:
                        isAllowed = IsOnlineAllowed(countryCode);
                        break;
                    default:
                        throw new Exception("Invalid rightsType.");
                }
                if (isAllowed)
                {
                    var productShows = Products.Where(p => (p.Product.OfferingId == offering.OfferingId) && (p.Product.StatusId == 1));
                    foreach (var p in productShows)
                    {
                        products.Add(p.Product);
                    }
                }
            }

            return (products.Count > 0 ? products : null);

        }
Beispiel #17
0
        public static void AddToPaypalRecurringBilling(IPTV2Entities context, Product product, Offering offering, User user, DateTime registDt, string subscr_id, bool IsRecurringSignUp = false, int TrialProductId = 0)
        {
            try
            {
                //Check if product is subscription product
                if (product is SubscriptionProduct)
                {
                    //check if there are any recurring products that have the same productgroup
                    SubscriptionProduct subscriptionProduct = (SubscriptionProduct)product;

                    //Get user's recurring productGroups
                    var recurringProductGroups = user.GetRecurringProductGroups(offering);
                    if (!recurringProductGroups.Contains(subscriptionProduct.ProductGroup))
                    {
                        var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId);
                        if (productPackage != null)
                        {
                            var entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == productPackage.PackageId);
                            if (entitlement != null)
                            {
                                var paypalRecurringBilling = user.RecurringBillings.FirstOrDefault(r => r is PaypalRecurringBilling && r.StatusId == GlobalConfig.Visible && String.Compare(((PaypalRecurringBilling)r).SubscriberId, subscr_id, true) == 0);
                                if (paypalRecurringBilling == null)
                                {
                                    var billing = new PaypalRecurringBilling()
                                    {
                                        CreatedOn = registDt,
                                        Product = product,
                                        User = user,
                                        UpdatedOn = registDt,
                                        EndDate = entitlement.EndDate,
                                        //NextRun = entitlement.EndDate.AddDays(-3).Date, // Run day before expiry
                                        NextRun = entitlement.EndDate.Date,
                                        StatusId = GlobalConfig.Visible,
                                        Offering = offering,
                                        Package = (Package)productPackage.Package,
                                        SubscriberId = subscr_id,
                                        NumberOfAttempts = 0
                                    };
                                    context.RecurringBillings.Add(billing);
                                }
                                else
                                {
                                    if (paypalRecurringBilling.Product != null)
                                    {
                                        var recurringProduct = paypalRecurringBilling.Product;
                                        if (recurringProduct is SubscriptionProduct)
                                        {
                                            var recurringSubscriptionProduct = (SubscriptionProduct)recurringProduct;
                                            paypalRecurringBilling.NextRun = MyUtility.getEntitlementEndDate(recurringSubscriptionProduct.Duration, recurringSubscriptionProduct.DurationType, paypalRecurringBilling.NextRun != null ? (DateTime)paypalRecurringBilling.NextRun : registDt.Date);
                                            paypalRecurringBilling.UpdatedOn = DateTime.Now;
                                        }
                                    }
                                }
                                context.SaveChanges();
                            }
                            else
                            {
                                if (IsRecurringSignUp)
                                {
                                    // get  trial product
                                    var trialProduct = context.Products.FirstOrDefault(p => p.ProductId == TrialProductId);
                                    SubscriptionProduct trialSubscriptionProduct = (SubscriptionProduct)trialProduct;
                                    var billing = new PaypalRecurringBilling()
                                    {
                                        CreatedOn = registDt,
                                        Product = product,
                                        User = user,
                                        UpdatedOn = registDt,
                                        //NextRun = entitlement.EndDate.AddDays(-3).Date, // Run day before expiry                                    
                                        EndDate = MyUtility.getEntitlementEndDate(trialSubscriptionProduct.Duration, trialSubscriptionProduct.DurationType, registDt),
                                        NextRun = MyUtility.getEntitlementEndDate(trialSubscriptionProduct.Duration, trialSubscriptionProduct.DurationType, registDt),
                                        StatusId = GlobalConfig.Visible,
                                        Offering = offering,
                                        Package = (Package)productPackage.Package,
                                        SubscriberId = subscr_id,
                                        NumberOfAttempts = 0
                                    };
                                    context.RecurringBillings.Add(billing);
                                    context.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) { MyUtility.LogException(e); }
        }
Beispiel #18
0
        public SortedSet<PackageSubscriptionProduct> GetPackageProducts(Offering offering, String countryCode, RightsType rightsType, bool useCache, TimeSpan cacheDuration)
        {
            var products = new SortedSet<PackageSubscriptionProduct>();

            foreach (var p in offering.PackageSubscriptionProducts)
            {
                if (p.IsAllowed(countryCode))
                {
                    foreach (var package in p.Packages)
                    {
                        bool isInPackage = false;
                        switch (rightsType)
                        {
                            case RightsType.IPTV:
                                isInPackage = package.Package.GetAllChannelIds(countryCode, RightsType.IPTV, useCache, cacheDuration).Contains(ChannelId);
                                break;
                            case RightsType.Online:
                                isInPackage = package.Package.GetAllChannelIds(countryCode, RightsType.Online, useCache, cacheDuration).Contains(ChannelId);
                                break;
                            case RightsType.Mobile:
                                isInPackage = package.Package.GetAllChannelIds(countryCode, RightsType.Mobile, useCache, cacheDuration).Contains(ChannelId);
                                break;
                            default:
                                throw new Exception("Invalid RightsType.");
                        }
                        if (isInPackage)
                        {
                            products.Add(p);
                        }
                    }
                }

            }

            return (products.Count > 0 ? products : null);

        }
Beispiel #19
0
 public SortedSet<int> GetPackageProductIds(Offering offering, String countryCode, RightsType rightsType, bool useCache)
 {
     return GetPackageProductIds(offering, countryCode, rightsType, useCache, DataCache.CacheDuration);
 }
Beispiel #20
0
        public void ProcessSinglePendingTransactionInGoms(IPTV2Entities context, Offering offering, int transactionId)
        {
            var transtype = String.Empty;
            // var transactions = context.Transactions.Where(t => (t.GomsTransactionId == null || t.GomsTransactionId == 0) && t.OfferingId == offering.OfferingId).OrderBy(t => t.TransactionId).ToList();
            var transactions = context.Transactions.Where(t => (t.GomsTransactionId == null || t.GomsTransactionId == 0) && t.TransactionId == transactionId && t.OfferingId == offering.OfferingId).OrderBy(t => t.TransactionId).ToList();
            foreach (var t in transactions)
            {
                Console.WriteLine("Processing transaction:" + t.TransactionId.ToString() + " for " + t.User.EMail);
                try
                {
                    if (t is ReloadTransaction)
                    {
                        transtype = "Reload";
                        ProcessReloadTransactionInGoms(context, (ReloadTransaction)t);
                    }
                    else if (t is PaymentTransaction)
                    {
                        transtype = "Payment";
                        ProcessPaymentTransactionInGoms(context, (PaymentTransaction)t);
                    }
                    else if (t is UpgradeTransaction)
                    {
                        transtype = "Upgrade";
                        ProcessUpgradeTransactionInGoms(context, (UpgradeTransaction)t);
                    }
                    else if (t is MigrationTransaction)
                    {
                        transtype = "Migration";
                        ProcessMigrationTransactionInGoms(context, (MigrationTransaction)t);
                    }
                    else if (t is ChangeCountryTransaction)
                    {
                        transtype = "ChangeCountry";
                        ProcessChangeCountryTransactionInGoms(context, (ChangeCountryTransaction)t);
                    }
                    else if (t is RegistrationTransaction)
                    {
                        transtype = "Registration";
                        ProcessRegistrationTransactionInGoms(context, (RegistrationTransaction)t);
                    }
                    else
                    {
                        throw new Exception("Invalid transaction.");
                    }

                    Console.WriteLine(String.Format("Processing {0} transaction for email {1}...", transtype, t.User.EMail));
                }
                catch (Exception e)
                {
                    var message = e.Message;
                    if (e is GomsException)
                        message = ((GomsException)e).StatusMessage;

                    // TODO: exception processing, put in error digest
                    Console.WriteLine(String.Format("{0}{1}: {2} {3}", t.TransactionId, transtype, t.User.EMail, message));
                    // update GomsRemarks in transaction
                    try
                    {
                        t.GomsRemarks = message;
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error in saving GomsRemarks:" + ex.Message);
                    }
                }
            }
        }
Beispiel #21
0
 public static IEnumerable<int> GetAllShowsBasedOnCountryCode(IPTV2Entities context, string CountryCode, bool addExclusion = false, Offering offering = null, Service service = null, Category category = null)
 {
     SortedSet<int> list = null;
     try
     {
         if (offering == null)
             offering = context.Offerings.Find(GlobalConfig.offeringId);
         if (service == null)
             service = offering.Services.FirstOrDefault(s => s.PackageId == GlobalConfig.serviceId);
         if (category != null)
             list = service.GetAllOnlineShowIds(CountryCode, category);
         else
             list = service.GetAllOnlineShowIds(CountryCode);
         if (addExclusion)
         {
             if (list != null)
             {
                 var excludedCategoryIds = MyUtility.StringToIntList(GlobalConfig.ExcludedCategoryIdsForDisplay);
                 var result = list.Except(excludedCategoryIds);
                 return result;
             }
         }
         if (list != null)
             return list.ToList();
     }
     catch (Exception) { }
     return null;
 }