37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using System;
|
|
using System.Web;
|
|
using Kreta.BusinessLogic.Classes.MobileApi.Common.Co;
|
|
|
|
namespace Kreta.Web.Areas.MobileApi.ModelConverter
|
|
{
|
|
public static class MobileUserModelConverter
|
|
{
|
|
/// <summary>
|
|
/// Try get mobile user from http context
|
|
/// </summary>
|
|
/// <param name="mobileUser">Mobile user</param>
|
|
/// <returns>True if mobile user exists</returns>
|
|
public static bool TryLoadFromHttpContext(out MobileUser mobileUser)
|
|
{
|
|
mobileUser = (MobileUser)HttpContext.Current?.Items?[nameof(MobileUser)];
|
|
return mobileUser != null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Try get mobile user from http context
|
|
/// </summary>
|
|
/// <param name="mobileUser">Mobile user</param>
|
|
/// <returns>True if mobile user exists</returns>
|
|
public static MobileUser GetFromHttpContext()
|
|
{
|
|
MobileUser user;
|
|
|
|
if (!TryLoadFromHttpContext(out user))
|
|
{
|
|
throw new InvalidOperationException($"There is no existing mobile user in http context {nameof(MobileUser)}");
|
|
}
|
|
|
|
return user;
|
|
}
|
|
}
|
|
}
|