public async Task <IHttpActionResult> DeleteUser(DeleteUserBindingModel model)
        {
            if (string.IsNullOrEmpty(model.Id))
            {
                return(BadRequest());
            }

            try
            {
                var user = await UserManager.FindByIdAsync(model.Id);

                IdentityResult result = await UserManager.DeleteAsync(user);

                if (!result.Succeeded)
                {
                    return(GetErrorResult(result));
                }
                else
                {
                    UserManager.RemoveFromRoles(model.Id, UserManager.GetRoles(model.Id).ToArray());
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <ActionResult> Delete(string Id)
        {
            try
            {
                var model = new DeleteUserBindingModel();
                model.Id = Id;

                //Call API Provider
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var token = _userSession.BearerToken;

                string strUrl = controllerName + ConstantDomain.DELETE_USER;
                var    result = await APIProvider.Authorize_DynamicTransaction <DeleteUserBindingModel, string>(model, token, strUrl, APIConstant.API_Resource_Authorize, ARS.Delete);

                if (Response.StatusCode == 200)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_DELETE, ApplicationGenerator.TypeResult.SUCCESS));
                }
                else
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.ISUSED, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_DELETE, ApplicationGenerator.TypeResult.ISUSED));
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.Account, APIConstant.ACTION_DELETE);
                return(RedirectToAction("Index"));
            }
        }
        public async Task <IHttpActionResult> DeleteUser(DeleteUserBindingModel model)
        {
            //Only Admin can delete users
            var appUser = await this.AppUserManager.FindByIdAsync(model.Id);

            if (appUser != null)
            {
                IdentityResult result = await this.AppUserManager.DeleteAsync(appUser);

                if (!result.Succeeded)
                {
                    return(GetErrorResult(result));
                }

                return(Ok());
            }

            return(NotFound());
        }
Example #4
0
        public async Task <IHttpActionResult> DeleteUser(DeleteUserBindingModel model)
        {
            var result = new DeleteUserViewModel();

            result.Result = await _userAccess.DeleteAsync(model.Data.ID) > 0;

            if (result.Result)
            {
                var notificationHub = GetHub <NotificationHub, INotificationHub>();

                var connectionId = _requestReader.Read(HttpHeaders.Request.SignalRConnectionId);
                if (!string.IsNullOrEmpty(connectionId))
                {
                    notificationHub.Clients.AllExcept(connectionId).UpdateModel(new NotificationModel()
                    {
                        Username = UserName,
                        Action   = string.Format("Ha cancellato l'user {0}", model.Data.UserName)
                    });
                }
            }

            return(Ok(result));
        }