Esempio n. 1
0
        //GET : Account/IsAdmin
        public async Task <ActionResult> IsAdmin()
        {
            IsAdminBindingModel Model    = new IsAdminBindingModel();
            HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync("api/Role/IsAdmin");

            if (response.IsSuccessStatusCode)
            {
                Model = await response.Content.ReadAsAsync <IsAdminBindingModel>();

                UserInfo.IsAdmin = Model.IsAdmin;
                return(RedirectToAction("Users"));
            }
            else if (response.StatusCode == HttpStatusCode.Unauthorized)
            {
                return(View("Unauthorized"));
            }
            else if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(View("NotFound"));
            }
            else
            {
                return(View("SomethingWrong"));
            }
        }
Esempio n. 2
0
        public IHttpActionResult IsAdmin()
        {
            IsAdminBindingModel Model = new IsAdminBindingModel();
            var UserID = User.Identity.GetUserId();

            //var RolesForUser = await UserManager.GetRolesAsync(UserID);
            //var IsInRole =  UserManager.IsInRole(UserID, "admin");
            Model.IsAdmin = UserManager.IsInRole(UserID, "admin");
            return(Ok(Model));
        }