本文整理汇总了C#中ObservableCollection.Patch方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Patch方法的具体用法?C# ObservableCollection.Patch怎么用?C# ObservableCollection.Patch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Patch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateAsync
public async Task<IHttpActionResult> UpdateAsync(ApplicationUserExtended user)
{
var dbUser = await UserManager.FindByIdAsync(user.Id);
dbUser.InjectFrom(user);
foreach (var login in user.Logins)
{
var userLogin = dbUser.Logins.FirstOrDefault(l => l.LoginProvider == login.LoginProvider);
if (userLogin != null)
{
userLogin.ProviderKey = login.ProviderKey;
}
else
{
dbUser.Logins.Add(new Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin
{
LoginProvider = login.LoginProvider,
ProviderKey = login.ProviderKey,
UserId = dbUser.Id
});
}
}
var result = await UserManager.UpdateAsync(dbUser);
if (result.Succeeded)
{
using (var repository = _platformRepository())
{
var acount = repository.GetAccountByName(user.UserName, UserDetails.Full);
if (acount == null)
{
return BadRequest("Acount not found");
}
acount.RegisterType = (RegisterType)user.UserType;
acount.AccountState = (AccountState)user.UserState;
acount.MemberId = user.MemberId;
acount.StoreId = user.StoreId;
if (user.ApiAcounts != null)
{
var source = new ObservableCollection<ApiAccountEntity>(user.ApiAcounts.Select(x => x.ToFoundation()));
var inventoryComparer = AnonymousComparer.Create((ApiAccountEntity x) => x.Id);
acount.ApiAccounts.ObserveCollection(x => repository.Add(x), x => repository.Remove(x));
source.Patch(acount.ApiAccounts, inventoryComparer, (sourceAccount, targetAccount) => sourceAccount.Patch(targetAccount));
}
if (user.Roles != null)
{
var sourceCollection = new ObservableCollection<RoleAssignmentEntity>(user.Roles.Select(r => new RoleAssignmentEntity { RoleId = r.Id }));
var comparer = AnonymousComparer.Create((RoleAssignmentEntity x) => x.RoleId);
acount.RoleAssignments.ObserveCollection(ra => repository.Add(ra), ra => repository.Remove(ra));
sourceCollection.Patch(acount.RoleAssignments, comparer, (source, target) => source.Patch(target));
}
repository.UnitOfWork.Commit();
}
return Ok();
}
return BadRequest(String.Join(" ", result.Errors));
}
示例2: UpdateAsync
public async Task<SecurityResult> UpdateAsync(ApplicationUserExtended user)
{
SecurityResult result = null;
if (user != null)
{
var dbUser = await _userManager.FindByIdAsync(user.Id);
result = ValidateUser(dbUser);
if (result.Succeeded)
{
dbUser.InjectFrom(user);
if (user.Logins != null)
{
foreach (var login in user.Logins)
{
var userLogin = dbUser.Logins.FirstOrDefault(l => l.LoginProvider == login.LoginProvider);
if (userLogin != null)
{
userLogin.ProviderKey = login.ProviderKey;
}
else
{
dbUser.Logins.Add(new IdentityUserLogin
{
LoginProvider = login.LoginProvider,
ProviderKey = login.ProviderKey,
UserId = dbUser.Id
});
}
}
}
var identityResult = await _userManager.UpdateAsync(dbUser);
result = identityResult.ToCoreModel();
if (result.Succeeded)
{
using (var repository = _platformRepository())
{
var acount = repository.GetAccountByName(user.UserName, UserDetails.Full);
if (acount == null)
{
result = new SecurityResult { Errors = new[] { "Acount not found." } };
}
else
{
acount.RegisterType = (RegisterType)user.UserType;
acount.AccountState = (AccountState)user.UserState;
acount.MemberId = user.MemberId;
acount.StoreId = user.StoreId;
if (user.ApiAcounts != null)
{
var sourceCollection = new ObservableCollection<ApiAccountEntity>(user.ApiAcounts.Select(x => x.ToEntity()));
var comparer = AnonymousComparer.Create((ApiAccountEntity x) => x.Id);
acount.ApiAccounts.ObserveCollection(x => repository.Add(x), x => repository.Remove(x));
sourceCollection.Patch(acount.ApiAccounts, comparer, (sourceItem, targetItem) => sourceItem.Patch(targetItem));
}
if (user.Roles != null)
{
var sourceCollection = new ObservableCollection<RoleAssignmentEntity>(user.Roles.Select(r => new RoleAssignmentEntity { RoleId = r.Id }));
var comparer = AnonymousComparer.Create((RoleAssignmentEntity x) => x.RoleId);
acount.RoleAssignments.ObserveCollection(x => repository.Add(x), ra => repository.Remove(ra));
sourceCollection.Patch(acount.RoleAssignments, comparer, (sourceItem, targetItem) => sourceItem.Patch(targetItem));
}
repository.UnitOfWork.Commit();
}
}
}
}
}
return result;
}