本文整理汇总了C#中Microsoft.AspNet.Identity.IdentityResult类的典型用法代码示例。如果您正苦于以下问题:C# IdentityResult类的具体用法?C# IdentityResult怎么用?C# IdentityResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdentityResult类属于Microsoft.AspNet.Identity命名空间,在下文中一共展示了IdentityResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetErrorResult
private IHttpActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
return InternalServerError();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("",error);
}
}
if (ModelState.IsValid)
{
//No Modelstate errors are available to send so just return bad request
return BadRequest();
}
return BadRequest(ModelState);
}
return null;
throw new NotImplementedException();
}
示例2: AddErrors
private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
示例3: GetErrorResult
private IHttpActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
return InternalServerError();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (String error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
if (ModelState.IsValid)
{
//Ingen fejlkode, derfor sendes der bare en badrequest
return BadRequest();
}
}
return null;
}
示例4: GetErrorResult
protected IHttpActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
return this.InternalServerError();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (var error in result.Errors)
{
this.ModelState.AddModelError(string.Empty, error);
}
}
if (this.ModelState.IsValid)
{
return this.BadRequest();
}
return this.BadRequest(this.ModelState);
}
return null;
}
示例5: GetErrorResult
//rolling up error message to return error result
private IHttpActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
return InternalServerError();
}
if(!result.Succeeded)
{
if (result.Errors != null)
{
foreach (string error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
if (ModelState.IsValid)
{
//no model state errors available to send, just send bad request
return BadRequest();
}
return BadRequest(ModelState);
}
return null;
}
示例6: ValidarErroresResultado
/// <summary>
/// Método que realiza la validación de errores que se puedan presentar durante el proceso
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
private IHttpActionResult ValidarErroresResultado(IdentityResult result)
{
if (result == null)
{
return InternalServerError();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (string error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
if (ModelState.IsValid)
{
// Se retorna simplemente un bad request en caso de que no se encuentre un state valido
return BadRequest();
}
//Se retorna la información con el error
return BadRequest(ModelState);
}
return null;
}
示例7: GetErrorResult
private IHttpActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
return InternalServerError();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (string error in result.Errors)
{
ModelState.AddModelError("error", error);
}
}
if (ModelState.IsValid)
{
// Ошибки ModelState для отправки отсутствуют, поэтому просто возвращается пустой BadRequest.
return BadRequest();
}
return BadRequest(ModelState);
}
return null;
}
示例8: AddErrors
private static void AddErrors(IdentityResult result, ModelMethodContext context)
{
foreach (var error in result.Errors)
{
context.ModelState.AddModelError("", error);
}
}
示例9: GetErrorResult
protected IHttpActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
return InternalServerError();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (string error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
if (ModelState.IsValid)
{
// No ModelState errors are available to send, so just return an empty BadRequest.
return BadRequest();
}
return BadRequest(ModelState);
}
return null;
}
示例10: AddErrors
private void AddErrors(IdentityResult result)
{
foreach (string str in result.Errors)
{
base.ModelState.AddModelError("", str);
}
}
示例11: AddErrorsFromResult
private void AddErrorsFromResult(IdentityResult result)
{
foreach (string error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
示例12: IsFailure
public static void IsFailure(IdentityResult result, IdentityError error)
{
Assert.NotNull(result);
Assert.False(result.Succeeded);
Assert.Equal(error.Description, result.Errors.First().Description);
Assert.Equal(error.Code, result.Errors.First().Code);
}
示例13: AddErrors
protected void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
this.ModelState.AddModelError(string.Empty, error);
}
}
示例14: GetErrorResult
private IHttpActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
return InternalServerError();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (string error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
if (ModelState.IsValid)
{
// No ModelState errors to send, so send a Bad Request
return BadRequest();
}
// Return the errors
return BadRequest(ModelState);
}
return null;
}
示例15: RegisterCustomerAsync
public async Task<IdentityResult> RegisterCustomerAsync(UserModel userModel, AppRole appRole = AppRole.customer)
{
var addToRoleResult = new IdentityResult();
// Add generate username to the model
IdentityUser user = new IdentityUser
{
UserName = userModel.UserName,
Email = userModel.EmailAddress,
EmailConfirmed = true,
PhoneNumber = userModel.PhoneNumber,
PhoneNumberConfirmed = true,
};
var result = await _userManager.CreateAsync(user, userModel.Password);
//Role-user combination is managed as Contact-Role combination in ContactRole table
//Create Role Admin if it does not exist
var _role = await _roleManager.FindByNameAsync(appRole.ToString());
if (_role == null)
{
_role = new IdentityRole(appRole.ToString());
var roleresult = await _roleManager.CreateAsync(_role);
}
var rolesForUser = await _userManager.GetRolesAsync(user.Id);
if (!rolesForUser.Contains(_role.Name))
{
addToRoleResult = await _userManager.AddToRoleAsync(user.Id, _role.Name);
}
return addToRoleResult;
}