public void OnAuthorization(AuthorizationFilterContext context)
 {
     if (context.HttpContext.User.Claims.Count() != 0)
     {
         var user = userService.CheckExistUser(int.Parse(context.HttpContext.User.Claims.Single(u => u.Type == "userId").Value));
         if (user == null)
         {
             context.Result = new JsonResult("User not found")
             {
                 StatusCode = 401
             };
             return;
         }
     }
     else
     {
         context.HttpContext.Request.Headers.TryGetValue("DeviceId", out var deviceId);
         var guest = guestService.CheckExistGuest(deviceId.ToString());
         if (!guest)
         {
             context.Result = new JsonResult("Guest not found")
             {
                 StatusCode = 401
             };
             return;
         }
     }
 }
Example #2
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            context.HttpContext.Request.Headers.TryGetValue("DeviceId", out var deviceId);
            var guest = guestService.CheckExistGuest(deviceId.ToString());

            if (!guest)
            {
                context.Result = new JsonResult("Guest not found")
                {
                    StatusCode = 401
                };
                return;
            }
        }