init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue