Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions EsiaNET/EsiaClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,60 @@ public static async Task<IEnumerable<VehicleInfo>> GetPersonVehiclesAsync(this E

return result;
}

/// <summary>
/// Get vehicles of authorized user
/// </summary>
/// <param name="client"></param>
/// <returns>VehicleInfo array</returns>
public static Task<IEnumerable<PersonRole>> GetPersonRolesAsync(this EsiaClient client)
{
if (client.Token == null)
{
throw new ArgumentNullException("Token");
}

return client.GetPersonRolesAsync(client.Token.SbjId);
}

/// <summary>
/// Get person roles of specified user
/// </summary>
/// <param name="client"></param>
/// <param name="oid">User oid</param>
/// <returns>VehicleInfo array</returns>
public static async Task<IEnumerable<PersonRole>> GetPersonRolesAsync(this EsiaClient client, string oid)
{
if (string.IsNullOrEmpty(oid))
{
throw new ArgumentNullException(nameof(oid));
}

var uri = $"{EsiaHelpers.NormalizeUri(client.Options.RestUri, client.Options.PrnsSfx)}{oid}/roles";
var result = new List<PersonRole>();
var response = await client.GetAsync(uri);

if (response == null)
{
return result;
}

IDictionary<string, JToken> vehicleDictionary = JObject.Parse(response);

if (!vehicleDictionary.ContainsKey("elements"))
{
return result;
}

foreach ( var vehicle in vehicleDictionary["elements"] )
{
if (vehicle is JObject personRole)
{
result.Add(new PersonRole(personRole));
}
}

return result;
}
}
}
6 changes: 6 additions & 0 deletions EsiaNET/EsiaHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public static string PropertyValueIfExists(string property, IDictionary<string,
{
return dictionary.ContainsKey(property) ? dictionary[property].ToString() : null;
}
public static bool PropertyBoolValueIfExists(string property, IDictionary<string, JToken> dictionary)
{
var value = PropertyValueIfExists(property, dictionary);

return !string.IsNullOrWhiteSpace(value) && value.ToLowerInvariant() == "true";
}

public static DateTime DateFromUnixSeconds(double seconds)
{
Expand Down
104 changes: 104 additions & 0 deletions EsiaNET/PersonRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using Newtonsoft.Json.Linq;

namespace EsiaNET
{
/// <summary>
/// Provides personal role information
/// </summary>
public class PersonRole
{
internal PersonRole(JObject personRole)
{
if (personRole == null)
{
return;
}

Oid = Convert.ToInt64(EsiaHelpers.PropertyValueIfExists("oid", personRole));
PersonOid = Convert.ToInt64(EsiaHelpers.PropertyValueIfExists("prnOid", personRole));
FullName = EsiaHelpers.PropertyValueIfExists("fullName", personRole);
ShortName = EsiaHelpers.PropertyValueIfExists("shortName", personRole);
Ogrn = EsiaHelpers.PropertyValueIfExists("ogrn", personRole);
Type = EsiaHelpers.PropertyValueIfExists("type", personRole);
Chief = EsiaHelpers.PropertyBoolValueIfExists("chief", personRole);
Admin = EsiaHelpers.PropertyBoolValueIfExists("admin", personRole);
Phone = EsiaHelpers.PropertyValueIfExists("phone", personRole);
Email = EsiaHelpers.PropertyValueIfExists("email", personRole);
Active = EsiaHelpers.PropertyBoolValueIfExists("active", personRole);
HasRightOfSubstitution = EsiaHelpers.PropertyBoolValueIfExists("hasRightOfSubstitution", personRole);
HasApprovalTabAccess = EsiaHelpers.PropertyBoolValueIfExists("hasApprovalTabAccess", personRole);
IsLiquidated = EsiaHelpers.PropertyBoolValueIfExists("isLiquidated", personRole);
}

/// <summary>
/// Organization identifier
/// </summary>
public long Oid { get; set; }

/// <summary>
/// Person Organization identifier
/// </summary>
public long PersonOid { get; set; }

/// <summary>
/// Full name for organization
/// </summary>
public string FullName { get; set; }

/// <summary>
/// Short name for organization
/// </summary>
public string ShortName { get; set; }

/// <summary>
/// Ogrn
/// </summary>
public string Ogrn { get; set; }

/// <summary>
/// Type for organization
/// </summary>
public string Type { get; set; }

/// <summary>
/// Chief current organization
/// </summary>
public bool Chief { get; set; }

/// <summary>
/// Administrator for current organization
/// </summary>
public bool Admin { get; set; }

/// <summary>
/// Contact phone number
/// </summary>
public string Phone { get; set; }

/// <summary>
/// Contact Email
/// </summary>
public string Email { get; set; }

/// <summary>
/// Flag determinate what a company have active status
/// </summary>
public bool Active { get; set; }

/// <summary>
/// Flag determinate what a company has right of substitution
/// </summary>
public bool? HasRightOfSubstitution { get; set; }

/// <summary>
/// Flag determinate what a company has approval tab access
/// </summary>
public bool HasApprovalTabAccess { get; set; }

/// <summary>
/// Flag determinate what a company is liquidated
/// </summary>
public bool IsLiquidated { get; set; }
}
}