Example #1
0
        public ActionResult _RegisterTFCEverywhere(FormCollection fc)
        {
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = String.Empty
            };

            string url = Url.Action("RegisterTFCEverywhere", "User").ToString();
            var field_names = new string[] { "smartCardNum", "cusAccount" };
            try
            {
                if (TempData["qs"] != null)
                {
                    var qs = (NameValueCollection)TempData["qs"];
                    ViewBag.qs = qs;
                    TempData["qs"] = qs;
                }

                DateTime registDt = DateTime.Now;
                Dictionary<string, string> tmpCollection = fc.AllKeys.ToDictionary(k => k, v => fc[v]);
                bool isMissingRequiredFields = false;

                foreach (var x in tmpCollection)
                {
                    if (!field_names.Contains(x.Key))
                        if (String.IsNullOrEmpty(x.Value))
                        {
                            isMissingRequiredFields = true;
                            break;
                        }
                }

                if (!isMissingRequiredFields) // process form
                {
                    if (HasConsumedNumberOfRetriesForTFCEverywhere())
                    {
                        ReturnCode.StatusMessage = "Invalid data entered. Please call our Customer Service at 18778846832 or chat with our live support team for assistance.";
                        TempData["ErrorMessage"] = ReturnCode;
                        return RedirectToAction("RegisterTFCEverywhere", "User");
                    }

                    if (String.IsNullOrEmpty(fc["smartCardNum"]) && String.IsNullOrEmpty(fc["cusAccount"]))
                    {
                        ReturnCode.StatusMessage = "Please fill up all the required fields.";
                        TempData["ErrorMessage"] = ReturnCode;
                        return RedirectToAction("RegisterTFCEverywhere", "User");
                    }

                    var context = new IPTV2Entities();
                    User user = null;
                    if (User.Identity.IsAuthenticated)
                    {
                        string CurrencyCode = GlobalConfig.DefaultCurrency;
                        var UserId = new Guid(User.Identity.Name);
                        user = context.Users.FirstOrDefault(u => u.UserId == UserId);
                        if (user != null)
                        {
                            CurrencyCode = user.Country.CurrencyCode;

                            var transaction = new TfcEverywhereTransaction()
                            {
                                Amount = 0,
                                Date = registDt,
                                Currency = CurrencyCode,
                                OfferingId = GlobalConfig.offeringId,
                                StatusId = GlobalConfig.Visible,
                                Reference = "TFC Everywhere - CLAIM",
                                UserId = user.UserId
                            };

                            var gomsService = new GomsTfcTv();

                            var MacAddressOrSmartCard = fc["smartCardNum"].Replace(" ", "");
                            var AccountNumber = fc["cusAccount"].Replace(" ", "");
                            var ActivationNumber = fc["actCode"].Replace(" ", "");

                            var response = gomsService.ClaimTVEverywhere(context, user.UserId, transaction, MacAddressOrSmartCard, AccountNumber, ActivationNumber);
                            if (response.IsSuccess)
                            {
                                AddTfcEverywhereEntitlement(context, response.TFCTVSubItemId, response.ExpiryDate, response.TVEServiceId, user);
                                transaction.GomsTFCEverywhereEndDate = Convert.ToDateTime(response.ExpiryDate);
                                transaction.GomsTFCEverywhereStartDate = registDt;
                                user.Transactions.Add(transaction);
                                user.IsTVEverywhere = true;
                                if (context.SaveChanges() > 0)
                                {
                                    ReturnCode.StatusCode = (int)ErrorCodes.Success;
                                    ReturnCode.info = "TFC Everywhere Activation";
                                    ReturnCode.CCStatusMessage = "Congratulations! Your TFC Everywhere is now activated.";
                                    ReturnCode.StatusMessage = "Pwede ka nang manood ng piling Kapamilya shows at<br>movies mula sa paborito niyong TFC Channels.";
                                    TempData["ErrorMessage"] = ReturnCode;
                                    return RedirectToAction("Index", "Home"); // successful tve activation                                    
                                }
                            }
                            else
                            {
                                SetNumberOfTriesForTFCEverywhereCookie();
                                if (String.Compare(response.StatusCode, "8", true) == 0)
                                    ReturnCode.StatusMessage = "Go to your Edit My Profile page to update the last name registered on your TFC.tv account.";
                                else
                                    ReturnCode.StatusMessage = response.StatusMessage;
                            }
                        }
                        else
                            ReturnCode.StatusMessage = "User does not exist.";
                    }
                    else
                        ReturnCode.StatusMessage = "You are not logged in.";
                }
                else
                    ReturnCode.StatusMessage = "Please fill in all required fields.";
                TempData["ErrorMessage"] = ReturnCode;
                url = Request.UrlReferrer.AbsolutePath;
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return Redirect(url);
        }
Example #2
0
        public ActionResult _ClaimTVEverywhere(FormCollection fc)
        {
            Dictionary<string, object> collection = new Dictionary<string, object>();
            ErrorCodes errorCode = ErrorCodes.UnknownError;
            string errorMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError);
            collection = MyUtility.setError(errorCode, errorMessage);
            DateTime registDt = DateTime.Now;
            try
            {
                if (HasConsumedNumberOfRetriesForTFCEverywhere())
                {
                    collection = MyUtility.setError(ErrorCodes.LimitReached, "Invalid data entered. Please call our Customer Service at 18778846832 or chat with our live support team for assistance.");
                    return Content(MyUtility.buildJson(collection), "application/json");
                }
                if (((String.IsNullOrEmpty(fc["MacAddressOrSmartCard"]) && String.IsNullOrEmpty(fc["AccountNumber"]))) || String.IsNullOrEmpty(fc["ActivationNumber"]))
                {
                    collection = MyUtility.setError(ErrorCodes.IsMissingRequiredFields, "Please fill up the required fields.");
                    return Content(MyUtility.buildJson(collection), "application/json");
                }

                var context = new IPTV2Entities();
                User user = null;
                if (MyUtility.isUserLoggedIn())
                {
                    var userId = new Guid(User.Identity.Name);
                    user = context.Users.FirstOrDefault(u => u.UserId == userId);
                }
                else
                {
                    var userId = (Guid)TempData["tempUid"];
                    TempData["tempUserId"] = userId; // REASSIGN
                    TempData["tempUid"] = userId; // REASSIGN
                    user = context.Users.FirstOrDefault(u => u.UserId == userId);
                }

                if (user != null)
                {
                    string CurrencyCode = GlobalConfig.DefaultCurrency;
                    Country country = context.Countries.FirstOrDefault(c => c.Code == user.CountryCode);
                    if (country != null)
                    {
                        Currency currency = context.Currencies.FirstOrDefault(c => c.Code == country.CurrencyCode);
                        if (currency != null) CurrencyCode = currency.Code;
                    }

                    var transaction = new TfcEverywhereTransaction()
                    {
                        Amount = 0,
                        Date = DateTime.Now,
                        Currency = CurrencyCode,
                        OfferingId = GlobalConfig.offeringId,
                        StatusId = GlobalConfig.Visible,
                        Reference = "TFC Everywhere - CLAIM",
                        UserId = user.UserId
                    };

                    var gomsService = new GomsTfcTv();


                    var MacAddressOrSmartCard = fc["MacAddressOrSmartCard"].Replace(" ", "");
                    var AccountNumber = fc["AccountNumber"].Replace(" ", "");
                    var ActivationNumber = fc["ActivationNumber"].Replace(" ", "");

                    var response = gomsService.ClaimTVEverywhere(context, user.UserId, transaction, MacAddressOrSmartCard, AccountNumber, ActivationNumber);
                    if (response.IsSuccess)
                    {
                        AddTfcEverywhereEntitlement(context, response.TFCTVSubItemId, response.ExpiryDate, response.TVEServiceId, user);
                        transaction.GomsTFCEverywhereEndDate = Convert.ToDateTime(response.ExpiryDate);
                        transaction.GomsTFCEverywhereStartDate = registDt;
                        user.Transactions.Add(transaction);
                        user.IsTVEverywhere = true;
                        if (context.SaveChanges() > 0)
                        {
                            collection = MyUtility.setError(ErrorCodes.Success, String.Empty);
                            collection.Add("href", GlobalConfig.RegistrationCompleteTVE);
                        }
                    }
                    else
                    {
                        SetNumberOfTriesForTFCEverywhereCookie();
                        if (String.Compare(response.StatusCode, "8", true) == 0)
                        {
                            var sb = new StringBuilder();
                            sb.Append(response.StatusMessage);
                            sb.Append(" Go to your <a href=\"/EditProfile\" target=\"_blank\">Edit My Profile</a> page to update the last name registered on your TFC.tv account.");
                            collection = MyUtility.setError(ErrorCodes.UnknownError, sb.ToString());
                        }
                        else
                            collection = MyUtility.setError(ErrorCodes.UnknownError, response.StatusMessage);

                    }

                }
                else
                    collection = MyUtility.setError(ErrorCodes.UserDoesNotExist, "User does not exist.");
            }
            catch (Exception e) { MyUtility.LogException(e); collection = MyUtility.setError(ErrorCodes.UnknownError, e.Message); }
            return Content(MyUtility.buildJson(collection), "application/json");
        }
Example #3
0
        public ActionResult _ClaimTVE(FormCollection fc, string EmailAddress, string MacAddressOrSmartCard, string AccountNumber, string ActivationCode)
        {
            Dictionary<string, object> collection = new Dictionary<string, object>();
            ErrorCodes errorCode = ErrorCodes.UnknownError;
            string errorMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError);
            collection = MyUtility.setError(errorCode, errorMessage);

            try
            {
                DateTime registDt = DateTime.Now;

                var context = new IPTV2Entities();

                var userId = new Guid("E21D87F3-5940-451A-B7EE-ADA4F3CEC234");

                if (!String.IsNullOrEmpty(EmailAddress))
                {
                    var user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EmailAddress, true) == 0);
                    if (user != null)
                    {
                        userId = user.UserId;
                        string CurrencyCode = GlobalConfig.DefaultCurrency;
                        Country country = context.Countries.FirstOrDefault(c => c.Code == user.CountryCode);
                        if (country != null)
                        {
                            Currency currency = context.Currencies.FirstOrDefault(c => c.Code == country.CurrencyCode);
                            if (currency != null) CurrencyCode = currency.Code;
                        }

                        var transaction = new TfcEverywhereTransaction()
                        {
                            Amount = 0,
                            Date = DateTime.Now,
                            Currency = CurrencyCode,
                            OfferingId = GlobalConfig.offeringId,
                            StatusId = GlobalConfig.Visible,
                            Reference = "TFC Everywhere - Activate"
                        };

                        //string MacAddressOrSmartCard = "00172F0108FC";
                        //string AccountNumber = "US-000179857";
                        //string ActivationCode = "5S3UDP";
                        var gomsService = new GomsTfcTv();
                        var response = gomsService.ClaimTVEverywhere(context, userId, transaction, MacAddressOrSmartCard, AccountNumber, ActivationCode);
                        if (response.IsSuccess)
                        {

                            //ADD Entitlement
                            AddTfcEverywhereEntitlement(context, response.TFCTVSubItemId, response.ExpiryDate, response.TVEServiceId, user);

                            transaction.GomsTFCEverywhereEndDate = Convert.ToDateTime(response.ExpiryDate);
                            transaction.GomsTFCEverywhereStartDate = registDt;
                            user.Transactions.Add(transaction);
                            user.IsTVEverywhere = true;
                            if (context.SaveChanges() > 0)
                                collection = MyUtility.setError(ErrorCodes.Success, "Claimed TVE");
                        }
                        else
                            collection = MyUtility.setError(ErrorCodes.UnknownError, response.StatusMessage);
                    }

                }



            }
            catch (Exception e) { collection = MyUtility.setError(ErrorCodes.UserDoesNotExist, e.Message); }
            return Content(MyUtility.buildJson(collection), "application/json");

        }
Example #4
0
        public RespClaimTVE ClaimTVEverywhere(IPTV2Entities context, Guid userId, TfcEverywhereTransaction transaction, string MacAddressOrSmartCard, string AccountNumber, string ActivationCode)
        {
            RespClaimTVE result = null;

            InitializeServiceClient();

            try
            {

                // Validate User
                GomsException validationResult = UserValidation(context, userId);
                if (!(validationResult is GomsSuccess))
                {
                    throw validationResult;
                }
                var user = context.Users.Find(userId);

                if (transaction == null)
                {
                    throw new GomsInvalidTransactionException();
                }
                else
                {
                    //if ((transaction.GomsTFCEverywhereServiceId == null))
                    //{
                    //    throw new GomsInvalidTransactionException();
                    //}
                }
                var PhoenixId = (int)(DateTime.Now.Ticks - int.MaxValue);
                var req = new ReqClaimTVE
                {
                    UID = ServiceUserId,
                    PWD = ServicePassword,
                    Email = user.EMail,
                    CustomerId = (int)user.GomsCustomerId,
                    TFCTVCustomerId = (int)user.GomsCustomerId,
                    TFCTVServiceId = (int)user.GomsServiceId,
                    MacAddressOrSmartCard = MacAddressOrSmartCard,
                    AccountNumber = AccountNumber,
                    ActivationCode = ActivationCode
                };
                var log = new GomsLogs() { email = user.EMail, phoenixid = PhoenixId };
                try
                {
                    // _serviceClient.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(5);
                    var startTime = DateTime.Now;
                    result = _serviceClient.ClaimTVE(req);
                    var endTime = DateTime.Now;
                    var timeDifference = endTime - startTime;

                    if (result.IsSuccess)
                    {
                        var registDt = DateTime.Now;
                        transaction.Reference += "-" + result.GomsTransactionId.ToString();
                        transaction.GomsTransactionId = result.GomsTransactionId;
                        transaction.GomsTransactionDate = registDt;
                        transaction.GomsTFCEverywhereSubscriptionId = result.TFCTVSubId.ToString();
                        transaction.GomsTFCEverywhereServiceId = result.TFCServiceId.ToString();
                        transaction.GomsTFCEverywhereStartDate = registDt;
                        transaction.GomsTFCEverywhereEndDate = Convert.ToDateTime(result.ExpiryDate);
                        transaction.GomsRemarks = null;
                        //user.Transactions.Add(transaction);
                        //context.SaveChanges();

                        log.transactionid = transaction.TransactionId;
                        log.transactiondate = transaction.GomsTransactionDate.Value.ToString("yyyy-MM-dd hh:mm:ss");
                    }
                    else
                    {
                        log.transactionid = 0;
                        log.transactiondate = String.Empty;
                    }

                    log.message = String.Format("{0} - {1}", result.IsSuccess, result.StatusMessage);
                    log.statuscode = result.StatusCode;
                    log.statusmessage = result.StatusMessage;
                    log.issuccess = result.IsSuccess;
                    log.gomstransactionid = result.GomsTransactionId;
                }
                catch (Exception e)
                {
                    log.message = e.Message;
                    LogToGigya("glogs", log);
                    throw new GomsServiceCallException(e.Message);

                }
                finally
                {
                    LogToGigya("glogs", log);
                }
            }
            catch (GomsException e)
            {
                result = new RespClaimTVE { IsSuccess = false, StatusCode = e.StatusCode, StatusMessage = e.StatusMessage };
            }

            return (result);
        }
Example #5
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;
        }
Example #6
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();
            }
        }