93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Kreta.Naplo.Infrastructure;
|
|
|
|
namespace Kreta.Naplo.Domain
|
|
{
|
|
/// <summary>
|
|
/// Service contect
|
|
/// </summary>
|
|
public class ServiceContext
|
|
{
|
|
/// <summary>
|
|
/// Institute code
|
|
/// </summary>
|
|
public string InstituteCode { get; }
|
|
|
|
/// <summary>
|
|
/// User identitier
|
|
/// </summary>
|
|
public int UserId { get; }
|
|
|
|
/// <summary>
|
|
/// User roles
|
|
/// </summary>
|
|
public IEnumerable<string> UserRoles { get; }
|
|
|
|
/// <summary>
|
|
/// Base url
|
|
/// </summary>
|
|
public string BaseUrl { get; }
|
|
public int SchoolYearId { get; }
|
|
|
|
/// <summary>
|
|
/// Api key
|
|
/// </summary>
|
|
public string ApiKey { get; }
|
|
|
|
/// <summary>
|
|
/// User agent
|
|
/// </summary>
|
|
public string UserAgent { get; }
|
|
|
|
/// <summary>
|
|
/// Constuctor
|
|
/// </summary>
|
|
/// <param name="instituteCode">Institute code</param>
|
|
/// <param name="userId">User Id</param>
|
|
/// <param name="userRoles">User roles</param>
|
|
/// <param name="baseUrl">Base url</param>
|
|
/// <param name="apiKey">Api key</param>
|
|
/// <param name="userAgent">User Agent</param>
|
|
public ServiceContext(string instituteCode, int userId, IEnumerable<string> userRoles, string baseUrl, string apiKey, string userAgent, int schoolYearId)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(instituteCode))
|
|
{
|
|
throw new ArgumentException($"{nameof(InstituteCode)} cannot be null or white space");
|
|
}
|
|
|
|
this.InstituteCode = instituteCode;
|
|
|
|
if (userId < Constants.MinimumPrimaryKeyValue)
|
|
{
|
|
throw new ArgumentException($"{nameof(userId)} must be greater or equal than {Constants.MinimumPrimaryKeyValue}");
|
|
}
|
|
|
|
if (schoolYearId < Constants.MinimumPrimaryKeyValue)
|
|
{
|
|
throw new ArgumentException($"{nameof(schoolYearId)} must be greater or equal than {Constants.MinimumPrimaryKeyValue}");
|
|
}
|
|
this.SchoolYearId = schoolYearId;
|
|
|
|
this.UserId = userId;
|
|
|
|
this.UserRoles = userRoles ?? throw new ArgumentNullException(nameof(userRoles));
|
|
|
|
if (string.IsNullOrWhiteSpace(baseUrl))
|
|
{
|
|
throw new ArgumentException($"{nameof(baseUrl)} cannot be null or white space");
|
|
}
|
|
|
|
this.BaseUrl = baseUrl;
|
|
|
|
if (string.IsNullOrWhiteSpace(apiKey))
|
|
{
|
|
throw new ArgumentException($"{nameof(apiKey)} cannot be null or white space");
|
|
}
|
|
|
|
this.ApiKey = apiKey;
|
|
|
|
UserAgent = userAgent ?? throw new ArgumentNullException(nameof(userAgent));
|
|
}
|
|
}
|
|
}
|