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


C# IGenericRepository.Update方法代码示例

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


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

示例1: Disassociate

        public ActionResult Disassociate(string provider, string providerUserId)
        {
            var ownerAccount = OAuthWebSecurity.GetUserName(provider, providerUserId);
            ManageMessageId? message = null;

            // Only disassociate the account if the currently logged in user is the owner
            if (ownerAccount == User.Identity.Name)
            {
                var user = _userRepository.Find(x => x.UserName.ToLower() == ownerAccount.ToLower());
                // Use a transaction to prevent the user from deleting their last login credential
                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
                {
                    var hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(ownerAccount));
                    if (hasLocalAccount || OAuthWebSecurity.GetAccountsFromUserName(ownerAccount).Count > 1)
                    {
                        if (user != null)
                        {
                            if (provider.Equals("facebook"))
                            {
                                user.FbVerified = false;
                            }
                            if(provider.Equals("twitter"))
                            {
                                user.TwitterVerified = false;
                            }
                        }
                        OAuthWebSecurity.DeleteAccount(provider, providerUserId);
                        scope.Complete();
                        message = ManageMessageId.RemoveLoginSuccess;
                    }
                }
                using (var uow = new UnitOfWork())
                {
                    using (_userRepository = new GenericRepository<UserProfile>(uow))
                    {
                        _userRepository.Update(user);
                    }
                    uow.Save();
                }
            }

            return RedirectToAction("Manage", new { Message = message });
        }
开发者ID:jknopp,项目名称:HypeTheFest,代码行数:43,代码来源:AccountController.cs

示例2: EditItem

        public void EditItem(long id)
        {
            _useRepository = new UserRepository();
            using (_useRepository)
            {
                var item = _useRepository.Get(id);

                if (item == null)
                {
                    Response.Error404();
                    return;
                }

                TryUpdateModel(item);

                if (!ModelState.IsValid) return;
                // Save changes here
                _useRepository.Update(item);
                Response.RedirectPermanent(Request.Url.AbsoluteUri);
            }
        }
开发者ID:rabbal,项目名称:AspNetWebForms-Forum,代码行数:21,代码来源:PublicProfile.aspx.cs

示例3: ExternalLoginCallback

        public ActionResult ExternalLoginCallback(string returnUrl)
        {
            var externalLoginModel = new ExternalLoginModel();

            var result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
            if (!result.IsSuccessful)
            {
                return RedirectToAction("ExternalLoginFailure");
            }

            if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, false))
            {
                //ModelState.AddModelError("", "This external account is already associated with your account.");
                return RedirectToLocal(returnUrl);
            }

            switch (result.Provider)
            {
                case "facebook":
                    externalLoginModel.UserName = result.UserName;
                    externalLoginModel.DisplayName = result.ExtraData["name"];
                    if (result.ExtraData.Keys.Contains("accesstoken"))
                    {
                        var facebookClient = new Facebook.FacebookClient(result.ExtraData["accesstoken"]);
                        dynamic response = facebookClient.Get("me", new { fields = "verified" });
                        externalLoginModel.FbVerified = response.ContainsKey("verified") && response["verified"];
                    }

                    break;
                case "twitter":
                    externalLoginModel.UserName = "";
                    externalLoginModel.DisplayName = result.UserName;
                    if (result.ExtraData.Keys.Contains("accesstoken") && result.ExtraData.Keys.Contains("accesssecret"))
                    {
                        var twitterClient = new Twitter(ConfigurationManager.AppSettings["TwitterConsumerKey"], ConfigurationManager.AppSettings["TwitterConsumerSecret"], result.ExtraData["accesstoken"], result.ExtraData["accesssecret"]);
                        externalLoginModel.TwitterVerified = twitterClient.VerifyCredentials();
                    }
                    break;
                case "google":
                    externalLoginModel.UserName = result.UserName;
                    externalLoginModel.DisplayName = result.UserName;
                    break;
                default:
                    externalLoginModel.UserName = "";
                    externalLoginModel.DisplayName = "";
                    break;
            }

            if (User.Identity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    var user = _userRepository.Find(x => x.UserName.ToLower() == User.Identity.Name.ToLower());
                    if (user != null)
                    {
                        if (externalLoginModel.FbVerified)
                        {
                            user.FbVerified = true;
                        }
                        if (externalLoginModel.TwitterVerified)
                        {
                            user.TwitterVerified = true;
                        }
                        using (var uow = new UnitOfWork())
                        {

                            using (_userRepository = new GenericRepository<UserProfile>(uow))
                            {
                                    _userRepository.Update(user);
                            }
                            uow.Save();
                        }
                    }
                }
                // If the current user is logged in add the new account
                OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name);
                return RedirectToLocal(returnUrl);
            }
            // User is new, ask for their desired membership name
            var loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;

            return View("ExternalLoginConfirmation", new RegisterExternalLoginModel { UserName = externalLoginModel.UserName, ExternalLoginData = loginData, DisplayName = externalLoginModel.DisplayName, FbVerified = externalLoginModel.FbVerified, TwitterVerified = externalLoginModel.TwitterVerified});
        }
开发者ID:jknopp,项目名称:HypeTheFest,代码行数:85,代码来源:AccountController.cs


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