本文整理汇总了C#中SecurityGuard.ViewModels.JsonResponse类的典型用法代码示例。如果您正苦于以下问题:C# JsonResponse类的具体用法?C# JsonResponse怎么用?C# JsonResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonResponse类属于SecurityGuard.ViewModels命名空间,在下文中一共展示了JsonResponse类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApproveDeny
public ActionResult ApproveDeny(string userName)
{
JsonResponse response = new JsonResponse();
MembershipUser user = membershipService.GetUser(userName);
try
{
user.IsApproved = !user.IsApproved;
membershipService.UpdateUser(user);
string approvedMsg = (user.IsApproved) ? "Approved" : "Denied";
response.Success = true;
response.Message = "User " + approvedMsg + " successfully!";
response.Approved = user.IsApproved;
response.ApprovedStatus = (user.IsApproved) ? "Approved" : "Not approved";
}
catch (Exception)
{
response.Success = false;
response.Message = "User unlocked failed.";
}
return Json(response);
}
示例2: CheckForUniqueUser
public ActionResult CheckForUniqueUser(string userName)
{
MembershipUser user = membershipService.GetUser(userName);
JsonResponse response = new JsonResponse();
response.Exists = (user == null) ? false : true;
return Json(response, JsonRequestBehavior.AllowGet);
}
示例3: CreateRole
public virtual ActionResult CreateRole(string roleName)
{
JsonResponse response = new JsonResponse();
if (string.IsNullOrEmpty(roleName))
{
response.Success = false;
response.Message = "You must enter a role name.";
response.CssClass = "red";
return Json(response);
}
try
{
roleService.CreateRole(roleName);
if (Request.IsAjaxRequest())
{
response.Success = true;
response.Message = "Role created successfully!";
response.CssClass = "green";
return Json(response);
}
return RedirectToAction("Index");
}
catch (Exception ex)
{
if (Request.IsAjaxRequest())
{
response.Success = false;
response.Message = ex.Message;
response.CssClass = "red";
return Json(response);
}
ModelState.AddModelError("", ex.Message);
}
return RedirectToAction("Index");
}
示例4: Unlock
public ActionResult Unlock(string userName)
{
JsonResponse response = new JsonResponse();
MembershipUser user = membershipService.GetUser(userName);
try
{
user.UnlockUser();
response.Success = true;
response.Message = "User unlocked successfully!";
response.Locked = false;
response.LockedStatus = (response.Locked) ? "Locked" : "Unlocked";
}
catch (Exception)
{
response.Success = false;
response.Message = "User unlocked failed.";
}
return Json(response);
}
示例5: RevokeRolesForUser
public ActionResult RevokeRolesForUser(string userName, string roles)
{
JsonResponse response = new JsonResponse();
if (string.IsNullOrEmpty(userName))
{
response.Success = false;
response.Message = "The userName is missing.";
return Json(response);
}
if (string.IsNullOrEmpty(roles))
{
response.Success = false;
response.Message = "Roles is missing";
return Json(response);
}
string[] roleNames = roles.Substring(0, roles.Length - 1).Split(',');
if (roleNames.Length == 0)
{
response.Success = false;
response.Message = "No roles are selected to be revoked.";
return Json(response);
}
try
{
roleService.RemoveUserFromRoles(userName, roleNames);
response.Success = true;
response.Message = "The Role(s) has been REVOKED successfully for " + userName;
}
catch (Exception)
{
response.Success = false;
response.Message = "There was a problem revoking roles for the user.";
}
return Json(response);
}
示例6: GrantRolesToUser
public virtual ActionResult GrantRolesToUser(string userName, string roles)
{
JsonResponse response = new JsonResponse();
if (string.IsNullOrEmpty(userName))
{
response.Success = false;
response.Message = "The userName is missing.";
return Json(response);
}
string[] roleNames = roles.Substring(0, roles.Length - 1).Split(',');
if (roleNames.Length == 0)
{
response.Success = false;
response.Message = "No roles have been granted to the user.";
return Json(response);
}
try
{
roleService.AddUserToRoles(userName, roleNames);
response.Success = true;
response.Message = "The Role(s) has been GRANTED successfully to " + userName;
}
catch (Exception)
{
response.Success = false;
response.Message = "There was a problem adding the user to the roles.";
}
return Json(response);
}
示例7: DeleteRole
public virtual ActionResult DeleteRole(string roleName)
{
JsonResponse response = new JsonResponse();
if (string.IsNullOrEmpty(roleName))
{
response.Success = false;
response.Message = "You must select a Role Name to delete.";
response.CssClass = "red";
return Json(response);
}
roleService.DeleteRole(roleName);
response.Success = true;
response.Message = roleName + " was deleted successfully!";
response.CssClass = "green";
return Json(response);
}
示例8: DeleteRoles
public ActionResult DeleteRoles(string roles, bool throwOnPopulatedRole)
{
JsonResponse response = new JsonResponse();
response.Messages = new List<ResponseItem>();
if (string.IsNullOrEmpty(roles))
{
response.Success = false;
response.Message = "You must select at least one role.";
return Json(response);
}
string[] roleNames = roles.Split(',');
StringBuilder sb = new StringBuilder();
ResponseItem item = null;
foreach (var role in roleNames)
{
if (!string.IsNullOrEmpty(role))
{
try
{
roleService.DeleteRole(role, throwOnPopulatedRole);
item = new ResponseItem();
item.Success = true;
item.Message = "Deleted this role successfully - " + role;
item.CssClass = "green";
response.Messages.Add(item);
//sb.AppendLine("Deleted this role successfully - " + role + "<br />");
}
catch (System.Configuration.Provider.ProviderException ex)
{
//sb.AppendLine(role + " - " + ex.Message + "<br />");
item = new ResponseItem();
item.Success = false;
item.Message = ex.Message;
item.CssClass = "yellow";
response.Messages.Add(item);
}
}
}
response.Success = true;
response.Message = sb.ToString();
return Json(response);
}