本文整理汇总了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 });
}
示例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);
}
}
示例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});
}