public ActionResult EditAppRole(AppRoleView model, string save, string search) { System.Threading.Thread.Sleep(200); dynamic jsonMessage; if (!ModelState.IsValid) { Dictionary <string, string> modelErrors = GetModelErrors.GetErrors(ModelState); } else { using (var role_Manager = HttpContext.GetOwinContext().Get <AppRoleManager>()) { AppRole appRole = role_Manager.Roles.FirstOrDefault(f => f.Id == model.appRole.Id); if (appRole == null) { appRole = new AppRole(); appRole.Name = model.appRole.Name; appRole.Description = model.appRole.Description; appRole.CreateDate = DateTime.Now; role_Manager.Create(appRole); jsonMessage = new { param1 = "RoleName", param2 = "", param3 = "Role was created." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } appRole.Description = model.appRole.Description; role_Manager.Update(appRole); jsonMessage = new { param1 = "RoleName", param2 = "OK", param3 = "Role was updated." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } } return(View(model)); }
public ActionResult AddUserRole(AppRoleView model) { System.Threading.Thread.Sleep(500); dynamic jsonMessage; if (!ModelState.IsValid) { Dictionary <string, string> modelErrors = GetModelErrors.GetErrors(ModelState); jsonMessage = new { param1 = "ModelState", param2 = "Error", param3 = modelErrors.ToList()[0].Value }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } else { if (model.status == "AddUser") { using (var userManager = HttpContext.GetOwinContext().Get <AppUserManager>()) { userManager.AddToRole(model.key, model.appRole.Name); jsonMessage = new { param1 = "AddUserRole", param2 = model.key, param3 = "User was added to role." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } } if (model.status == "RemoveUser") { using (var userManager = HttpContext.GetOwinContext().Get <AppUserManager>()) { userManager.RemoveFromRole(model.key, model.appRole.Name); jsonMessage = new { param1 = "RemoveUserRole", param2 = model.key, param3 = "User was removed from role." }; HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } } if (model.status == "SearchUsers") { List <AppUser> tmp_list = AppUserProcs.GetUsers(model); model.srchUsers = tmp_list; jsonMessage = new { param1 = "param1", param2 = "param2", param3 = "param2" }; string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(jsonMessage); HttpContext.Response.AddHeader("srchMessage", jsonString); HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(PartialView("SrchUsersTable", model)); } } return(View(model)); }
public ActionResult EditApplication(FormCollection model, string Create, string Delete, string Save) { System.Threading.Thread.Sleep(500); if (!ModelState.IsValid) { Dictionary <String, String> err_list = GetModelErrors.GetErrors(ModelState); dynamic errorMessage = new { param1 = err_list.ToList()[0].Key, param2 = err_list.ToList()[0].Value }; HttpContext.Response.StatusCode = (int)HttpStatusCode.NotAcceptable; return(Json(errorMessage, JsonRequestBehavior.AllowGet)); } try { string tmpJson = model.ToJSON(); AppSystem tmpSystem = new AppBuilder().Build(tmpJson); dynamic jsonMessage; if (!String.IsNullOrEmpty(Delete)) { SecAppManager.Delete(tmpSystem); HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; jsonMessage = new { param1 = "Deleted", param2 = tmpSystem.Name }; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } else if (!String.IsNullOrEmpty(Create)) { AppSystem newSystem = SecAppManager.Create(tmpSystem); string appJson = newSystem.ToJSON(); jsonMessage = new { param1 = "Created", newSystem.Id, newSystem.AppId, newSystem.Name, newSystem.Desc, CreateDate = newSystem.CreateDate.ToShortDateString() + " " + newSystem.CreateDate.ToShortTimeString(), UpdateDate = newSystem.UpdateDate.ToShortDateString() + " " + newSystem.UpdateDate.ToShortTimeString() }; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } else if (!String.IsNullOrEmpty(Save)) { AppSystem updSystem = SecAppManager.Update(tmpSystem); HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; jsonMessage = new { param1 = "Updated", updSystem.Id, updSystem.AppId, updSystem.Name, updSystem.Desc, CreateDate = updSystem.CreateDate.ToShortDateString() + " " + updSystem.CreateDate.ToShortTimeString(), UpdateDate = updSystem.UpdateDate.ToShortDateString() + " " + updSystem.UpdateDate.ToShortTimeString() }; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } else { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotImplemented; jsonMessage = new { param1 = "Error", param2 = "Uknown function call" }; return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { dynamic jsonMessage; HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; string errMessage = ExceptionProcs.GetExceptionMessage(ex); if (errMessage.Contains("duplicate")) { jsonMessage = new { param1 = "Error", param2 = "Already Exists" }; } else { jsonMessage = new { param1 = "Error", param2 = errMessage }; } return(Json(jsonMessage, JsonRequestBehavior.AllowGet)); } }