当前位置: 首页>>代码示例>>C#>>正文


C# IPTV2Entities.SaveChanges方法代码示例

本文整理汇总了C#中IPTV2_Model.IPTV2Entities.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# IPTV2Entities.SaveChanges方法的具体用法?C# IPTV2Entities.SaveChanges怎么用?C# IPTV2Entities.SaveChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPTV2_Model.IPTV2Entities的用法示例。


在下文中一共展示了IPTV2Entities.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateHlsClips

        static void ValidateHlsClips()
        {
            string dirList = @"C:\Users\epaden\Desktop\dirlist.txt";

            int offeringId = 2;
            int serviceId = 46;

            var context = new IPTV2Entities();

            var directoryList = LoadDirectoryList(dirList);

            var offering = context.Offerings.Find(offeringId);

            var service = offering.Services.FirstOrDefault(s => s.PackageId == serviceId);
            var showList = service.GetAllOnlineShowIds("US");
            foreach (var showId in showList)
            {
                var showAsCategory = context.CategoryClasses.Find(showId);

                if (showAsCategory is Show)
                {
                    var show = (Show)showAsCategory;
                    foreach (var ep in show.Episodes.Where(e => e.Episode.OnlineStatusId == 1).OrderBy(ep => ep.Episode.DateAired))
                    {
                        var hlsAssets = from a in ep.Episode.PremiumAssets
                                        from ac in a.Asset.AssetCdns
                                        where ac.CdnId == 2
                                        select ac;

                        foreach (var ha in hlsAssets)
                        {                            
                            var cdnRef = ha.CdnReference;
                            var videoFile = cdnRef.Replace(",500000,800000,1000000,1300000,1500000,.mp4.csmil/master.m3u8", ".mp4");
                            videoFile = videoFile.Substring(videoFile.LastIndexOf('/') + 1).Replace(",", "");
                            if (!directoryList.Contains(videoFile))
                            {
                                Console.WriteLine("Disabling Episode: {0} {1} {2}", show.CategoryName, ep.Episode.Description, ep.Episode.DateAired);
                                ep.Episode.OnlineStatusId = 0;
                                ep.Episode.MobileStatusId = 0;
                                context.SaveChanges();
                            }

                        }

                    }
                }

            }

        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:50,代码来源:Program.cs

示例2: _SignUp

        public ActionResult _SignUp(FormCollection f)
        {
            var context = new IPTV2Entities();
            Dictionary<string, object> collection = new Dictionary<string, object>();
            if (String.IsNullOrEmpty(f["email"]))
            {
                collection.Add("errorCode", -1);
                collection.Add("errorMessage", "Please fill up your email address.");
                return Content(MyUtility.buildJson(collection), "application/json");
                // Do something
            }
            string email = f["email"];

            RegexUtilities util = new RegexUtilities();
            //if (!MyUtility.isEmail(email))
            if (!util.IsValidEmail(email))
            {
                collection.Add("errorCode", (int)ErrorCodes.IsNotValidEmail);
                collection.Add("errorMessage", "Invalid email format.");
                return Content(MyUtility.buildJson(collection), "application/json");
            }
            var tester = context.BetaTesters.FirstOrDefault(b => b.EMailAddress == email);
            if (tester == null) // New sign up
            {
                context.BetaTesters.Add(new BetaTester() { EMailAddress = email, DateSent = DateTime.Now, InvitationKey = System.Guid.NewGuid(), InvitedBy = System.Guid.Parse("9B4216E8-69BA-4548-9552-4CD065E58D3E") });
                int result = context.SaveChanges();
                if (result > 0)
                {
                    //Success
                    collection.Add("errorCode", 0);
                    collection.Add("errorMessage", "Thank you for signing up!");
                }
                else
                {
                    //Fail
                    collection.Add("errorCode", -2);
                    collection.Add("errorMessage", "The system encountered an unidentified error. Please try again.");
                }
            }
            else
            {
                // USer has signed up
                collection.Add("errorCode", -3);
                collection.Add("errorMessage", "You have already signed up.");
            }

            return Content(MyUtility.buildJson(collection), "application/json");
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:48,代码来源:BetaController.cs

示例3: _RegisterAndSubscribe


//.........这里部分代码省略.........
                            ReturnCode.StatusMessage = "We have detected that you have already registered using this machine.";
                            return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
                        }
                    }
                    catch (Exception) { }

                    string CurrencyCode = GlobalConfig.DefaultCurrency;
                    var country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0);
                    if (country != null)
                        CurrencyCode = country.CurrencyCode;
                    var wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0);
                    if (wallet == null) // Wallet does not exist. Create new wallet for User.
                    {
                        wallet = ContextHelper.CreateWallet(0, CurrencyCode, registDt);
                        user.UserWallets.Add(wallet);
                    }

                    var transaction = new RegistrationTransaction()
                    {
                        RegisteredState = user.State,
                        RegisteredCity = user.City,
                        RegisteredCountryCode = user.CountryCode,
                        Amount = 0,
                        Currency = CurrencyCode,
                        Reference = isSourceAir ? "New Registration (air)" : "New Registration",
                        Date = registDt,
                        OfferingId = GlobalConfig.offeringId,
                        UserId = user.UserId,
                        StatusId = GlobalConfig.Visible
                    };
                    user.Transactions.Add(transaction);

                    context.Users.Add(user);
                    if (context.SaveChanges() > 0)
                    {
                        string verification_email = String.Format("{0}/User/Verify?key={1}", GlobalConfig.baseUrl, user.ActivationKey.ToString());
                        if (isSourceAir)
                        {
                            try
                            {
                                verification_email = String.Format("{0}&source=air", verification_email);
                                var template = MyUtility.GetUrlContent(GlobalConfig.ProjectAirEmailVerificationBodyTemplateUrl);
                                var htmlBody = String.Format(template, FirstName, EMail, verification_email);
                                if (!Request.IsLocal)
                                    try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", htmlBody, MailType.HtmlOnly, String.Empty); }
                                    catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); }
                            }
                            catch (Exception)
                            {
                                string emailBody = String.Format(GlobalConfig.EmailVerificationBodyTextOnly, FirstName, EMail, verification_email);
                                if (!Request.IsLocal)
                                    try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody, MailType.TextOnly, emailBody); }
                                    catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); }
                            }
                        }
                        else
                        {
                            string emailBody = String.Format(GlobalConfig.EmailVerificationBodyTextOnly, FirstName, EMail, verification_email);
                            if (!Request.IsLocal)
                                try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody, MailType.TextOnly, emailBody); }
                                catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); }
                        }
                        GSResponse res = null;
                        if (!String.IsNullOrEmpty(uid) && !String.IsNullOrEmpty(provider))
                        {
                            Dictionary<string, object> collection = new Dictionary<string, object>();
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:67,代码来源:UserController.cs

示例4: _ResetYourPassword

        public ActionResult _ResetYourPassword(FormCollection fc)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("Index", "Home");

            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = String.Empty
            };

            string url = Url.Action("ResetPassword", "User").ToString();
            try
            {
                if (User.Identity.IsAuthenticated)
                    return RedirectToAction("Index", "Home");

                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 (String.IsNullOrEmpty(x.Value))
                    {
                        isMissingRequiredFields = true;
                        break;
                    }
                }

                if (!isMissingRequiredFields) // process form
                {
                    string NewPassword = tmpCollection["newPass"];
                    string CNewPassword = tmpCollection["cnewPass"];

                    string oid = tmpCollection["oid"];
                    string key = tmpCollection["key"];

                    //ViewBag.oid = oid;
                    //ViewBag.key = key;
                    //ViewBag.ts = MyUtility.ConvertToTimestamp(registDt);

                    Guid temp_key;
                    try
                    {
                        temp_key = Guid.Parse(key);
                    }
                    catch (Exception) { ReturnCode.StatusMessage = "The page you requested has an invalid key (key)."; }

                    url = Url.Action("ResetPassword", "User", new { key = key, oid = oid }).ToString();

                    if (String.Compare(NewPassword, CNewPassword, false) != 0)
                        ReturnCode.StatusMessage = "The passwords you entered do not match.";
                    else
                    {
                        using (var context = new IPTV2Entities())
                        {
                            var activation_key = new Guid(key);
                            User user = context.Users.FirstOrDefault(u => u.ActivationKey == activation_key);
                            if (user != null)
                            {
                                string oid_base = MyUtility.GetSHA1(String.Format("{0}{1}", user.UserId, user.LastUpdated));

                                if (registDt.Subtract(user.LastUpdated).TotalSeconds > 86400)
                                    ReturnCode.StatusMessage = "The page you requested has already expired.";
                                else if (String.Compare(oid, oid_base, true) != 0)
                                    ReturnCode.StatusMessage = "The page you requested has an invalid key (oid).";
                                else
                                {
                                    string hashedNewPassword = MyUtility.GetSHA1(NewPassword);
                                    user.Password = hashedNewPassword;
                                    user.LastUpdated = registDt;
                                    if (context.SaveChanges() > 0)
                                    {
                                        ReturnCode.StatusCode = (int)ErrorCodes.Success;
                                        ReturnCode.StatusHeader = "Reset Password Complete!";
                                        ReturnCode.StatusMessage = "You've successfully updated your password.";
                                        ReturnCode.StatusMessage2 = String.Empty;
                                        TempData["ErrorMessage"] = ReturnCode;
                                        return RedirectToAction("Index", "Home");  //Successful reset of password, redirect user login
                                    }
                                    else
                                        ReturnCode.StatusMessage = "We were unable to reset your password. Please try again.";
                                }
                            }
                            else
                                return RedirectToAction("ResetPassword", "User", new { key = key, oid = oid });
                        }
                    }
                    TempData["ErrorMessage"] = ReturnCode;
                    return RedirectToAction("ResetPassword", "User", new { key = key, oid = oid });
                }
                else
                    ReturnCode.StatusMessage = "Please fill in all required fields.";

                if (!String.IsNullOrEmpty(ReturnCode.StatusMessage))
                    TempData["ErrorMessage"] = ReturnCode.StatusMessage;

            }
            catch (Exception e) { MyUtility.LogException(e); ReturnCode.StatusMessage = "The system encountered an unspecified error."; }
//.........这里部分代码省略.........
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:101,代码来源:UserController.cs

示例5: ForgotPassword

        public ActionResult ForgotPassword(FormCollection fc)
        {
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = "The system encountered an unspecified error. Please contact Customer Support.",
                info = "Forget Password"
            };

            string url = Url.Action("Index", "Home").ToString();
            try
            {
                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 (String.IsNullOrEmpty(x.Value))
                    {
                        isMissingRequiredFields = true;
                        break;
                    }
                }

                if (!isMissingRequiredFields)
                {
                    string EmailAddress = fc["forgotpassword_email"];
                    var context = new IPTV2Entities();
                    var user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EmailAddress, true) == 0);
                    if (user == null)
                    {
                        ReturnCode.StatusCode = (int)ErrorCodes.UserDoesNotExist;
                        ReturnCode.StatusMessage = "User does not exist.";
                        TempData["ForgotPasswordErrorMessage"] = ReturnCode.StatusMessage;
                        return Redirect(Request.UrlReferrer.AbsoluteUri);
                    }

                    if (user.StatusId != 1)
                    {
                        ReturnCode.StatusCode = (int)ErrorCodes.UserDoesNotExist;
                        ReturnCode.StatusMessage = "Email address is not verified.";
                        TempData["ForgotPasswordErrorMessage"] = ReturnCode.StatusMessage;
                        return Redirect(Request.UrlReferrer.AbsoluteUri);
                    }

                    user.LastUpdated = registDt;
                    if (context.SaveChanges() > 0)
                    {
                        string oid = MyUtility.GetSHA1(String.Format("{0}{1}", user.UserId, user.LastUpdated));
                        string reset_pwd_email = String.Format("{0}/User/ResetPassword?key={1}&oid={2}", GlobalConfig.baseUrl, user.ActivationKey, oid.ToLower());
                        string emailBody = String.Format(GlobalConfig.ResetPasswordBodyTextOnly, user.FirstName, registDt.ToString("MM/dd/yyyy hh:mm:ss tt"), reset_pwd_email);
                        try
                        {
                            MyUtility.SendEmailViaSendGrid(user.EMail, GlobalConfig.NoReplyEmail, "Reset your TFC.tv Password", emailBody, MailType.TextOnly, emailBody);
                            ReturnCode.StatusCode = (int)ErrorCodes.Success;
                            ReturnCode.StatusMessage = "Instructions on how to reset your password have been sent to your email address.";
                        }
                        catch (Exception e)
                        {
                            MyUtility.LogException(e);
                            ReturnCode.StatusCode = (int)ErrorCodes.UnknownError;
                            ReturnCode.StatusMessage = "The system encountered an unspecified error. Please contact Customer Support.";
                            TempData["ForgotPasswordErrorMessage"] = ReturnCode.StatusMessage;
                            return Redirect(Request.UrlReferrer.AbsoluteUri);
                        }
                    }
                    else
                    {
                        ReturnCode.StatusCode = (int)ErrorCodes.UnknownError;
                        ReturnCode.StatusMessage = "The system was unable to process your request. Please try again later.";
                    }
                }
            }
            catch (Exception e) { MyUtility.LogException(e); }

            if (!String.IsNullOrEmpty(ReturnCode.StatusMessage))
                TempData["ForgotPasswordErrorMessage"] = ReturnCode.StatusMessage;
            url = Request.UrlReferrer.AbsoluteUri;
            return Redirect(url);
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:80,代码来源:UserController.cs

示例6: _EditUserProfile


//.........这里部分代码省略.........
                                    currentWallet.LastUpdated = registDt;
                                    var wallet = ContextHelper.CreateWallet(balance, newCurrencyCode, registDt);
                                    user.UserWallets.Add(wallet);
                                }
                            }
                            else  // new wallet currency exists, update the balance onl
                            {
                                if (String.Compare(newCurrencyCode, currentCurrencyCode, true) != 0)
                                {
                                    balance = Forex.Convert(context, currentWallet.Currency, newWallet.Currency, currentWallet.Balance);
                                    newWallet.Balance = balance;
                                    newWallet.IsActive = true;
                                    newWallet.LastUpdated = registDt;
                                    newWallet.GomsWalletId = null; // Reset Goms WalletId

                                    currentWallet.Balance = 0; // Deactivate old wallet
                                    currentWallet.IsActive = false; //Deactivate                                
                                    currentWallet.LastUpdated = registDt;
                                }
                                else
                                {
                                    newWallet.GomsWalletId = null;
                                    newWallet.LastUpdated = registDt;
                                }
                            }

                            ChangeCountryTransaction transaction = new ChangeCountryTransaction()
                            {
                                OldCountryCode = currentCountryCode,
                                NewCountryCode = newCountryCode,
                                Date = registDt,
                                OfferingId = GlobalConfig.offeringId,
                                Reference = "Change Country",
                                UserId = user.UserId,
                                Amount = 0,
                                NewWalletBalance = balance,
                                OldWalletBalance = currentWalletBalance,
                                OldGomsCustomerId = user.GomsCustomerId,
                                OldGomsWalletId = currentGomsWalletId,
                                Currency = currentCurrencyCode,
                                StatusId = GlobalConfig.Visible
                            };
                            user.Transactions.Add(transaction);
                            user.CountryCode = CountryCode;
                        }

                        if (!String.IsNullOrEmpty(ReturnCode.StatusMessage))
                        {
                            TempData["ErrorMessage"] = ReturnCode;
                            return RedirectToAction("EditYourProfile", "User");
                        }

                        user.State = State;
                        user.City = City;


                        if (context.SaveChanges() > 0)
                        {
                            setUserData(user.UserId.ToString(), user);
                            ReturnCode.StatusCode = (int)ErrorCodes.Success;
                            ReturnCode.StatusHeader = "Profile update complete!";
                            ReturnCode.StatusMessage = "You should see the changes on your profile automatically.";
                            ReturnCode.StatusMessage2 = String.Empty;
                            TempData["ErrorMessage"] = ReturnCode;
                            return RedirectToAction("Index", "Profile");
                        }
                        else
                            ReturnCode.StatusMessage = "Ooops! We encountered a problem updating your profile. Please try again later.";
                    }
                    else
                    {
                        user.City = City;
                        user.State = State;
                        if (context.SaveChanges() > 0)
                        {
                            setUserData(user.UserId.ToString(), user);
                            ReturnCode.StatusCode = (int)ErrorCodes.Success;
                            ReturnCode.StatusHeader = "Profile update complete!";
                            ReturnCode.StatusMessage = "You should see the changes on your profile automatically.";
                            ReturnCode.StatusMessage2 = String.Empty;
                            TempData["ErrorMessage"] = ReturnCode;
                            return RedirectToAction("Index", "Profile");
                        }
                        else
                            ReturnCode.StatusMessage = "The system encountered an unspecified error while updating your profile. Please contact support.";
                    }
                }
                else
                    ReturnCode.StatusMessage = "Please fill in all required fields.";

                TempData["ErrorMessage"] = ReturnCode;
                url = Request.UrlReferrer.AbsolutePath;
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException en)
            {
                MyUtility.LogException((Exception)en, string.Join(",", en.EntityValidationErrors).ToString());
            }
            catch (Exception e) { MyUtility.LogException(e); }
            return Redirect(url);
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:101,代码来源:UserController.cs

示例7: _LoginX

        public ActionResult _LoginX(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);

            if (MyUtility.isUserLoggedIn()) //User is logged in.
                return RedirectToAction("Index", "Home");

            try
            {
                ViewBag.IsTVEverywhere = false;
                string EmailAddress = fc["EmailAddress"];
                string Password = fc["Password"];

                if (String.IsNullOrEmpty(fc["EmailAddress"]))
                {
                    errorCode = ErrorCodes.IsMissingRequiredFields;
                    collection = MyUtility.setError(errorCode, "Email address is required.");
                    return Content(MyUtility.buildJson(collection), "application/json");
                }

                if (String.IsNullOrEmpty(fc["Password"]))
                {
                    errorCode = ErrorCodes.IsMissingRequiredFields;
                    collection = MyUtility.setError(errorCode, "Password is required.");
                    return Content(MyUtility.buildJson(collection), "application/json");
                }

                var context = new IPTV2Entities();
                var user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EmailAddress, true) == 0);

                if (user == null)
                    collection = MyUtility.setError(ErrorCodes.UserDoesNotExist);
                else
                {
                    //if (user.StatusId != 1 && user.DateVerified == null) // Not verified
                    if (user.StatusId != 1) // Not verified
                    {
                        errorCode = ErrorCodes.IsNotVerified;
                        collection = MyUtility.setError(errorCode, "Email is not verified.");
                        return Content(MyUtility.buildJson(collection), "application/json");
                    }

                    Password = MyUtility.GetSHA1(Password);
                    if (String.Compare(user.EMail, EmailAddress, true) == 0 && String.Compare(user.Password, Password, false) == 0)
                    {
                        Dictionary<string, object> userInfo = new Dictionary<string, object>();
                        userInfo.Add("firstName", user.FirstName);
                        userInfo.Add("lastName", user.LastName);
                        userInfo.Add("email", user.EMail);
                        Dictionary<string, object> gigyaCollection = new Dictionary<string, object>();
                        gigyaCollection.Add("siteUID", user.UserId);
                        gigyaCollection.Add("cid", "TFCTV - Login");
                        gigyaCollection.Add("sessionExpiration", "0");
                        gigyaCollection.Add("userInfo", MyUtility.buildJson(userInfo));
                        GSResponse res = GigyaHelpers.createAndSendRequest("socialize.notifyLogin", GigyaHelpers.buildParameter(gigyaCollection));
                        GigyaHelpers.setCookie(res, this.ControllerContext);
                        errorMessage = "Login successful!";
                        //Session.SessionID;
                        SetAutheticationCookie(user.UserId.ToString());
                        SetSession(user.UserId.ToString());
                        ContextHelper.SaveSessionInDatabase(context, user);
                        //FormsAuthentication.SetAuthCookie(user.UserId.ToString(), true);
                        collection = MyUtility.setError(ErrorCodes.Success, errorMessage);
                        var UserHostAddress = Request.GetUserHostAddressFromCloudflare();
                        collection.Add("info", String.Format("{0}|{1}|{2}|{3}|{4}", user.EMail, UserHostAddress, "Site", MyUtility.getCountry(UserHostAddress).getCode(), DateTime.Now.ToString("yyyyMMdd-HHmmss")));

                        //UPDATE: FEB18,2013 - If TVE cookie is valid, assign user who logged in as TVERegistrant
                        try
                        {
                            if (MyUtility.isTVECookieValid())
                            {
                                user.IsTVERegistrant = true;
                                context.SaveChanges();
                                MyUtility.RemoveTVECookie();
                            }
                            if (user.IsTVEverywhere == true)
                            {
                                collection.Add("href", "/TFCChannel");
                            }
                        }
                        catch (Exception) { }
                    }
                    else
                        collection = MyUtility.setError(ErrorCodes.IsWrongPassword);
                }
            }
            catch (Exception e)
            {
                collection = MyUtility.setError(ErrorCodes.UnknownError, e.Message);
                //Debug.WriteLine(e.InnerException); throw;
            }
            return Content(MyUtility.buildJson(collection), "application/json");
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:96,代码来源:UserController.cs

示例8: _SignIn

        public JsonResult _SignIn(FormCollection fc)
        {
            //Response.ContentType = "application/json";

            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = "The system encountered an unspecified error. Please contact Customer Support.",
                HtmlUri = ""
            };

            try
            {
                ViewBag.IsTVEverywhere = false;
                string EmailAddress = fc["EmailAddress"];
                string Password = fc["Password"];

                if (String.IsNullOrEmpty(fc["EmailAddress"]))
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.IsMissingRequiredFields;
                    ReturnCode.StatusMessage = "Email address is required.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                if (String.IsNullOrEmpty(fc["Password"]))
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.IsMissingRequiredFields;
                    ReturnCode.StatusMessage = "Password is required.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                if (!Request.IsAjaxRequest())
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.IsInvalidRequest;
                    ReturnCode.StatusMessage = "Your request is invalid.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                var context = new IPTV2Entities();

                if (User.Identity.IsAuthenticated)
                {
                    var UserId = new Guid(User.Identity.Name);
                    var tUser = context.Users.FirstOrDefault(u => u.UserId == UserId);
                    if (tUser != null)
                    {
                        ReturnCode.StatusCode = (int)ErrorCodes.Success;
                        ReturnCode.StatusMessage = "Login successful. Please wait while we redirect you...";
                        var UserHostAddress = Request.GetUserHostAddressFromCloudflare();
                        ReturnCode.info = String.Format("{0}|{1}|{2}|{3}|{4}", tUser.EMail, UserHostAddress, "Site", MyUtility.getCountry(UserHostAddress).getCode(), DateTime.Now.ToString("yyyyMMdd-HHmmss"));
                        //UPDATE: FEB18,2013 - If TVE cookie is valid, assign user who logged in as TVERegistrant
                        try
                        {
                            if (tUser.IsTVEverywhere == true)
                                ReturnCode.HtmlUri = "/TFCChannel";
                        }
                        catch (Exception) { }
                    }
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                var user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EmailAddress, true) == 0);
                if (user == null)
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.UserDoesNotExist;
                    ReturnCode.StatusMessage = "User does not exist.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                if (user.StatusId != GlobalConfig.Visible)
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.UserDoesNotExist;
                    ReturnCode.StatusMessage = "Email address is not verified.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

                Password = MyUtility.GetSHA1(Password);
                if (String.Compare(user.EMail, EmailAddress, true) == 0 && String.Compare(user.Password, Password, false) == 0)
                {
                    SendToGigya(user);
                    SetAutheticationCookie(user.UserId.ToString());
                    SetSession(user.UserId.ToString());
                    ContextHelper.SaveSessionInDatabase(context, user);
                    ReturnCode.StatusCode = (int)ErrorCodes.Success;
                    ReturnCode.StatusMessage = "Login successful. Please wait while we redirect you...";
                    var UserHostAddress = Request.GetUserHostAddressFromCloudflare();
                    ReturnCode.info = String.Format("{0}|{1}|{2}|{3}|{4}", user.EMail, UserHostAddress, "Site", MyUtility.getCountry(UserHostAddress).getCode(), DateTime.Now.ToString("yyyyMMdd-HHmmss"));
                    //UPDATE: FEB18,2013 - If TVE cookie is valid, assign user who logged in as TVERegistrant
                    try
                    {
                        if (MyUtility.isTVECookieValid())
                        {
                            user.IsTVERegistrant = true;
                            context.SaveChanges();
                            MyUtility.RemoveTVECookie();
                            ReturnCode.HtmlUri = "/RegisterTFCEverywhere";
                        }
                        if (user.IsTVEverywhere == true)
                            ReturnCode.HtmlUri = "/TFCChannel";
                    }
//.........这里部分代码省略.........
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:101,代码来源:UserController.cs

示例9: _ChangePassword

        public JsonResult _ChangePassword(FormCollection f)
        {
            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;
            string currentPassword = f["Password"];
            string newPassword = f["NewPassword"];
            string confirmPassword = f["ConfirmPassword"];

            if (String.IsNullOrEmpty(currentPassword) || String.IsNullOrEmpty(newPassword) || String.IsNullOrEmpty(confirmPassword))
            {
                errorMessage = "Please fill in the required fields.";
                collection = MyUtility.setError(ErrorCodes.IsMissingRequiredFields, errorMessage);
                return this.Json(collection, JsonRequestBehavior.AllowGet);
            }

            if (String.Compare(newPassword, confirmPassword, false) != 0)
            {
                errorMessage = "Password mismatch.";
                collection = MyUtility.setError(ErrorCodes.IsMismatchPassword, errorMessage);
                return this.Json(collection, JsonRequestBehavior.AllowGet);
            }

            try
            {
                System.Guid userId = System.Guid.Parse(User.Identity.Name);
                var context = new IPTV2Entities();
                User user = context.Users.FirstOrDefault(u => u.UserId == userId);
                if (user != null)
                {
                    string hashedPassword = MyUtility.GetSHA1(currentPassword);
                    string hashedNewPassword = MyUtility.GetSHA1(newPassword);
                    if (String.Compare(user.Password, hashedPassword, false) != 0)
                    {
                        errorMessage = "The current password you entered is incorrect. Please try again.";
                        collection = MyUtility.setError(ErrorCodes.IsMismatchPassword, errorMessage);
                        return this.Json(collection, JsonRequestBehavior.AllowGet);
                    }

                    user.Password = hashedNewPassword;
                    user.LastUpdated = registDt;

                    if (context.SaveChanges() > 0)
                    {
                        errorMessage = "Your password has been changed succcessfully.";
                        collection = MyUtility.setError(ErrorCodes.Success, errorMessage);
                    }
                    else
                    {
                        errorMessage = "The system encountered an unidentified error. Please try again.";
                        collection = MyUtility.setError(ErrorCodes.EntityUpdateError, errorMessage);
                    }
                }
            }
            catch (Exception e) { collection = MyUtility.setError(ErrorCodes.UnknownError, e.Message); }
            return this.Json(collection, JsonRequestBehavior.AllowGet);
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:59,代码来源:UserController.cs

示例10: Send


//.........这里部分代码省略.........
                        catch (Exception) { Console.WriteLine("Test Connect failed."); }

                        foreach (var i in recurringBillings)
                        {
                            var user = context.Users.FirstOrDefault(u => u.UserId == i.UserId);
                            var recurringBilling = context.RecurringBillings.Find(i.RecurringBillingId);
                            var product = context.Products.Find(i.ProductId);
                            Trace.TraceInformation(String.Format("Processing user {0} with productId {1}, endDate {2}", user.EMail, product.Description, i.EndDate));
                            try
                            {
                                ProductPrice priceOfProduct = context.ProductPrices.FirstOrDefault(p => p.CurrencyCode == user.Country.CurrencyCode && p.ProductId == product.ProductId);
                                if (priceOfProduct == null)
                                    priceOfProduct = context.ProductPrices.FirstOrDefault(p => p.CurrencyCode == DefaultCurrencyCode && p.ProductId == product.ProductId);

                                Purchase purchase = CreatePurchase(registDt, "Payment via Credit Card");
                                user.Purchases.Add(purchase);

                                PurchaseItem item = CreatePurchaseItem(user.UserId, product, priceOfProduct);
                                purchase.PurchaseItems.Add(item);

                                var cardType = user.CreditCards.LastOrDefault(c => c.StatusId == 1).CardType;
                                CreditCardPaymentTransaction transaction = new CreditCardPaymentTransaction()
                                {
                                    Amount = priceOfProduct.Amount,
                                    Currency = priceOfProduct.CurrencyCode,
                                    Reference = cardType.ToUpper(),
                                    Date = registDt,
                                    Purchase = purchase,
                                    OfferingId = offeringId,
                                    StatusId = 1
                                };

                                var response = gomsService.CreateOrderViaRecurringPayment(context, user.UserId, transaction);
                                if (response.IsSuccess)
                                {
                                    DateTime endDate = registDt;
                                    item.SubscriptionProduct = (SubscriptionProduct)product;
                                    if (item.SubscriptionProduct is PackageSubscriptionProduct)
                                    {
                                        PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product;

                                        foreach (var package in subscription.Packages)
                                        {
                                            string packageName = package.Package.Description;
                                            string ProductNameBought = packageName;

                                            PackageEntitlement currentPackage = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == package.PackageId);

                                            EntitlementRequest request = CreateEntitlementRequest(registDt, endDate, product, String.Format("{0}-{1}", "CC", cardType), response.TransactionId.ToString(), registDt);
                                            if (currentPackage != null)
                                            {
                                                request.StartDate = currentPackage.EndDate;
                                                currentPackage.EndDate = GetEntitlementEndDate(subscription.Duration, subscription.DurationType, ((currentPackage.EndDate > registDt) ? currentPackage.EndDate : registDt));

                                                endDate = currentPackage.EndDate;
                                                currentPackage.LatestEntitlementRequest = request;
                                                request.EndDate = endDate;
                                            }
                                            else
                                            {
                                                PackageEntitlement entitlement = CreatePackageEntitlement(request, subscription, package, registDt);
                                                request.EndDate = entitlement.EndDate;
                                                user.PackageEntitlements.Add(entitlement);
                                            }
                                            user.EntitlementRequests.Add(request);
                                            item.EntitlementRequest = request; //UPDATED: November 22, 2012                                        
                                        }

                                        recurringBilling.EndDate = endDate;
                                        recurringBilling.NextRun = endDate.AddDays(-3).Date;
                                        recurringBilling.UpdatedOn = registDt;
                                        recurringBilling.GomsRemarks = String.Empty;
                                        recurringBilling.NumberOfAttempts = 0;

                                    }
                                    Trace.TraceInformation(user.EMail + ": renewal process complete!");
                                }
                                else
                                {
                                    recurringBilling.GomsRemarks = response.StatusMessage;
                                    recurringBilling.NumberOfAttempts += 1;
                                    throw new Exception(user.EMail + ": " + response.StatusMessage);
                                }
                            }
                            catch (Exception e)
                            {
                                Trace.TraceError("INNER ERROR: " + e.Message);
                            }

                            if (context.SaveChanges() > 0)
                                Trace.TraceInformation("Saving changes...");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Trace.TraceError("ERROR: " + e.Message);
            }
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:101,代码来源:RecurringProcessor.cs

示例11: _EnterPromo

        public JsonResult _EnterPromo(FormCollection fc)
        {
            var ReturnCode = new TransactionReturnType()
            {
                StatusCode = (int)ErrorCodes.UnknownError,
                StatusMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError)
            };
            DateTime registDt = DateTime.Now;
            int promoID = GlobalConfig.TFCtvFirstYearAnniversaryPromoId;
            var userID = new System.Guid(User.Identity.Name);

            try
            {
                var context = new IPTV2Entities();
                Promo promo = context.Promos.FirstOrDefault(p => p.PromoId == promoID && p.StatusId == GlobalConfig.Visible && p.EndDate > registDt && p.StartDate < registDt);
                if (promo != null)
                {
                    UserPromo userPromo = context.UserPromos.FirstOrDefault(u => u.UserId == userID && u.PromoId == promoID);
                    if (userPromo == null)

                        userPromo = new UserPromo()
                        {
                            PromoId = promoID,
                            UserId = userID,
                            AuditTrail = new AuditTrail() { CreatedOn = DateTime.Now }
                        };
                    context.UserPromos.Add(userPromo);
                    if (context.SaveChanges() > 0)
                    {
                        ReturnCode.StatusCode = (int)ErrorCodes.Success;
                        ReturnCode.StatusMessage = "You have successfully joined the promo.";
                        //adds points for each presconnected SNS
                        var providers = GigyaMethods.GetUserInfoByKey(userID, "providers");
                        var providerList = providers.Split(',');
                        foreach (string p in providerList)
                        {
                            if (!(String.Compare(p, "site") == 0))
                            {
                                GigyaActionSingleAttribute actionAttribute = new GigyaActionSingleAttribute();
                                {
                                    actionAttribute.description = new List<string> { "You connected to " + p };
                                }
                                GigyaMethods.NotifyAction(userID, AnniversaryPromo.AnnivPromo_LinkingSNS.ToString(), actionAttribute);
                            }
                        }
                    }
                    else
                    {
                        ReturnCode.StatusCode = (int)ErrorCodes.UnknownError;
                        ReturnCode.StatusMessage = "You have already joined the promo.";
                    }
                }
            }
            catch (Exception e)
            {
                MyUtility.LogException(e);
            }
            return this.Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:59,代码来源:FanMobPromoController.cs

示例12: LogUserToPromo

        public JsonResult LogUserToPromo()
        {
            var ReturnCode = new TransactionReturnType()
                       {
                           StatusCode = (int)ErrorCodes.UnknownError,
                           StatusMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError)
                       };

            if (!Request.IsLocal)
                if (!Request.IsAjaxRequest())
                {
                    ReturnCode.StatusCode = (int)ErrorCodes.IsInvalidRequest;
                    ReturnCode.StatusMessage = "Your request is invalid.";
                    return Json(ReturnCode, JsonRequestBehavior.AllowGet);
                }

            if (!User.Identity.IsAuthenticated)
            {
                ReturnCode.StatusCode = (int)ErrorCodes.IsInvalidRequest;
                ReturnCode.StatusMessage = "Your request is invalid.";
                return Json(ReturnCode, JsonRequestBehavior.AllowGet);
            }
            try
            {
                var UserId = new Guid(User.Identity.Name);
                var registDt = DateTime.Now;
                var context = new IPTV2Entities();
                var user = context.Users.FirstOrDefault(u => u.UserId == UserId);
                if (user != null)
                {
                    var promo = context.Promos.FirstOrDefault(p => p.PromoId == GlobalConfig.ProjectAirPromoId && p.StartDate < registDt && p.EndDate > registDt && p.StatusId == GlobalConfig.Visible);
                    if (promo != null)
                    {
                        if (context.UserPromos.Count(p => p.PromoId == GlobalConfig.ProjectAirPromoId && p.UserId == user.UserId) <= 0)
                        {
                            var uObj = new UserPromo()
                            {
                                UserId = user.UserId,
                                PromoId = promo.PromoId,
                                AuditTrail = new AuditTrail() { CreatedOn = DateTime.Now }
                            };
                            context.UserPromos.Add(uObj);
                            if (context.SaveChanges() > 0)
                            {
                                ReturnCode.StatusCode = (int)ErrorCodes.Success;
                                ReturnCode.StatusMessage = "Success";
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MyUtility.LogException(e);
                ReturnCode.StatusMessage = e.Message;
            }
            return Json(ReturnCode, JsonRequestBehavior.AllowGet);
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:58,代码来源:AjaxController.cs

示例13: EditProfile


//.........这里部分代码省略.........
                        }

                        UserWallet currentWallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0);
                        if (currentWallet == null) //If no wallet, get default USD wallet.
                            currentWallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, GlobalConfig.DefaultCurrency, true) == 0);

                        string newCountryCode = fc["CountryCode"];
                        user.FirstName = fc["FirstName"];
                        user.LastName = fc["LastName"];
                        user.City = fc["City"];
                        user.State = String.IsNullOrEmpty(fc["State"]) || fc["State"] == "" ? (String.IsNullOrEmpty(fc["StateDD"]) ? user.State : fc["StateDD"]) : fc["State"];

                        country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, newCountryCode, true) == 0);
                        if (country != null)
                        {
                            Currency currency = country.Currency;
                            CurrencyCode = (currency == null) ? GlobalConfig.DefaultCurrency : currency.Code;
                        }

                        UserWallet wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0);
                        decimal balance = 0;
                        decimal oldWalletBalance = currentWallet.Balance;
                        string oldCurrency = currentWallet.Currency;
                        if (wallet == null) // Wallet does not exist. Create new wallet for User.
                        {
                            if (currentWallet != null)
                            {
                                balance = currentWallet.Currency != CurrencyCode ? Forex.Convert(context, currentWallet.Currency, CurrencyCode, currentWallet.Balance) : currentWallet.Balance;
                                //balance = currentWallet.Balance;
                                currentWallet.Balance = 0;
                                currentWallet.IsActive = false;
                                currentWallet.GomsWalletId = null; // Reset Goms WalletId
                                currentWallet.LastUpdated = registDt;
                            }
                            wallet = ContextHelper.CreateWallet(balance, CurrencyCode, registDt);
                            user.UserWallets.Add(wallet);
                        }
                        else // Wallet already exists. Update the balance only.
                        {
                            if (currentWallet.Currency != wallet.Currency)
                            {
                                balance = currentWallet.Currency != wallet.Currency ? Forex.Convert(context, currentWallet.Currency, wallet.Currency, currentWallet.Balance) : currentWallet.Balance;
                                wallet.Balance = balance;
                                //wallet.Balance += (currentWallet.Balance * 1);
                                wallet.IsActive = true;
                                wallet.LastUpdated = registDt;
                                wallet.GomsWalletId = null; // Reset Goms WalletId
                                currentWallet.Balance = 0; // Deactivate old wallet
                                currentWallet.IsActive = false; //Deactivate
                                currentWallet.GomsWalletId = null; // Reset Goms WalletId
                                currentWallet.LastUpdated = registDt;
                            }
                        }

                        user.CountryCode = newCountryCode; // Update user country
                        user.LastUpdated = registDt; // lastUpdate

                        if (OldCountryCode != newCountryCode)
                        {
                            ChangeCountryTransaction transaction = new ChangeCountryTransaction()
                            {
                                OldCountryCode = OldCountryCode,
                                NewCountryCode = newCountryCode,
                                Date = registDt,
                                OfferingId = GlobalConfig.offeringId,
                                Reference = "Change Country",
                                UserId = user.UserId,
                                Amount = 0,
                                NewWalletBalance = balance,
                                OldWalletBalance = oldWalletBalance,
                                Currency = oldCurrency,
                                StatusId = GlobalConfig.Visible
                            };

                            user.Transactions.Add(transaction);
                        }

                        if (context.SaveChanges() > 0)
                        {
                            //setUserData
                            setUserData(user.UserId.ToString(), user);

                            errorMessage = "Your information has been updated successfully.";
                            collection = MyUtility.setError(ErrorCodes.Success, errorMessage);
                        }
                        else
                        {
                            errorMessage = "Error in updating your profile.";
                            collection = MyUtility.setError(ErrorCodes.EntityUpdateError, errorMessage);
                        }
                    }
                }
                catch (Exception e)
                {
                    collection = MyUtility.setError(ErrorCodes.UnknownError, e.Message);
                }
            }

            return Content(MyUtility.buildJson(collection), "application/json");
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:101,代码来源:SynapseController.cs

示例14: Register


//.........这里部分代码省略.........
                    DateVerified = registDt
                };
                string CurrencyCode = GlobalConfig.DefaultCurrency;
                Country country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0);
                if (country != null)
                {
                    Currency currency = context.Currencies.FirstOrDefault(c => String.Compare(c.Code, country.CurrencyCode, true) == 0);
                    if (currency != null) CurrencyCode = currency.Code;
                }
                UserWallet wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0);
                if (wallet == null) // Wallet does not exist. Create new wallet for User.
                {
                    wallet = ContextHelper.CreateWallet(0, CurrencyCode, registDt);
                    user.UserWallets.Add(wallet);
                }

                var transaction = new RegistrationTransaction()
                {
                    RegisteredState = user.State,
                    RegisteredCity = user.City,
                    RegisteredCountryCode = user.CountryCode,
                    Amount = 0,
                    Currency = CurrencyCode,
                    Reference = "New Registration (Mobile)",
                    Date = registDt,
                    OfferingId = GlobalConfig.offeringId,
                    UserId = user.UserId,
                    StatusId = GlobalConfig.Visible
                };

                user.Transactions.Add(transaction);

                context.Users.Add(user);
                if (context.SaveChanges() > 0)
                {
                    if (!String.IsNullOrEmpty(fc["UID"]))
                    {
                        Dictionary<string, object> GigyaCollection = new Dictionary<string, object>();
                        collection.Add("uid", fc["UID"]);
                        collection.Add("siteUID", userId);
                        collection.Add("cid", String.Format("{0} - New User", fc["provider"]));
                        GSResponse res = GigyaHelpers.createAndSendRequest("socialize.notifyRegistration", GigyaHelpers.buildParameter(collection));
                    }
                    else
                    {
                        Dictionary<string, object> userInfo = new Dictionary<string, object>();
                        userInfo.Add("firstName", user.FirstName);
                        userInfo.Add("lastName", user.LastName);
                        userInfo.Add("email", user.EMail);
                        Dictionary<string, object> gigyaCollection = new Dictionary<string, object>();
                        gigyaCollection.Add("siteUID", user.UserId);
                        gigyaCollection.Add("cid", "TFCTV - Registration");
                        gigyaCollection.Add("sessionExpiration", "0");
                        gigyaCollection.Add("newUser", true);
                        gigyaCollection.Add("userInfo", MyUtility.buildJson(userInfo));
                        GSResponse res = GigyaHelpers.createAndSendRequest("socialize.notifyLogin", GigyaHelpers.buildParameter(gigyaCollection));
                        GigyaHelpers.setCookie(res, this.ControllerContext);
                    }

                    //setUserData
                    User usr = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EMail, true) == 0);
                    setUserData(usr.UserId.ToString(), usr);


                    if (usr.IsTVERegistrant == null || usr.IsTVERegistrant == false)
                    {
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:67,代码来源:SynapseController.cs

示例15: UsePrepaidCard


//.........这里部分代码省略.........
                        ServiceId = (int)user.GomsServiceId,
                        SubsidiaryId = (int)user.GomsSubsidiaryId,
                        WalletId = (int)user.GomsWalletId,
                        PhoenixId = transaction.TransactionId,
                        TransactionDate = transaction.Date,
                        Amount = (double)transaction.Amount
                        // TODO: use transactionID or use base number
                        // PhoenixId=(int)(DateTime.Now.Ticks - int.MaxValue),
                    };

                    if (transaction is PpcReloadTransaction)
                    {
                        var reloadTransaction = (PpcReloadTransaction)transaction;
                        req.PPCPin = reloadTransaction.ReloadPpc.Pin;
                        req.PPCSerial = reloadTransaction.ReloadPpc.SerialNumber;
                        req.CurrencyId = (int)context.Currencies.Find(reloadTransaction.ReloadPpc.Currency).GomsId;
                    }
                    else if (transaction is PpcPaymentTransaction)
                    {
                        var paymentTransaction = (PpcPaymentTransaction)transaction;

                        int currencyId = 0;
                        string curr = transaction.Currency;
                        if (transaction.Currency == "---")
                        {
                            currencyId = (int)paymentTransaction.User.Country.Currency.GomsId;
                            curr = paymentTransaction.User.Country.CurrencyCode;
                        }
                        else
                        {
                            currencyId = (int)context.Currencies.Find(paymentTransaction.Currency).GomsId;
                        }

                        req.PPCPin = paymentTransaction.SubscriptionPpc.Pin;
                        req.PPCSerial = paymentTransaction.SubscriptionPpc.SerialNumber;
                        req.CurrencyId = currencyId;

                        var item = paymentTransaction.Purchase.PurchaseItems.FirstOrDefault();
                        if (item != null)
                        {
                            var endDate = item.EntitlementRequest.EndDate;
                            var startDate = endDate;
                            switch (item.SubscriptionProduct.DurationType.ToUpper())
                            {
                                case "D":
                                    {
                                        startDate = endDate.AddDays(item.SubscriptionProduct.Duration * -1);
                                        break;
                                    };
                                case "M":
                                    {
                                        startDate = endDate.AddMonths(item.SubscriptionProduct.Duration * -1);
                                        break;
                                    };
                                case "Y":
                                    {
                                        startDate = endDate.AddYears(item.SubscriptionProduct.Duration * -1);
                                        break;
                                    };
                                default:
                                    {
                                        break;
                                    }
                            }

                            req.SubscriptionStartDate = startDate;
                            req.SubscriptionEndDate = endDate;
                        }
                    }
                    else
                    {
                        throw new GomsInvalidTransactionTypeException();
                    }

                    try
                    {
                        result = _serviceClient.ConsumePrepaidCard(req);
                        if (result.IsSuccess)
                        {
                            transaction.GomsTransactionId = result.TransactionId;
                            transaction.GomsTransactionDate = DateTime.Now;
                            context.SaveChanges();
                        }
                    }
                    catch (Exception e)
                    {
                        throw new GomsServiceCallException(e.Message);
                    }
                }
                else
                {
                    throw new GomsInvalidTransactionTypeException();
                }
            }
            catch (GomsException e)
            {
                result = new RespConsumePrepaidCard { IsSuccess = false, StatusCode = e.StatusCode, StatusMessage = e.StatusMessage };
            }
            return (result);
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:101,代码来源:GomsTfctv.cs


注:本文中的IPTV2_Model.IPTV2Entities.SaveChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。