Пример #1
0
        private static void AddTfcEverywhereEntitlement(IPTV2Entities context, int GomsProductId, string expiryDate, int serviceId, User user, int GomsTransactionId = 0)
        {
            DateTime registDt = DateTime.Now;
            var product = context.Products.FirstOrDefault(p => p.GomsProductId == GomsProductId && p.GomsProductQuantity == 1);
            if (product != null)
            {
                ProductPrice productPrice;
                try
                {
                    productPrice = product.ProductPrices.FirstOrDefault(i => i.CurrencyCode == user.Country.CurrencyCode);
                }
                catch (Exception)
                {
                    productPrice = product.ProductPrices.FirstOrDefault(i => i.CurrencyCode == GlobalConfig.DefaultCurrency);
                }

                //Create Purchase
                Purchase purchase = ContextHelper.CreatePurchase(registDt, "TFC Everywhere");
                //Create Purchase Item
                PurchaseItem purchaseItem = ContextHelper.CreatePurchaseItem(user.UserId, product, productPrice);

                var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId);
                //Create Entitlement & EntitlementRequest
                Entitlement entitlement = user.PackageEntitlements.FirstOrDefault(i => i.PackageId == productPackage.PackageId);

                user.Purchases.Add(purchase);
                user.PurchaseItems.Add(purchaseItem);


                if (entitlement != null)
                {
                    entitlement.EndDate = Convert.ToDateTime(expiryDate);
                    EntitlementRequest request = new EntitlementRequest()
                    {
                        DateRequested = registDt,
                        StartDate = registDt,
                        EndDate = entitlement.EndDate,
                        Product = productPackage.Product,
                        Source = "TFC Everywhere",
                        ReferenceId = GomsTransactionId.ToString()
                    };
                    user.EntitlementRequests.Add(request);
                    entitlement.LatestEntitlementRequest = request;
                    purchaseItem.EntitlementRequest = request;
                }
                else
                {
                    EntitlementRequest request = new EntitlementRequest()
                    {
                        DateRequested = registDt,
                        StartDate = registDt,
                        EndDate = Convert.ToDateTime(expiryDate),
                        Product = productPackage.Product,
                        Source = "TFC Everywhere",
                        ReferenceId = GomsTransactionId.ToString()
                    };

                    PackageEntitlement pkg_entitlement = new PackageEntitlement()
                    {
                        EndDate = Convert.ToDateTime(expiryDate),
                        Package = (IPTV2_Model.Package)productPackage.Package,
                        OfferingId = GlobalConfig.offeringId,
                        LatestEntitlementRequest = request
                    };

                    user.PackageEntitlements.Add(pkg_entitlement);
                    user.EntitlementRequests.Add(request);
                    purchaseItem.EntitlementRequest = request;
                }
            }
        }
Пример #2
0
 private static PackageEntitlement CreatePackageEntitlement(EntitlementRequest request, PackageSubscriptionProduct subscription, ProductPackage package, DateTime registDt)
 {
     var currentDt = registDt;
     if (subscription.BreakingDate != null)
         registDt = (DateTime)subscription.BreakingDate > currentDt ? (DateTime)subscription.BreakingDate : currentDt;
     PackageEntitlement entitlement = new PackageEntitlement()
     {
         EndDate = MyUtility.getEntitlementEndDate(subscription.Duration, subscription.DurationType, registDt),
         Package = (Package)package.Package,
         OfferingId = GlobalConfig.offeringId,
         LatestEntitlementRequest = request
     };
     return entitlement;
 }
Пример #3
0
 private static PackageEntitlement CreatePackageEntitlement(EntitlementRequest request, PackageSubscriptionProduct subscription, ProductPackage package, DateTime registDt)
 {
     PackageEntitlement entitlement = new PackageEntitlement()
     {
         EndDate = GetEntitlementEndDate(subscription.Duration, subscription.DurationType, registDt),
         Package = (Package)package.Package,
         OfferingId = offeringId,
         LatestEntitlementRequest = request
     };
     return entitlement;
 }
Пример #4
0
        private static bool Upgrade(IPTV2Entities context, System.Guid userId, Product product, System.Guid recipientUserId, int? cpId)
        {
            if (userId == recipientUserId)
            {
                if (product is PackageSubscriptionProduct)
                {
                    PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product;

                    DateTime registDt = DateTime.Now;
                    User user = context.Users.FirstOrDefault(u => u.UserId == new Guid(HttpContext.Current.User.Identity.Name));
                    string CurrencyCode = MyUtility.GetCurrencyOrDefault(user.Country != null ? user.Country.Code : GlobalConfig.DefaultCountry);
                    var offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId);
                    var currentSubscription = user.GetSubscribedProducts(offering).FirstOrDefault(s => s.ProductId == cpId);
                    if (currentSubscription == null)
                        return false;

                    //Check if its upgrade to the product being bought
                    if (currentSubscription.ProductGroup.UpgradeableToProductGroups().Contains(subscription.ProductGroup))
                    {
                        //if true, deactivate the package based on product

                        //Get all product Id inside the current subscription
                        var list = currentSubscription.ProductGroup.SubscriptionProducts.Select(e => e.ProductId);

                        //Get the Packagea
                        var productPackage = context.ProductPackages.FirstOrDefault(p => list.Contains(p.ProductId));

                        //Get Package Entitlement based on the Package Id
                        var packageEntitlement = user.PackageEntitlements.Where(e => e.PackageId == productPackage.PackageId);
                        foreach (var entitlement in packageEntitlement)
                        {
                            //Compute for remaining days.
                            var remainingDaysToBeAdded = GetEquivalentPremiumDuration(context, CurrencyCode, entitlement);
                            //Deactivate the package
                            DateTime originalExpirationDate = entitlement.EndDate;
                            entitlement.EndDate = registDt;

                            //DateTime newExpirationDate = MyUtility.getEntitlementEndDate((int)remainingDaysToBeAdded, "d", registDt);
                            DateTime newExpirationDate = MyUtility.getEntitlementEndDate((int)remainingDaysToBeAdded, "d", GetPackageEndDateIfAvailable(user, subscription, registDt));

                            //Create an UpgradeTransaction
                            UpgradeTransaction transaction = CreateUpgradeTransaction(originalExpirationDate, currentSubscription.ProductId, newExpirationDate, product.ProductId, CurrencyCode, registDt);
                            user.Transactions.Add(transaction);

                            //Add the new package

                            foreach (var package in subscription.Packages)
                            {
                                PackageEntitlement currentPackage = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == package.PackageId);

                                EntitlementRequest request = new EntitlementRequest()
                                {
                                    DateRequested = registDt,
                                    EndDate = newExpirationDate,
                                    Product = product,
                                    Source = "SUBSCRIPTION UPGRADE",
                                    ReferenceId = "SUBSCRIPTION UPGRADE"
                                };

                                if (currentPackage != null)
                                {
                                    currentPackage.LatestEntitlementRequest = request;
                                    currentPackage.EndDate = newExpirationDate;
                                    request.EndDate = newExpirationDate;
                                }
                                else
                                {
                                    PackageEntitlement pkgEntitlement = new PackageEntitlement()
                                    {
                                        EndDate = newExpirationDate,
                                        Package = (Package)package.Package,
                                        OfferingId = GlobalConfig.offeringId,
                                        LatestEntitlementRequest = request
                                    };

                                    request.EndDate = pkgEntitlement.EndDate;
                                    user.PackageEntitlements.Add(pkgEntitlement);
                                }

                                user.EntitlementRequests.Add(request);
                            }
                        }
                    }

                    if (context.SaveChanges() > 0)
                        return true;
                }
                return false;
            }
            return false;
        }
Пример #5
0
        private static decimal GetEquivalentPremiumDuration(IPTV2Entities context, string CurrenyCode, PackageEntitlement entitlement)
        {
            DateTime registDt = DateTime.Now;
            if (entitlement != null)
            {
                //Get remaining hours of current LITE subscription (LD)
                var remainingTs = entitlement.EndDate.Subtract(registDt);
                var remainingDuration = remainingTs.Hours;
                remainingDuration = remainingTs.Days;

                //Get price of 1 month LITE subscription (1ML)
                var Lite1Month = context.ProductPackages.FirstOrDefault(p => p.PackageId == GlobalConfig.LitePackageId && p.Product.OfferingId == GlobalConfig.offeringId && p.Product.Duration == 1 && p.Product.DurationType == "m");
                if (Lite1Month == null)
                    return 0;

                var LiteProductPrice = Lite1Month.Product.ProductPrices.FirstOrDefault(p => p.CurrencyCode == CurrenyCode);
                if (LiteProductPrice == null)
                    return 0;

                //Lite Daily Rate (LDR)
                var LiteDailyRate = LiteProductPrice.Amount / 30;

                //Balance in Currency (BIC) = LDR * LD
                var BalanceInCurrency = LiteDailyRate * remainingDuration;

                //Get price of 1 month PREMIUM (1MP)
                var Premium1Month = context.ProductPackages.FirstOrDefault(p => p.PackageId == GlobalConfig.PremiumPackageId && p.Product.OfferingId == GlobalConfig.offeringId && p.Product.Duration == 1 && p.Product.DurationType == "m");
                if (Premium1Month == null)
                    return 0;

                var PremiumProductPrice = Premium1Month.Product.ProductPrices.FirstOrDefault(p => p.CurrencyCode == CurrenyCode);
                if (PremiumProductPrice == null)
                    return 0;

                //Premium Daily Rate (PDR)
                var PremiumDailyRate = PremiumProductPrice.Amount / 30;

                //Equivalent Premium Duration
                return BalanceInCurrency / PremiumDailyRate;
            }
            return 0;
        }
Пример #6
0
 private static PackageEntitlement CreatePackageEntitlement(EntitlementRequest request, PackageSubscriptionProduct subscription, ProductPackage package, DateTime endDate, int offeringId)
 {
     PackageEntitlement entitlement = new PackageEntitlement()
     {
         EndDate = endDate,
         Package = (IPTV2_Model.Package)package.Package,
         OfferingId = offeringId,
         LatestEntitlementRequest = request
     };
     return entitlement;
 }
Пример #7
0
        public TFCtvResponse CreateTFCtvEverywhereEntitlement(ReqCreateTFCtvEverywhereEntitlement req)
        {
            TFCtvResponse resp = null;
            DateTime registDt = DateTime.Now;
            string ip = ConfigurationManager.AppSettings["IpWhiteList"];
            string[] IpAddresses = ip.Split(';');
            bool isWhitelisted = IpAddresses.Contains(HttpContext.Current.Request.UserHostAddress);
            if (!isWhitelisted)
            {
                resp = new TFCtvResponse() { Code = -3001, Message = "Ip address is unauthorized." }; return resp;
            }

            if (!HttpContext.Current.Request.IsLocal)
            {
                //Check SoapHeader
                if (Credentials.Username.ToLower() != SoapHeaderUsername || Credentials.Password != SoapHeaderPassword)
                { resp = new TFCtvResponse() { Code = -3002, Message = "Call is unauthorized." }; return resp; }
            }

            if (req == null)
                resp = new TFCtvResponse() { Code = -3003, Message = "Request parameter is empty." };
            else
            {
                if (req.GomsCustomerId == null || req.GomsTransactionDate == null || req.GomsTransactionId == null || req.GomsProductId == null || req.GomsProductQuantity == null || req.GomsTFCEverywhereEndDate == null || req.GomsTFCEverywhereStartDate == null || req.EmailAddress == null)
                {
                    resp = new TFCtvResponse() { Code = -3004, Message = "Missing required fields." };
                    return resp;
                }

                if (req.GomsProductId != null)
                    if (req.GomsProductId <= 0)
                    {
                        resp = new TFCtvResponse() { Code = -1000, Message = "GomsProductId is not applicable." };
                        return resp;
                    }

                var context = new IPTV2Entities();
                if (isProduction)
                    context.Database.Connection.ConnectionString = IPTV2EntitiesAzureConnectionString;


                var product = context.Products.FirstOrDefault(p => p.GomsProductId == req.GomsProductId && p.GomsProductQuantity == req.GomsProductQuantity);
                if (product == null)
                {
                    resp = new TFCtvResponse() { Code = -1007, Message = "Product does not exist." };
                    return resp;
                }

                var user = context.Users.FirstOrDefault(u => u.GomsCustomerId == req.GomsCustomerId && String.Compare(u.EMail, req.EmailAddress, true) == 0);
                if (user == null)
                {
                    resp = new TFCtvResponse() { Code = -1001, Message = "User does not exist." };
                    return resp;
                }

                //if (String.Compare(user.EMail, req.EmailAddress, true) != 0)
                //{
                //    resp = new TFCtvResponse() { Code = -1001, Message = "User does not exist." };
                //    return resp;
                //}

                if (user.Country == null)
                {
                    resp = new TFCtvResponse() { Code = -1002, Message = "User country is not valid." };
                    return resp;
                }
                //else // Do we need to check for Japan/US only?
                //{
                //    var countries = TVECountryWhitelist.Split(',');
                //    if (!countries.Contains(user.Country.Code))
                //    {
                //        resp = new TFCtvResponse() { Code = -1002, Message = "User country is not valid." };
                //        return resp;
                //    }
                //}

                if (user.IsTVEverywhere == null)
                {
                    resp = new TFCtvResponse() { Code = -1003, Message = "User is not applicable for TVEverywhere." };
                    return resp;
                }
                else
                {
                    if (user.IsTVEverywhere == false)
                    {
                        resp = new TFCtvResponse() { Code = -1003, Message = "User is not applicable for TVEverywhere." };
                        return resp;
                    }
                }

                var match = System.Text.RegularExpressions.Regex.Match(req.Reference, "Update|Deactivate|Activate|Change Plan", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                if (!match.Success)
                {
                    if (user.Transactions.Count(t => t.GomsTransactionId == req.GomsTransactionId) > 0)
                    {
                        resp = new TFCtvResponse() { Code = -1006, Message = "Transaction already exists in TFC.tv." };
                        return resp;
                    }
                }


                if (user != null)
                {
                    //user.LastUpdated = registDt;
                    user.LastUpdated = (DateTime)req.GomsTransactionDate;

                    if (user.IsTVEverywhere != null) // Check if set to true
                        if (user.IsTVEverywhere == false)
                            user.IsTVEverywhere = true;

                    ProductPrice productPrice;
                    try
                    {
                        productPrice = product.ProductPrices.FirstOrDefault(i => i.CurrencyCode == user.Country.CurrencyCode);
                    }
                    catch (Exception)
                    {
                        productPrice = product.ProductPrices.FirstOrDefault(i => i.CurrencyCode == DefaultCurrencyCode);
                    }

                    //Create Purchase
                    Purchase purchase = CreatePurchase((DateTime)req.GomsTransactionDate, "TFC Everywhere");
                    //Create Purchase Item
                    PurchaseItem purchaseItem = CreatePurchaseItem(user.UserId, product, productPrice);

                    var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId);
                    //Create Entitlement & EntitlementRequest
                    Entitlement entitlement = user.PackageEntitlements.FirstOrDefault(i => i.PackageId == productPackage.PackageId);

                    //DateTime endDate = registDt;
                    DateTime endDate = (DateTime)req.GomsTFCEverywhereEndDate;


                    if (entitlement != null)
                    {
                        //if (entitlement.EndDate > registDt)
                        //    entitlement.EndDate = entitlement.EndDate.Add(difference);
                        //else
                        //    entitlement.EndDate = registDt.Add(difference);

                        entitlement.EndDate = (DateTime)req.GomsTFCEverywhereEndDate;
                        EntitlementRequest request = new EntitlementRequest()
                        {
                            //DateRequested = registDt,
                            DateRequested = (DateTime)req.GomsTransactionDate,
                            StartDate = (DateTime)req.GomsTFCEverywhereStartDate,
                            EndDate = entitlement.EndDate,
                            Product = productPackage.Product,
                            Source = "TFC Everywhere",
                            ReferenceId = req.Reference
                        };

                        endDate = entitlement.EndDate;
                        user.EntitlementRequests.Add(request);
                        entitlement.LatestEntitlementRequest = request;
                    }
                    else
                    {
                        EntitlementRequest request = new EntitlementRequest()
                        {
                            //DateRequested = registDt,
                            DateRequested = (DateTime)req.GomsTransactionDate,
                            StartDate = (DateTime)req.GomsTFCEverywhereStartDate,
                            EndDate = (DateTime)req.GomsTFCEverywhereEndDate,
                            Product = productPackage.Product,
                            Source = "TFC Everywhere",
                            ReferenceId = req.Reference
                        };

                        PackageEntitlement pkg_entitlement = new PackageEntitlement()
                        {
                            EndDate = (DateTime)req.GomsTFCEverywhereEndDate,
                            Package = (IPTV2_Model.Package)productPackage.Package,
                            OfferingId = offeringId,
                            LatestEntitlementRequest = request
                        };

                        //endDate = item.LicenseEndDate;

                        user.PackageEntitlements.Add(pkg_entitlement);
                    }

                    //Create TFCtvEverywhereTransaction
                    TfcEverywhereTransaction transaction = new TfcEverywhereTransaction()
                    {
                        GomsTFCEverywhereEndDate = (DateTime)req.GomsTFCEverywhereEndDate,
                        GomsTFCEverywhereStartDate = (DateTime)req.GomsTFCEverywhereStartDate,
                        GomsTFCEverywhereSubscriptionId = "N/A",
                        GomsTFCEverywhereServiceId = "N/A",
                        GomsTransactionDate = req.GomsTransactionDate,
                        GomsTransactionId = req.GomsTransactionId,
                        Amount = productPrice.Amount,
                        Currency = productPrice.CurrencyCode,
                        //Date = registDt,
                        Date = (DateTime)req.GomsTransactionDate,
                        Reference = req.Reference,
                        OfferingId = offeringId,
                        StatusId = 1
                    };

                    user.Transactions.Add(transaction);
                }

                try
                {
                    if (context.SaveChanges() > 0)
                        resp = new TFCtvResponse() { Code = 0, Message = String.Format("Successfully created entitlement ending {0} to GomsCustomerId {1}.", req.GomsTFCEverywhereEndDate, req.GomsCustomerId) };
                    else
                        resp = new TFCtvResponse() { Code = -1005, Message = "Unable to create TFC.tv Everywhere entitlement." };
                }
                catch (Exception e)
                {
                    resp = new TFCtvResponse() { Code = -3000, Message = e.InnerException.Message };
                }

            }
            return resp;
        }
Пример #8
0
        private static void RunThis()
        {
            DateTime registDt = DateTime.Now;
            var absnow_context = new ABSNowEntities();
            var context = new IPTV2Entities();

            var processed_licenses = absnow_context.LicensePurchasedProcesseds.ToList();
            Console.WriteLine(String.Format("Processed Licenses: {0}", processed_licenses.Count()));
            //var platinum_users = absnow_context.CustomerLicensePurchased1.Where(i => i.PackageID == TFCnowPlatinumProductId && i.LicenseEndDate > registDt) // && i.EmailAddress == "*****@*****.**")
            //    .OrderByDescending(i => i.LicenseEndDate)
            //    .AsEnumerable()
            //    .GroupBy(i => i.EmailAddress)
            //     .Select(i => new
            //     {
            //         EmailAddress = i.Key,
            //         PackageID = i.Max(ii => ii.PackageID),
            //         CustomerID = i.Max(ii => ii.CustomerID),
            //         LicenseEndDate = i.Max(ii => ii.LicenseEndDate)
            //     }).ToList();

            var processedLicenses = processed_licenses.Select(i => i.LicensePurchasedID).ToArray();
            absnow_context.CommandTimeout = 120;
            var platinum_users = absnow_context.vwCustomerLicensePurchaseds.Where(i => !processedLicenses.Contains(i.LicensePurchasedID)).ToList();
            Console.WriteLine(String.Format("Platinum Users: {0}", platinum_users.Count()));
            var productPlatinum = context.Products.FirstOrDefault(i => i.ProductId == PlatinumProductId);
            var PremiumPackage = context.ProductPackages.FirstOrDefault(i => i.PackageId == PremiumPackageId);

            ProductPrice productPrice;
            if (platinum_users != null)
            {
                int counter = 1;
                foreach (var item in platinum_users)
                {
                    Console.WriteLine(String.Format("{1}. PROCESSING {0}", item.EmailAddress, counter));
                    //var purchaseId = absnow_context.CustomerLicensePurchased1.Where(i => i.EmailAddress.ToLower() == item.EmailAddress.ToLower() && i.PackageID == TFCnowPlatinumProductId).OrderByDescending(i => i.LicenseEndDate).First();
                    Console.WriteLine(String.Format("LicensePurchase ID: {0}", item.LicensePurchasedID));
                    counter++;
                    //if (!processed_licenses.Select(i => i.LicensePurchasedID).Contains(purchaseId.LicensePurchasedID))
                    //{
                    var difference = item.LicenseEndDate.Subtract(registDt);

                    var user = context.Users.FirstOrDefault(i => i.TfcNowUserName.ToLower() == item.EmailAddress.ToLower());
                    if (user != null)
                    {
                        Console.WriteLine(String.Format("TAGGED TFCnow {0} TO TFCtv {1}", item.EmailAddress, user.EMail));
                        try
                        {
                            productPrice = productPlatinum.ProductPrices.FirstOrDefault(i => i.CurrencyCode == user.Country.CurrencyCode);
                        }
                        catch (Exception)
                        {
                            productPrice = productPlatinum.ProductPrices.FirstOrDefault(i => i.CurrencyCode == DefaultCurrencyCode);
                        }

                        user.LastUpdated = registDt;


                        //Create Purchase
                        Purchase purchase = CreatePurchase(registDt, "TFC.tv Everywhere");
                        //Create Purchase Item
                        PurchaseItem purchaseItem = CreatePurchaseItem(user.UserId, productPlatinum, productPrice);

                        //Create Entitlement & EntitlementRequest
                        Entitlement entitlement = user.PackageEntitlements.FirstOrDefault(i => i.PackageId == PremiumPackageId);

                        DateTime endDate = registDt;

                        if (entitlement != null)
                        {

                            if (entitlement.EndDate > registDt)
                                entitlement.EndDate = entitlement.EndDate.Add(difference);
                            else
                                entitlement.EndDate = registDt.Add(difference);

                            //entitlement.EndDate = item.LicenseEndDate;

                            EntitlementRequest request = new EntitlementRequest()
                            {
                                DateRequested = registDt,
                                EndDate = entitlement.EndDate,
                                Product = PremiumPackage.Product,
                                Source = "TFC.tv Everywhere",
                                ReferenceId = String.Format("{0}", item.LicensePurchasedID)
                                //ReferenceId = String.Format("{0}", String.Empty)
                            };

                            endDate = entitlement.EndDate;

                            user.EntitlementRequests.Add(request);
                        }
                        else
                        {

                            EntitlementRequest request = new EntitlementRequest()
                            {
                                DateRequested = registDt,
                                EndDate = item.LicenseEndDate,
                                Product = PremiumPackage.Product,
                                Source = "TFC.tv Everywhere",
                                ReferenceId = String.Format("{0}", item.LicensePurchasedID)
                                //ReferenceId = String.Format("{0}", String.Empty)
                            };

                            PackageEntitlement pkg_entitlement = new PackageEntitlement()
                            {
                                EndDate = item.LicenseEndDate,
                                Package = (IPTV2_Model.Package)PremiumPackage.Package,
                                OfferingId = OfferingId,
                                LatestEntitlementRequest = request
                            };

                            //endDate = item.LicenseEndDate;

                            user.PackageEntitlements.Add(pkg_entitlement);

                        }

                        //Create TFCtvEverywhereTransaction
                        TfcEverywhereTransaction transaction = new TfcEverywhereTransaction()
                        {
                            GomsTFCEverywhereEndDate = endDate,
                            GomsTFCEverywhereStartDate = registDt,
                            GomsTFCEverywhereSubscriptionId = "N/A",
                            GomsTFCEverywhereServiceId = "N/A",
                            Amount = productPrice.Amount,
                            Currency = productPrice.CurrencyCode,
                            Date = registDt,
                            Reference = String.Format("TVE-{0}", item.TransactionID),
                            OfferingId = OfferingId,
                            StatusId = 1
                        };

                        user.Transactions.Add(transaction);

                        //Console.WriteLine(String.Format("TFCtv {0} LICENSE END DATE UPDATED", user.EMail));

                        if (context.SaveChanges() > 0)
                        {
                            Console.WriteLine(String.Format("TFCtv {0} LICENSE END DATE UPDATED", user.EMail));
                            LicensePurchasedProcessed receipt = new LicensePurchasedProcessed();
                            receipt.LicensePurchasedID = item.LicensePurchasedID;
                            receipt.CreateDate = registDt;
                            absnow_context.LicensePurchasedProcesseds.AddObject(receipt);
                            absnow_context.SaveChanges();
                        }
                    }
                    else
                        Console.WriteLine(String.Format("{0} NOT FOUND. SKIPPING.", item.EmailAddress));

                    //}
                }

                //absnow_context.SaveChanges();
            }
        }
        public ActionResult _Subscription(FormCollection f)
        {
            Dictionary<string, object> collection = new Dictionary<string, object>();
            collection = MyUtility.SetError(ErrorCode.UnidentifiedError, String.Empty);

            var email = f["EmailAddress"];
            var pId = f["Product"];
            var payment_mode = f["PaymentMode"];
            var reference = f["Reference"];
            var amt = f["Amount"];
            var currency = f["Currency"];
            var edt = f["EndDate"];
            var OverrideDuration = MyUtility.GetCheckBoxValue(Request, "OverrideDuration");
            var isRefund = MyUtility.GetCheckBoxValue(Request, "IsRefund");
            var IncludeWalletLoad = MyUtility.GetCheckBoxValue(Request, "IncludeWalletLoad");
            var registDt = DateTime.Now;
            try
            {
                int Duration = 0;
                string DurationType = String.Empty;
                DateTime endDt = registDt;

                if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(pId) || String.IsNullOrEmpty(payment_mode) || String.IsNullOrEmpty(reference) || String.IsNullOrEmpty(amt) || String.IsNullOrEmpty(currency))
                    throw new TFCtvMissingRequiredFields();

                if (isRefund && OverrideDuration)
                    throw new TFCtvUnidentifiedError("Is this a refund & Override product's duration can't be checked at the same time.");

                currency = currency.ToUpper();
                reference = reference.ToUpper();

                var context = new IPTV2Entities();
                var user = context.Users.FirstOrDefault(item => item.EMail.ToLower() == email.ToLower());
                if (user == null)
                    throw new TFCtvUserDoesNotExist();

                decimal amount;
                bool amt_result = decimal.TryParse(amt, out amount);
                if (!amt_result)
                    throw new TFCtvUnidentifiedError("Unable to convert Amount to decimal. User input was invalid.");

                int productId;
                bool pId_result = Int32.TryParse(pId, out productId);
                if (!pId_result)
                    throw new TFCtvUnidentifiedError("Unable to convert ProductId to Int32. User input was invalid.");

                if (OverrideDuration)
                {
                    DateTime overridingEndDate;
                    bool overrideDuration_result = DateTime.TryParse(edt, out overridingEndDate);
                    if (!overrideDuration_result)
                        throw new TFCtvUnidentifiedError("Unable to convert End Date to DateTime. User input was invalid.");
                }

                var currency_count = context.Currencies.Count(item => item.Code.ToUpper() == currency);
                if (currency_count == 0)
                    throw new TFCtvUnidentifiedError("Currency does not exist on our list. User input was invalid.");
                if (currency != Global.TrialCurrency)
                    if (user.Country.CurrencyCode.ToUpper() != currency)
                        throw new TFCtvUnidentifiedError("Currency does not match current user's currency.");

                var offering = context.Offerings.Find(Global.OfferingId);
                if (user.HasPendingGomsChangeCountryTransaction(offering))
                    throw new TFCtvUnidentifiedError("Change in location transaction found. Please retry later.");

                var product = context.Products.FirstOrDefault(item => item.ProductId == productId);

                if (product == null)
                    throw new TFCtvProductDoesNotExist();

                if (product is SubscriptionProduct)
                {
                    bool insertTransaction = false;
                    if (product is PackageSubscriptionProduct)
                    {
                        var package_subscription = (PackageSubscriptionProduct)product;
                        Duration = package_subscription.Duration;
                        DurationType = package_subscription.DurationType;

                        if (isRefund) //Refunding a subscription
                            Duration *= -1;

                        //Get Package
                        var package = package_subscription.Packages.FirstOrDefault();
                        if (package == null)
                            throw new TFCtvObjectIsNull("Package");

                        PackageEntitlement entitlement = null;

                        //Check entitlement for package
                        var package_entitlement = user.PackageEntitlements.FirstOrDefault(item => item.PackageId == package.PackageId);

                        if (isRefund) //Refunding a subscription
                            registDt = package_entitlement.EndDate;

                        endDt = MyUtility.GetEntitlementEndDate(Duration, DurationType, registDt);

                        if (package_entitlement != null)
                        {
                            endDt = MyUtility.GetEntitlementEndDate(Duration, DurationType, package_entitlement.EndDate > registDt ? package_entitlement.EndDate : registDt);
                            package_entitlement.EndDate = endDt;
                        }
                        else
                        {
                            entitlement = new PackageEntitlement()
                            {
                                EndDate = endDt,
                                Package = (Package)package.Package,
                                OfferingId = Global.OfferingId,
                            };
                            user.PackageEntitlements.Add(entitlement);
                        }

                        EntitlementRequest request = CreateEntitlementRequest(registDt, endDt, package.Product, "cPanel Settlement", reference);
                        if (request != null)
                        {
                            if (entitlement != null)
                                entitlement.LatestEntitlementRequest = request;
                            else
                                user.EntitlementRequests.Add(request);
                            insertTransaction = true;
                        }
                    }
                    else if (product is ShowSubscriptionProduct)
                    {
                        var show_subscription = (ShowSubscriptionProduct)product;
                        Duration = show_subscription.Duration;
                        DurationType = show_subscription.DurationType;

                        if (isRefund) //Refuding a subscription
                            Duration *= -1;

                        //Get Show
                        var category = show_subscription.Categories.FirstOrDefault();
                        if (category == null)
                            throw new TFCtvObjectIsNull("Category");

                        ShowEntitlement entitlement = null;

                        //Check entitlement for Category/Show
                        var show_entitlement = user.ShowEntitlements.FirstOrDefault(item => item.CategoryId == category.CategoryId);

                        if (isRefund) //Refunding a subscription
                            registDt = show_entitlement.EndDate;

                        endDt = MyUtility.GetEntitlementEndDate(Duration, DurationType, registDt);

                        if (show_entitlement != null)
                        {
                            endDt = MyUtility.GetEntitlementEndDate(Duration, DurationType, show_entitlement.EndDate > registDt ? show_entitlement.EndDate : registDt);
                            show_entitlement.EndDate = endDt;
                        }
                        else
                        {
                            entitlement = new ShowEntitlement()
                            {
                                EndDate = endDt,
                                Show = category.Show,
                                OfferingId = Global.OfferingId,
                            };
                            user.ShowEntitlements.Add(entitlement);
                        }

                        EntitlementRequest request = CreateEntitlementRequest(registDt, endDt, category.Product, "cPanel Settlement", reference);
                        if (request != null)
                        {
                            if (entitlement != null)
                                entitlement.LatestEntitlementRequest = request;
                            else
                                user.EntitlementRequests.Add(request);
                            insertTransaction = true;
                        }
                    }
                    else if (product is EpisodeSubscriptionProduct)
                    {
                        var episode_subscription = (EpisodeSubscriptionProduct)product;
                        Duration = episode_subscription.Duration;
                        DurationType = episode_subscription.DurationType;

                        if (isRefund) //Refuding a subscription
                            Duration *= -1;

                        //Get Episode
                        var episode = episode_subscription.Episodes.FirstOrDefault();
                        if (episode == null)
                            throw new TFCtvObjectIsNull("Episode");

                        EpisodeEntitlement entitlement = null;

                        //Check entitlement for Category/Show
                        var episode_entitlement = user.EpisodeEntitlements.FirstOrDefault(item => item.EpisodeId == episode.EpisodeId);

                        if (isRefund) //Refunding a subscription
                            registDt = episode_entitlement.EndDate;

                        endDt = MyUtility.GetEntitlementEndDate(Duration, DurationType, registDt);

                        if (episode_entitlement != null)
                        {
                            endDt = MyUtility.GetEntitlementEndDate(Duration, DurationType, episode_entitlement.EndDate > registDt ? episode_entitlement.EndDate : registDt);
                            episode_entitlement.EndDate = endDt;
                        }
                        else
                        {
                            entitlement = new EpisodeEntitlement()
                            {
                                EndDate = endDt,
                                Episode = episode.Episode,
                                OfferingId = Global.OfferingId,
                            };
                            user.EpisodeEntitlements.Add(entitlement);
                        }

                        EntitlementRequest request = CreateEntitlementRequest(registDt, endDt, episode.Product, "cPanel Settlement", reference);
                        if (request != null)
                        {
                            if (entitlement != null)
                                entitlement.LatestEntitlementRequest = request;
                            else
                                user.EntitlementRequests.Add(request);
                            insertTransaction = true;
                        }
                    }

                    //Create Purchase & Purchase Items
                    Purchase purchase = null; //CreatePurchase(registDt, "Settlement");
                    PurchaseItem purchase_item = null; //CreatePurchaseItem(user.UserId, product, amount, currency);

                    //user.Purchases.Add(purchase);
                    //user.PurchaseItems.Add(purchase_item);

                    //Insert transaction
                    if (insertTransaction)
                    {
                        switch (Convert.ToInt32(payment_mode))
                        {
                            case 1: // Prepaid Card
                                purchase = CreatePurchase(registDt, "Settlement via Prepaid Card");
                                user.Purchases.Add(purchase);
                                purchase_item = CreatePurchaseItem(user.UserId, product, amount, currency);
                                purchase.PurchaseItems.Add(purchase_item);

                                Ppc Ppc = context.Ppcs.FirstOrDefault(item => item.SerialNumber.ToUpper() == reference);
                                if (Ppc == null)
                                    throw new TFCtvObjectIsNull("Prepaid Card");
                                if (!(Ppc is SubscriptionPpc))
                                    throw new TFCtvEntityFrameworkError("Prepaid Card is not of type: Subscription.");

                                PpcPaymentTransaction pTransaction = new PpcPaymentTransaction()
                                {
                                    Currency = currency,
                                    Reference = reference,
                                    Amount = Convert.ToDecimal(amount),
                                    Product = product,
                                    Purchase = purchase,
                                    SubscriptionPpc = (SubscriptionPpc)Ppc,
                                    Date = registDt,
                                    OfferingId = Global.OfferingId
                                };
                                user.Transactions.Add(pTransaction);
                                break;
                            case 2: // E-Wallet
                                purchase = CreatePurchase(registDt, "Settlement via Wallet");
                                user.Purchases.Add(purchase);
                                purchase_item = CreatePurchaseItem(user.UserId, product, amount, currency);
                                purchase.PurchaseItems.Add(purchase_item);

                                var wallet = user.UserWallets.FirstOrDefault(item => item.IsActive == true);
                                if (IncludeWalletLoad)
                                    wallet.Balance += amount;

                                WalletPaymentTransaction wTransaction = new WalletPaymentTransaction()
                                {
                                    Currency = currency,
                                    Reference = reference,
                                    Amount = Convert.ToDecimal(amount),
                                    Date = registDt,
                                    User = user,
                                    OfferingId = Global.OfferingId
                                };
                                user.Transactions.Add(wTransaction);
                                wallet.WalletPaymentTransactions.Add(wTransaction);
                                break;
                            case 3: // Credit Card
                                purchase = CreatePurchase(registDt, "Settlement via Credit Card");
                                user.Purchases.Add(purchase);
                                purchase_item = CreatePurchaseItem(user.UserId, product, Convert.ToDecimal(amount), currency);
                                purchase.PurchaseItems.Add(purchase_item);

                                CreditCardPaymentTransaction cTransaction = new CreditCardPaymentTransaction()
                                {
                                    Amount = Convert.ToDecimal(amount),
                                    Currency = currency,
                                    Reference = reference,
                                    Date = registDt,
                                    Purchase = purchase,
                                    OfferingId = Global.OfferingId
                                };
                                user.Transactions.Add(cTransaction);
                                break;
                            case 4: // Paypal
                                purchase = CreatePurchase(registDt, "Settlement via Paypal");
                                user.Purchases.Add(purchase);
                                purchase_item = CreatePurchaseItem(user.UserId, product, Convert.ToDecimal(amount), currency);
                                purchase.PurchaseItems.Add(purchase_item);

                                PaypalPaymentTransaction ppTransaction = new PaypalPaymentTransaction()
                                {
                                    Currency = currency,
                                    Reference = reference,
                                    Amount = Convert.ToDecimal(amount),
                                    User = user,
                                    Date = registDt,
                                    OfferingId = Global.OfferingId
                                };
                                user.Transactions.Add(ppTransaction);
                                break;
                            case 5: // Migration
                                MigrationTransaction mTransaction = new MigrationTransaction()
                                {
                                };
                                user.Transactions.Add(mTransaction);
                                break;
                            default: break;
                        }

                        if (context.SaveChanges() > 0)
                        {
                            collection = MyUtility.SetError(ErrorCode.Success, "You have successfully settled a complaint.");
                            // Success
                        }
                    }
                }
            }
            catch (TFCtvException e)
            {
                collection = MyUtility.SetError(e.StatusCode, e.StatusMessage);
            }
            catch (Exception e)
            {
                collection = MyUtility.SetError(ErrorCode.UnidentifiedError, e.Message);
            }

            return Content(MyUtility.BuildJSON(collection), "application/json");
        }
Пример #10
0
        public ActionResult Migrate()
        {
            if (GlobalConfig.IsTVERegistrationEnabled)
                return RedirectToAction("Index", "Home");

            Dictionary<string, object> collection = new Dictionary<string, object>();
            ErrorCodes errorCode = ErrorCodes.UnknownError;
            string errorMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError);
            DateTime registDt = DateTime.Now;
            collection = MyUtility.setError(errorCode, errorMessage);

            if (TempData["TFCnowCustomer"] == null)
                return RedirectToAction("Index", "Home");

            if (!MyUtility.isUserLoggedIn())
                return RedirectToAction("Index", "Home");

            Customer customer = (Customer)TempData["TFCnowCustomer"];

            var absnow_context = new ABSNowEntities();

            string TFCnowPackageIds = GlobalConfig.TFCnowPackageIds;
            var packageids = MyUtility.StringToIntList(TFCnowPackageIds);
            var context = new IPTV2Entities();
            var userId = new Guid(User.Identity.Name);
            User user = context.Users.FirstOrDefault(u => u.UserId == userId);
            if (user == null)
                return RedirectToAction("Index", "Migration");



            //Tag account
            user.TfcNowUserName = customer.EmailAddress;
            user.LastUpdated = registDt;
            context.SaveChanges();

            bool isLicenseMigrated = false;
            bool isWalletMigrated = false;
            //Migrate Wallet
            var balance = absnow_context.NCashWalletBalanceTables.FirstOrDefault(u => u.userId.ToLower() == customer.EmailAddress.ToLower());

            if (balance != null)
            {
                if (balance.cashBalance > 0)
                {
                    var transfer_amount = Forex.Convert(context, GlobalConfig.DefaultCurrency, user.Country.CurrencyCode, balance.cashBalance);

                    var userWallet = user.UserWallets.FirstOrDefault(u => u.Currency == user.Country.CurrencyCode && u.IsActive == true);
                    if (userWallet == null)
                    {
                        userWallet = new UserWallet()
                        {
                            Balance = transfer_amount,
                            IsActive = true,
                            Currency = user.Country.CurrencyCode,
                        };
                        user.UserWallets.Add(userWallet);
                    }
                    else
                        userWallet.Balance += transfer_amount;

                    //Create Paypal transaction

                    var ppTransaction = new PaypalReloadTransaction()
                    {
                        Amount = transfer_amount,
                        Currency = user.Country.CurrencyCode,
                        Date = registDt,
                        Reference = String.Format("M-{0}", customer.CustomerID),
                        OfferingId = GlobalConfig.offeringId,
                        UserWallet = userWallet,
                        StatusId = GlobalConfig.Visible
                    };

                    user.Transactions.Add(ppTransaction);
                    if (context.SaveChanges() > 0)
                        isWalletMigrated = true;
                }
            }

            var licenses = absnow_context.LicensePurchaseds.Where(l => l.CustomerID == customer.CustomerID && packageids.Contains(l.PackageID) && l.LicenseEndDate > registDt).OrderByDescending(l => l.LicenseEndDate);

            //Migrate Licenses
            if (licenses.Count() == 0)
            {
                if (isWalletMigrated)
                {
                    user.TfcNowUserName = customer.EmailAddress;
                    context.SaveChanges();
                }

                //  return RedirectToAction("Complete", "Migration");
                //collection = MyUtility.setError(ErrorCodes.UnknownError, "No licenses to migrate.");
            }
            else
            {
                bool isPremiumProcessed = false;
                bool isLiteProcessed = false;
                bool isMovieChannelProcessed = false;
                bool isLiveStreamProcessed = false;

                var TFCnowPremium = MyUtility.StringToIntList(GlobalConfig.TFCnowPremium);
                var TFCnowLite = MyUtility.StringToIntList(GlobalConfig.TFCnowLite);
                var TFCnowMovieChannel = MyUtility.StringToIntList(GlobalConfig.TFCnowMovieChannel);
                var TFCnowLiveStream = MyUtility.StringToIntList(GlobalConfig.TFCnowLiveStream);

                List<LicenseDisplay> display = new List<LicenseDisplay>();

                var premiumLicense = GetLicense(absnow_context, TFCnowPremium, licenses, 1427);
                display.Add(premiumLicense);
                display.Add(GetLicense(absnow_context, TFCnowLite, licenses, 1425));
                display.Add(GetLicense(absnow_context, TFCnowMovieChannel, licenses, 45));
                if (premiumLicense == null)
                    display.Add(GetLicense(absnow_context, TFCnowLiveStream, licenses, 1427));

                display.RemoveAll(item => item == null);

                foreach (var item in display)
                {
                    int TFCtvPackageId = 0;
                    int TFCtvProductId = 0;

                    if (item.LicenseEndDate > registDt)
                    {
                        var difference = item.LicenseEndDate.Subtract(registDt);
                        PackageEntitlement entitlement = null;
                        if (TFCnowPremium.Contains(item.PackageId))
                        {
                            if (!isPremiumProcessed)
                            {
                                entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == GlobalConfig.premiumId);
                                isPremiumProcessed = true;
                                TFCtvPackageId = GlobalConfig.premiumId;
                            }
                        }
                        else if (TFCnowLite.Contains(item.PackageId))
                        {
                            if (!isLiteProcessed)
                            {
                                if (user.CountryCode == GlobalConfig.DefaultCountry)
                                {
                                    entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == GlobalConfig.premiumId);
                                    TFCtvPackageId = GlobalConfig.premiumId;
                                }

                                else
                                {
                                    entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == GlobalConfig.liteId);
                                    TFCtvPackageId = GlobalConfig.liteId;
                                }

                                isLiteProcessed = true;
                            }
                        }
                        else if (TFCnowMovieChannel.Contains(item.PackageId))
                        {
                            if (!isMovieChannelProcessed)
                            {
                                entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == GlobalConfig.movieId);
                                isMovieChannelProcessed = true;
                                TFCtvPackageId = GlobalConfig.movieId;
                            }
                        }

                        else if (TFCnowLiveStream.Contains(item.PackageId))
                        {
                            if (!isLiveStreamProcessed)
                            {
                                if (!isPremiumProcessed)
                                {
                                    entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == GlobalConfig.premiumId);
                                    isLiveStreamProcessed = true;
                                    TFCtvPackageId = GlobalConfig.premiumId;
                                }
                            }
                        }

                        else
                        {
                            //Provide load
                        }
                        if (TFCtvPackageId > 0)
                        {
                            ProductPackage package = context.ProductPackages.FirstOrDefault(p => p.PackageId == TFCtvPackageId);
                            TFCtvProductId = package.Product.ProductId;

                            if (entitlement != null)
                            {
                                if (entitlement.EndDate > registDt)
                                    entitlement.EndDate = entitlement.EndDate.Add(difference);
                                else
                                    entitlement.EndDate = registDt.Add(difference);


                                EntitlementRequest request = new EntitlementRequest()
                                {
                                    DateRequested = registDt,
                                    StartDate = item.LicenseStartDate,
                                    EndDate = entitlement.EndDate,
                                    Product = package.Product,
                                    Source = "Entitlement Transfer",
                                    ReferenceId = item.LicensePurchaseId.ToString()
                                };
                                entitlement.LatestEntitlementRequest = request; // ADDED DECEMBER 06, 2012
                                user.EntitlementRequests.Add(request);
                            }

                            else
                            {
                                EntitlementRequest request = new EntitlementRequest()
                                {
                                    DateRequested = registDt,
                                    StartDate = item.LicenseStartDate,
                                    EndDate = item.LicenseEndDate,
                                    Product = package.Product,
                                    Source = "Entitlement Transfer",
                                    ReferenceId = item.LicensePurchaseId.ToString()
                                };

                                user.EntitlementRequests.Add(request);
                                PackageEntitlement pkg_entitlement = new PackageEntitlement()
                                {
                                    EndDate = item.LicenseEndDate,
                                    Package = (IPTV2_Model.Package)package.Package,
                                    OfferingId = GlobalConfig.offeringId,
                                    LatestEntitlementRequest = request
                                };
                                user.PackageEntitlements.Add(pkg_entitlement);
                            }
                        }
                    }

                    if (TFCtvProductId > 0)
                    {
                        MigrationTransaction transaction = new MigrationTransaction()
                        {
                            Amount = 0,
                            Currency = GlobalConfig.DefaultCurrency,
                            Date = registDt,
                            OfferingId = GlobalConfig.offeringId,
                            Reference = item.LicensePurchaseId.ToString(),
                            MigratedProductId = TFCtvProductId,
                            StatusId = GlobalConfig.Visible
                        };
                        user.Transactions.Add(transaction);
                    }
                }
                if (context.SaveChanges() > 0)
                    isLicenseMigrated = true;
            }

            bool isTingiMigrated = false;
            var tingi = absnow_context.TFCNowRetailMigrationIDs.Select(i => new { i.TFCnowPackageID, i.GOMSInternalID });
            var tingi_licenses = absnow_context.LicensePurchaseds.Where(l => l.CustomerID == customer.CustomerID && tingi.Select(i => i.TFCnowPackageID).Contains(l.PackageID) && l.LicenseEndDate > registDt).OrderByDescending(l => l.LicenseEndDate);
            if (tingi_licenses.Count() == 0)
            {
                if (isLicenseMigrated || isWalletMigrated)
                {
                    user.TfcNowUserName = customer.EmailAddress;
                    context.SaveChanges();
                }

                return RedirectToAction("Complete", "Migration");
            }
            else
            {
                foreach (var item in tingi_licenses)
                {
                    var diff = item.LicenseEndDate.Subtract(registDt);

                    var GomsProductId = tingi.FirstOrDefault(t => t.TFCnowPackageID == item.PackageID);
                    var TFCtvProduct = context.Products.FirstOrDefault(p => p.GomsProductId == GomsProductId.GOMSInternalID);

                    if (TFCtvProduct != null)
                    {
                        if (TFCtvProduct is ShowSubscriptionProduct)
                        {
                            var showSubscription = (ShowSubscriptionProduct)TFCtvProduct;
                            ShowEntitlement se = user.ShowEntitlements.FirstOrDefault(s => s.Show.CategoryId == showSubscription.Categories.First().CategoryId);
                            if (se != null)
                            {
                                if (se.EndDate > registDt)
                                    se.EndDate = showSubscription.ALaCarteSubscriptionTypeId == 2 ? se.EndDate.AddYears(1) : se.EndDate.Add(diff);
                                else
                                    se.EndDate = showSubscription.ALaCarteSubscriptionTypeId == 2 ? registDt.AddYears(1) : registDt.Add(diff);

                                EntitlementRequest request = new EntitlementRequest()
                                {
                                    DateRequested = registDt,
                                    EndDate = se.EndDate,
                                    Product = TFCtvProduct,
                                    Source = "Entitlement Transfer",
                                    ReferenceId = item.LicensePurchasedID.ToString()
                                };
                                user.EntitlementRequests.Add(request);
                            }
                            else
                            {
                                EntitlementRequest request = new EntitlementRequest()
                                {
                                    DateRequested = registDt,
                                    EndDate = showSubscription.ALaCarteSubscriptionTypeId == 2 ? registDt.AddYears(1) : registDt.Add(diff),
                                    Product = TFCtvProduct,
                                    Source = "Entitlement Transfer",
                                    ReferenceId = item.LicensePurchasedID.ToString()
                                };

                                user.EntitlementRequests.Add(request);
                                ShowEntitlement show_entitlement = new ShowEntitlement()
                                {
                                    EndDate = showSubscription.ALaCarteSubscriptionTypeId == 2 ? registDt.AddYears(1) : registDt.Add(diff),
                                    Show = showSubscription.Categories.First().Show,
                                    OfferingId = GlobalConfig.offeringId,
                                    LatestEntitlementRequest = request
                                };
                                user.ShowEntitlements.Add(show_entitlement);
                            }

                            MigrationTransaction transaction = new MigrationTransaction()
                            {
                                Amount = 0,
                                Currency = GlobalConfig.DefaultCurrency,
                                Date = registDt,
                                OfferingId = GlobalConfig.offeringId,
                                Reference = item.LicensePurchasedID.ToString(),
                                MigratedProductId = TFCtvProduct.ProductId,
                                StatusId = GlobalConfig.Visible
                            };
                            user.Transactions.Add(transaction);
                        }
                    }
                }
                if (context.SaveChanges() > 0)
                    isTingiMigrated = true;
            }

            if (isLicenseMigrated || isWalletMigrated || isTingiMigrated)
            {
                user.TfcNowUserName = customer.EmailAddress;
                user.LastUpdated = registDt;
            }
            else
            {
                user.TfcNowUserName = customer.EmailAddress;
                user.LastUpdated = registDt;
            }

            if (context.SaveChanges() > 0)
            {
                return RedirectToAction("Complete", "Migration");
            }
            return Content(MyUtility.buildJson(collection), "application/json");
        }