Exemplo n.º 1
0
 /// <summary>
 /// Create a new LicensePurchasedProcessed object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="licensePurchasedID">Initial value of the LicensePurchasedID property.</param>
 /// <param name="createDate">Initial value of the CreateDate property.</param>
 public static LicensePurchasedProcessed CreateLicensePurchasedProcessed(global::System.Int32 id, global::System.Guid licensePurchasedID, global::System.DateTime createDate)
 {
     LicensePurchasedProcessed licensePurchasedProcessed = new LicensePurchasedProcessed();
     licensePurchasedProcessed.Id = id;
     licensePurchasedProcessed.LicensePurchasedID = licensePurchasedID;
     licensePurchasedProcessed.CreateDate = createDate;
     return licensePurchasedProcessed;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the LicensePurchasedProcesseds EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToLicensePurchasedProcesseds(LicensePurchasedProcessed licensePurchasedProcessed)
 {
     base.AddObject("LicensePurchasedProcesseds", licensePurchasedProcessed);
 }
Exemplo n.º 3
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();
            }
        }