// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Identity
{
///
/// Represents the result of an identity operation
///
public class IdentityResult
{
private static readonly IdentityResult _success = new IdentityResult { Succeeded = true };
private List _errors = new List();
///
/// True if the operation was successful
///
public bool Succeeded { get; protected set; }
///
/// List of errors
///
public IEnumerable Errors => _errors;
///
/// Static success result
///
///
public static IdentityResult Success => _success;
///
/// Failed helper method
///
///
///
public static IdentityResult Failed(params IdentityError[] errors)
{
var result = new IdentityResult { Succeeded = false };
if (errors != null)
{
result._errors.AddRange(errors);
}
return result;
}
///
/// Return string representation of IdentityResult
///
/// "Succedded", if result is suceeded else "Failed:error codes"
public override string ToString()
{
return Succeeded ?
"Succeeded" :
string.Format("{0} : {1}", "Failed", string.Join(",", Errors.Select(x => x.Code).ToList()));
}
///
/// Get the level to log this result
///
/// LogLevel to log
public virtual LogLevel GetLogLevel()
{
return Succeeded ? LogLevel.Verbose : LogLevel.Warning;
}
}
}