public static HttpResponseMessage NotImplemented() { MyJsonResult json = MyJsonResult.CreateError(RQResources.Views.Shared.SharedStrings.err_notimplemented); return(new HttpResponseMessage(System.Net.HttpStatusCode.NotImplemented) { Content = new JsonContent(json) }); }
public static HttpResponseMessage InvalidData() { MyJsonResult json = MyJsonResult.CreateError("Data supplied are invalid."); return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest) { Content = new JsonContent(json) }); }
public static HttpResponseMessage Create(Mvc5RQ.Models.RQKosBranch.RQKosBranchStatus status) { MyJsonResult json = MyJsonResult.CreateError(status); return(new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new JsonContent(json), }); }
public static HttpResponseMessage UnknownError() { MyJsonResult json = MyJsonResult.CreateError(RQResources.Views.Shared.SharedStrings.err_unknown); return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest) { Content = new JsonContent(json) }); }
public static HttpResponseMessage Create(System.Net.HttpStatusCode status, string message) { MyJsonResult json = MyJsonResult.CreateError(message); return(new HttpResponseMessage(status) { Content = new JsonContent(json) }); }
public static HttpResponseMessage Create(Exception exception, string message) { MyJsonResult json; Exception iex = exception; while (iex != null) { if (!string.IsNullOrEmpty(iex.Message)) { message += "\n - " + iex.Message; } iex = iex.InnerException; } json = MyJsonResult.CreateError(message); return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError) { Content = new JsonContent(json), }); }
/// <summary> /// Gets a list of roles including the information wether the user is in that role or not. /// </summary> /// <param name="username">The user which role information should be gathered.</param> /// <returns>A list of roles including the information wether the user is in that role or not.</returns> public JsonResult GetUserRoleStatus(string Id) { if (string.IsNullOrEmpty(Id)) throw new ArgumentException("No user id specified in request"); var allRoles = _userAccountService.GetAllRoles(); var userRoles = _userAccountService.GetRolesForUser(Id); var result = new MyJsonResult() { data = from SelectListItem role in allRoles select new { rolename = role.Text, isInRole = userRoles.Contains(role.Text) }, isSuccess = true }; return Json(result); }
public JsonResult GetExternalDatabaseStatus() { //if (string.IsNullOrEmpty(username)) //throw new ArgumentException("No user name specified in request"); var allDatabases = this._settingsService.GetAllExternalDatabases(); var userDatabases = this._settingsService.GetExternalDatabasesForUser(); var result = new MyJsonResult() { data = from database in allDatabases select new { databasename = database, included = userDatabases.Contains(database) }, isSuccess = true }; return Json(result); }
/// <summary> /// Creates a new user account /// </summary> /// <param name="username">A unique username</param> /// <param name="password">A hopefully secure password</param> /// <param name="email">A unique email address</param> /// <param name="roles"></param> /// <returns></returns> public JsonResult Create(CreateUserViewModel userViewModel) { MyJsonResult result; if (ModelState.IsValid) { ApplicationUser user; IdentityResult res = _userAccountService.CreateUser(userViewModel.Email, userViewModel.Password, userViewModel.roles, out user); if (res.Succeeded) { result = new MyJsonResult() { data = user, isSuccess = true }; } else { ModelState.AddModelError("", res.Errors.First()); result = MyJsonResult.CreateError(string.Format("Error on adding user {0} to the database: ", userViewModel.Email) + res.Errors); } } else result = MyJsonResult.CreateError(string.Format("Error on adding user {0} to the database: ", userViewModel.Email) + "Invalid user model."); return Json(result); }
public JsonContent(MyJsonResult value) { _value = Newtonsoft.Json.Linq.JObject.Parse(new JavaScriptSerializer().Serialize(value)); Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); }