init
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user