public JsonResult ChangePassword(string userId, string password) { MyJsonResult result; try { Regex regex = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,15}$"); Match match = regex.Match(password); if (!match.Success) { result = MyJsonResult.CreateError("Invalid Password"); } string passwordHash = SecurityHelper.CreatePasswordHash(password, AppConfig.SaltKey); bool status = _IUserService.ChangePassword(userId, passwordHash); if (status) { result = MyJsonResult.CreateSuccess("Password has been changed successfully."); } else { result = MyJsonResult.CreateError(AppConstant.ErrorMessage); } return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { result = MyJsonResult.CreateError(AppConstant.ErrorMessage); return(Json(result, JsonRequestBehavior.AllowGet)); } }
/// <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 void Delete(int?Userid) { string[] names = { AppConstant.RoleAdmin }; MyJsonResult result; try { int id = (int)Userid; int status = _IUserService.Delete(id); if (status == 1) { result = MyJsonResult.CreateSuccess("Driver has been deleted."); } else if (status == 2) { result = MyJsonResult.CreateError("Cannot delete driver as there is a trip assigned to for this driver "); } else { result = MyJsonResult.CreateError(AppConstant.ErrorMessage); } TempData["result"] = result; TempData.Keep("result"); // return View(); } catch (Exception ex) { result = MyJsonResult.CreateError(AppConstant.ErrorMessage); TempData["result"] = result; TempData.Keep("result"); //return View(); } }
public ActionResult createPost(Petition model) { User user = TheApp.currentUser; if (user == null) { return(Redirect("/Home/Login")); } //todo: 判断权限,只有市县级信访局管理员才能填写日报 MyJsonResult result = new MyJsonResult(); if (model == null) { result.message = "请填写日报记录"; return(Json(result)); } model.PetitionDate = DateTime.Now.Date; model.ProblemAddress = user.CountyId; PetitionDao dao = new PetitionDao(); dao.addOrUpdate(model); dao.Dispose(); result.success = true; return(Json(result)); }
public ActionResult Login(string username, string password) { MyJsonResult result = new MyJsonResult(); if (string.IsNullOrEmpty(username)) { result.message = "请输入用户名"; return(Json(result)); } if (string.IsNullOrEmpty(password)) { result.message = "请输入密码"; return(Json(result)); } UserDao dao = new UserDao(); User user = dao.login(username, password); dao.Dispose(); if (user == null) { result.message = "用户名或密码不正确"; return(Json(result)); } if (user.Role != Role.Admin) { result.message = "您不是管理员,无权登录本系统"; return(Json(result)); } TheApp.currentUser = user; result.success = true; return(Json(result)); }
public ActionResult DeleteUserPost(int UserId) { User user = TheApp.currentUser; if (user == null) { return(Redirect("/Home/Login")); } MyJsonResult result = new MyJsonResult(); if (user.Role != Role.Admin || (user.Role == Role.Admin && user.theCounty.Level != (int)Level.City)) { result.message = "操作失败,您没有权限执行该操作"; return(Json(result)); } if (UserId == 0) { result.message = "请选择要删除的用户"; return(Json(result)); } UserDao dao = new UserDao(); bool r = dao.removeUser(UserId); dao.Dispose(); if (!r) { result.message = "删除失败,请稍后再试"; return(Json(result)); } result.success = true; return(Json(result)); }
public ActionResult ChangePassword(string oldPwd, string newPwd) { User user = TheApp.currentUser; if (user == null) { return(Redirect("/Home/Login")); } MyJsonResult result = new MyJsonResult(); if (string.IsNullOrEmpty(oldPwd)) { result.message = "请输入旧密码"; return(Json(result)); } if (string.IsNullOrEmpty(newPwd)) { result.message = "请输入新密码"; return(Json(result)); } if (user.Password.ToLower() != oldPwd.ToLower()) { result.message = "旧密码不正确"; return(Json(result)); } UserDao dao = new UserDao(); dao.changePassword(user.Id, oldPwd, newPwd); dao.Dispose(); result.success = true; return(Json(result)); }
public ActionResult MapPost(string overlays, string countyId) { MyJsonResult result = new MyJsonResult(); if (string.IsNullOrEmpty(countyId)) { result.message = "请选择乡镇"; return(Json(result)); } if (string.IsNullOrEmpty(overlays)) { result.message = "请在地图中选取行政规划"; return(Json(result)); } List <Coordinate> list = JsonConvert.DeserializeObject <List <Coordinate> >(overlays); if (list == null || list.Count == 0) { throw new ApplicationException("解析失败"); } string coordinate = CoordinateUtil.getCoordinateString(list); TownCoordinateDao dao = new TownCoordinateDao(); dao.save(new TownCoordinate() { CountyId = countyId, Coordinate = coordinate }); dao.Dispose(); result.success = true; return(Json(result)); }
public JsonResult Delete(string id) { MyJsonResult mjr = new MyJsonResult(); using (DbAccessor dba = DbAccessor.Create()) { try { dba.BeginTran(); _menuService.DeleteRecursive(id, dba); dba.CommitTran(); mjr.Success = true; } catch (Exception ex) { dba.RollbackTran(); mjr.Success = false; mjr.Message = ex.Message; } } return(Json(mjr)); }
//public override void OnAuthorization(HttpActionContext filterContext) //{ // //base.OnAuthorization(filterContext); // if (this.IsAuthorized(filterContext)) // this.HandleUnauthorizedRequest(filterContext); //} //protected override bool IsAuthorized(HttpActionContext actionContext) //{ // return HttpContext.Current.User.Identity.IsAuthenticated; //} //protected override bool AuthorizeCore(HttpActionContext httpContext) //{ // //if (!httpContext.Request.IsAuthenticated) // // return false; // if (!AccessRightsResolver.HasEditAccess()) // implement this method based on your tables and logic // { // return false; // //base.HandleUnauthorizedRequest(filterContext); // } // return true; // // base.OnAuthorization(filterContext); //} protected override void HandleUnauthorizedRequest(HttpActionContext filterContext) { string message = "Sie sind nicht autorisiert diese Funktion auszuführen."; MyJsonResult UnauthorizedResult = MyJsonResult.CreateError(message); filterContext.Response = filterContext.Request.CreateResponse <MyJsonResult>(HttpStatusCode.BadRequest, UnauthorizedResult); }
/// <summary> /// 构造注入 /// </summary> /// <param name="next"></param> /// <param name="_myJsonResult"></param> public FileUploadMiddleware(RequestDelegate next, MyJsonResult _myJsonResult, IFileHelper file, FileExtensionContentTypeProvider _provider, IOptions <FileUploadOptions> _options, FileJsonResult _fileResult) { myJsonResult = _myJsonResult; _file = file; provider = _provider; options = _options; fileResult = _fileResult; }
public JsonResult Login(SecUser model, string ValidateCode) { MyJsonResult mjr = new MyJsonResult(); try { var obj = Session["ValidateCode"]; if (obj == null || obj.ToString() != ValidateCode) { mjr.Success = false; mjr.Message = "验证码不正确!"; mjr.Data = 1; if (obj == null) { mjr.Data = 11; } return(Json(mjr)); } UserService userService = new UserService(); var user = userService.GetUserByLoginName(model.LoginName); if (user == null) { mjr.Success = false; mjr.Message = "用户名不正确!"; mjr.Data = 2; } else { if (user.Password != model.Password) { mjr.Success = false; mjr.Message = "密码不正确!"; mjr.Data = 3; } else { SecurityContext.Current = new SecurityContext() { User = user, PermissionManager = new PermissionManager(user.UserId) }; //Session[SSessionIndex.IsAuthorizedForCKEditor] = true; mjr.Success = true; } } } catch (Exception ex) { mjr.Success = false; mjr.Message = ex.Message; } return(Json(mjr)); }
public JsonResult Login(SecUser model, string ValidateCode) { MyJsonResult mjr = new MyJsonResult(); try { var obj = Session["ValidateCode"]; if (obj == null || obj.ToString() != ValidateCode) { mjr.Success = false; mjr.Message = "验证码不正确!"; mjr.Data = 1; if (obj == null) { mjr.Data = 11; } return Json(mjr); } UserService userService = new UserService(); var user = userService.GetUserByLoginName(model.LoginName); if (user == null) { mjr.Success = false; mjr.Message = "用户名不正确!"; mjr.Data = 2; } else { if (user.Password != model.Password) { mjr.Success = false; mjr.Message = "密码不正确!"; mjr.Data = 3; } else { SecurityContext.Current = new SecurityContext() { User = user, PermissionManager = new PermissionManager(user.UserId) }; //Session[SSessionIndex.IsAuthorizedForCKEditor] = true; mjr.Success = true; } } } catch (Exception ex) { mjr.Success = false; mjr.Message = ex.Message; } return Json(mjr); }
public JsonResult Save(SecUser model) { MyJsonResult mjr = new MyJsonResult(); using (var dba = DbAccessor.Create()) { try { dba.BeginTran(); model.ModifiedById = SecurityContext.Current.User.UserId; model.ModifiedDate = DateTime.Now; if (model.UserId == null) { #region 校验数据 dynamic count = _dba.ExecuteScalar<dynamic>("SecuritySettings.User.CountByLoginName", new { LoginName = model.LoginName, Status = (int)StatusType.Enabled }); if (count > 0) { mjr.Success = false; mjr.Message = "登录名已存在!"; goto End; } #endregion model.UserId = Guid.NewGuid().ToString(); model.Status = (int)StatusType.Enabled; model.CreatedById = SecurityContext.Current.User.UserId; model.CreatedDate = DateTime.Now; dba.Insert<SecUser>(model); } else { dba.UpdateFields(model, "LoginName", "Password", "Name", "Sex", "Birthday", "MobilePhone", "OrganizationId", "ModifiedById", "ModifiedDate"); } dba.CommitTran(); mjr.Success = true; mjr.Message = "保存成功!"; } catch (Exception ex) { dba.RollbackTran(); mjr.Success = false; mjr.Message = ex.Message; } } End: return Json(mjr); }
public Home1Controller(SettingApp _setting, IUnitOfWork <MysqlDbContent> _unitOfWork, IRedisOperationHelp _redis, MyJsonResult myJson, RSAHelper _rSA, IServiceProvider _serviceProvider) { setting = _setting; unitOfWork = _unitOfWork; redis = _redis; jsonResult = myJson; rSA = _rSA; serviceProvider = _serviceProvider; }
public JsonResult Save(SecUser model) { MyJsonResult mjr = new MyJsonResult(); using (var dba = DbAccessor.Create()) { try { dba.BeginTran(); model.ModifiedById = SecurityContext.Current.User.UserId; model.ModifiedDate = DateTime.Now; if (model.UserId == null) { #region 校验数据 dynamic count = _dba.ExecuteScalar <dynamic>("SecuritySettings.User.CountByLoginName", new { LoginName = model.LoginName, Status = (int)StatusType.Enabled }); if (count > 0) { mjr.Success = false; mjr.Message = "登录名已存在!"; goto End; } #endregion model.UserId = Guid.NewGuid().ToString(); model.Status = (int)StatusType.Enabled; model.CreatedById = SecurityContext.Current.User.UserId; model.CreatedDate = DateTime.Now; dba.Insert <SecUser>(model); } else { dba.UpdateFields(model, "LoginName", "Password", "Name", "Sex", "Birthday", "MobilePhone", "OrganizationId", "ModifiedById", "ModifiedDate"); } dba.CommitTran(); mjr.Success = true; mjr.Message = "保存成功!"; } catch (Exception ex) { dba.RollbackTran(); mjr.Success = false; mjr.Message = ex.Message; } } End: return(Json(mjr)); }
protected override JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior) { MyJsonResult json = new MyJsonResult(false); json.Data = data; json.ContentEncoding = contentEncoding; json.ContentType = contentType; json.JsonRequestBehavior = behavior; return(json); }
public void ChangeAccountStatus(long id, int accountStatus) { MyJsonResult result; string mailBody = string.Empty; string logId = UserAuthenticate.LogId; try { result = _IUserService.ChangeAccountStatus(id, accountStatus); if (result.isSuccess) { UserViewModel userData = _IUserService.GetUsersDetailsById(id); string subject = string.Empty; if (accountStatus == (int)Enums.AccountStatus.Active) { subject = "Account has been activated!"; result.message = "Account has been activated successfully"; // sending mail to user account status mailBody = RenderPartialToString("_Notify", userData, ControllerContext); _IMasterService.SendAccountStatusEmail(subject, mailBody, userData, logId); } else if (accountStatus == (int)Enums.AccountStatus.Deactivated) { subject = "Account has been deactivated !"; result.message = "Account has been deactivated successfully"; // sending mail to user account status mailBody = RenderPartialToString("_Notify", userData, ControllerContext); _IMasterService.SendAccountStatusEmail(subject, mailBody, userData, logId); } else if (accountStatus == (int)Enums.AccountStatus.Suspended) { subject = "Account has been suspended !"; result.message = "Account has been suspended successfully"; } //string mailBody = HomeController.RenderPartialToString("_ChangeAccountStatus", userData, ControllerContext); //_IMasterService.SendEmail(Enums.MailType.AccountStatusChanged, userData, Convert.ToInt64(UserAuthenticate.LogId), subject, mailBody); } TempData["result"] = result; TempData.Keep("result"); } catch (Exception ex) { result = MyJsonResult.CreateError(AppConstant.ErrorMessage); TempData["result"] = result; TempData.Keep("result"); } }
public ActionResult GetUsers(int id) { int count; UserDao dao = new UserDao(); var list = dao.getList(null, 10, 1, out count); dao.Dispose(); MyJsonResult result = new MyJsonResult(); result.success = true; result.data = list; return(Json(result)); }
/// <summary> /// Remove list[key] from json file.!--. /// </summary> /// <param name="fileName">Full path with FileName: string</param> /// <param name="keyList">List[Key] seperated by ', comma' : string[]</param> async Task <IJsonResult> IJsonManagerRepository.RemoveListJson(string fileName, string keyList, bool ignoreCase = true) { IJsonResult jsonResult = new MyJsonResult() { Message = "Failed to remove " + $"'{keyList}'", Result = JsonResultFlag.Failed }; if (!(File.Exists(fileName) == true)) { return(jsonResult); } // ensure atleast one key if (string.IsNullOrWhiteSpace(fileName) || string.IsNullOrWhiteSpace(keyList) || keyList.Length < 1) { return(jsonResult); } try{ string queryStr = ""; string[] lines = File.ReadAllLines(fileName); string[] linesToKeep = lines; string[] keys = keyList.Split(','); var tempFile = Path.GetTempFileName(); if (linesToKeep.Length > 2) { // loop through all elements in keyList== foreach (var key in keys) { queryStr = '"' + key + '"'; // Important to wrap the key with '"' linesToKeep = ignoreCase ? linesToKeep.Where(l => !(l.ToString().ToLower().IndexOf(queryStr.ToLower()) >= 0)).ToArray() : linesToKeep.Where(l => !(l.ToString().IndexOf(queryStr) >= 0)).ToArray(); } if (linesToKeep != null) { if (linesToKeep.Count() > 2) { linesToKeep[1] = linesToKeep[1].Substring(linesToKeep[1].IndexOf(',') + 1); // important to remove ',' at the beginning of json file } File.WriteAllLines(tempFile, linesToKeep.ToList()); File.Delete(fileName); File.Move(tempFile, fileName); } } jsonResult.Message = "Succeeded to remove " + $"'{keyList}'"; jsonResult.Result = JsonResultFlag.Succeeded; }catch (Exception ex) { jsonResult.Message = ex.Message; jsonResult.Result = JsonResultFlag.DbRetry; } return(jsonResult); }
public ActionResult Calculate(PenaltyCalculationVM model) { var jsonResult = new MyJsonResult(); try { CalculatePenalty(model, jsonResult); } catch (Exception ex) { jsonResult.ErrorMessage = ex.Message; } return(Json(jsonResult, JsonRequestBehavior.AllowGet)); }
public void ValidateModel(MyJsonResult jsonResult, PenaltyCalculationVM model) { var countryError = "Country Missing"; var checkedOutDateError = "Checked Out Date Missing"; var returnedDateError = "Returned Date Missing"; if (string.IsNullOrWhiteSpace(model.CountryId)) { jsonResult.ErrorMessage = countryError; } var countryId = 0; if (!int.TryParse(model.CountryId, out countryId)) { jsonResult.ErrorMessage = countryError; } var country = dbContext.Countries.FirstOrDefault(x => x.Id == countryId); if (country == null) { jsonResult.ErrorMessage = countryError; } if (string.IsNullOrWhiteSpace(model.CheckedOutDate)) { jsonResult.ErrorMessage = checkedOutDateError; } if (string.IsNullOrWhiteSpace(model.ReturnedDate)) { jsonResult.ErrorMessage = returnedDateError; } string format = "dd/mm/yyyy"; DateTime dateTime; if (!DateTime.TryParseExact(model.CheckedOutDate, format, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out dateTime)) { jsonResult.ErrorMessage = checkedOutDateError; } if (!DateTime.TryParseExact(model.ReturnedDate, format, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out dateTime)) { jsonResult.ErrorMessage = returnedDateError; } }
/// <summary> /// Deletes a user from through the membership service. /// </summary> /// <param name="userId">The id of the user account which should be deleted.</param> /// <returns>Result info for the user account deletion action.</returns> public JsonResult Delete(string username) { MyJsonResult result; IdentityResult res = _userAccountService.DeleteUser(username); if (res.Succeeded) { result = MyJsonResult.CreateSuccess(string.Format("User {0} has been deleted.", username)); } else { result = MyJsonResult.CreateError(string.Format("Error on deleting user {0} from the database: ", username) + res.Errors); } return(Json(result)); }
public ActionResult ChangePassword(ChangePasswordViewModel model) { MyJsonResult result; try { ViewBag.IsActive = "false"; if (!ModelState.IsValid) { return(View(model)); } if (model.OldPassword == model.NewPassword) { result = MyJsonResult.CreateError("Current password and new password cannot be same"); TempData["result"] = result; TempData.Keep("result"); } else { UserViewModel userModel = _IUserService.ChangePassword(model); result = MyJsonResult.CreateSuccess("Password has been changed successfully."); result.data = model.Email; TempData["result"] = result; TempData.Keep("result"); var context = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <SignalRHub>(); context.Clients.All.logoff(userModel.Id); return(RedirectToAction("LogOff", "Account")); //return RedirectToAction("Dashboard", "Dashboard", new { data = SecurityHelper.Encrypt(Newtonsoft.Json.JsonConvert.SerializeObject(new Qparams() { LogId = Convert.ToInt64(UserAuthenticate.LogId) })) }); } } catch (CustomException customException) { result = MyJsonResult.CreateError(customException.Message); TempData["result"] = result; TempData.Keep("result"); } catch (Exception ex) { result = MyJsonResult.CreateError("Due to some technical problem this process cannot be completed. Please try after some time."); TempData["result"] = result; TempData.Keep("result"); } return(View(model)); }
public ActionResult DeleteCategoryPost(int Id) { MyJsonResult result = new MyJsonResult(); if (Id == 0) { result.message = "请选择要删除的类别"; return(Json(result)); } CategoryDao dao = new CategoryDao(); dao.remove(Id); dao.Dispose(); result.success = true; return(Json(result)); }
/// <summary> /// Returns the includeExternal user LinkedData /// </summary> /// <returns>includeExternal LinkedData</returns> public JsonResult GetLinkedDataPredicates( string id) { var allPredicates = this._LinkedDataService.GetLinkedDataPredicates(id); var result = new MyJsonResult() { data = from predicate in allPredicates select new { predicatename = predicate, included = false }, isSuccess = true }; return Json(result); }
public ActionResult deletePost(int ledgerId) { MyJsonResult result = new MyJsonResult(); if (ledgerId == 0) { result.message = "请选择要删除的数据"; return(Json(result)); } LedgerDao dao = new LedgerDao(); dao.delete(ledgerId); dao.Dispose(); result.success = true; return(Json(result)); }
public ActionResult CreateCategoryPost(Category model) { MyJsonResult result = new MyJsonResult(); if (model == null) { result.message = "请填写类别"; return(Json(result)); } CategoryDao dao = new CategoryDao(); dao.addOrUpdate(model); dao.Dispose(); result.success = true; return(Json(result)); }
/// <summary> /// Creates a role by a given name. /// </summary> /// <param name="roleName">The role to create.</param> /// <returns>Information about the user creation success</returns> public JsonResult CreateRole(string roleName) { MyJsonResult result; try { _accountService.CreateRole(roleName); result = MyJsonResult.CreateSuccess("The role " + roleName + " has been created."); } catch (Exception ex) { result = MyJsonResult.CreateError(ex); } return(Json(result)); }
/// <summary> /// Deletes a user from through the membership service. /// </summary> /// <param name="userId">The id of the user account which should be deleted.</param> /// <returns>Result info for the user account deletion action.</returns> public JsonResult DeleteUser(string username) { MyJsonResult result; try { _accountService.DeleteUser(username); result = MyJsonResult.CreateSuccess("The user " + username + " has been deleted."); } catch (Exception ex) { result = MyJsonResult.CreateError(ex); } return(Json(result)); }
public ActionResult getCount(string countyId) { MyJsonResult result = new MyJsonResult(); if (string.IsNullOrEmpty(countyId)) { result.message = "未选择县区或乡镇"; return(Json(result)); } PetitionDao dao = new PetitionDao(); int count = dao.getCountByParentAndYear(countyId, 0); dao.Dispose(); result.success = true; result.data = count; return(Json(result)); }
public ActionResult ChangePassword(string data) { ChangePasswordViewModel changePasswordViewModel = Helper.Helper.DecryptParamData <ChangePasswordViewModel>(data); changePasswordViewModel.OldPassword = SecurityHelper.Encrypt(changePasswordViewModel.OldPassword); UserViewModel authenticatedUser = _userService.GetUsersDetailsByEmail(changePasswordViewModel.Email); MyJsonResult result; if (authenticatedUser == null) { result = MyJsonResult.CreateError("Unauthenticated request"); TempData["result"] = result; TempData.Keep("result"); return(RedirectToAction("Login")); } else { if (authenticatedUser.DefaultPassword == false) { if (authenticatedUser.AccountStatus == (int)Utility.Enums.AccountStatus.Active) { result = MyJsonResult.CreateError("Account is already active. Please login"); } else if (authenticatedUser.AccountStatus == (int)Utility.Enums.AccountStatus.Deactivated) { result = MyJsonResult.CreateError("Account has been deactivated. Please contact to administrator"); } else if (authenticatedUser.AccountStatus == (int)Utility.Enums.AccountStatus.Suspended) { result = MyJsonResult.CreateError("Account has been suspended. Please contact to administrator"); } else { result = MyJsonResult.CreateError("Unauthenticated request"); } TempData["result"] = result; TempData.Keep("result"); return(RedirectToAction("Login")); } } TempData["email"] = changePasswordViewModel.Email; return(View("ChangePassword", changePasswordViewModel)); }
/// <summary> /// Returns the includeExternal user LinkedData /// </summary> /// <returns>includeExternal LinkedData</returns> public JsonResult GetLinkedDataPredicates(string id) { var allPredicates = this._LinkedDataService.GetLinkedDataPredicates(id); var result = new MyJsonResult() { data = from predicate in allPredicates select new { predicatename = predicate, included = false }, isSuccess = true }; return(Json(result)); }
public JsonResult Save(SecMenu model) { MyJsonResult mjr = new MyJsonResult(); using (var dba = DbAccessor.Create()) { try { dba.BeginTran(); model.ModifiedById = SecurityContext.Current.User.UserId; model.ModifiedDate = DateTime.Now; if (model.MenuId == null) { model.MenuId = Guid.NewGuid().ToString(); model.Status = (int)StatusType.Enabled; model.CreatedById = SecurityContext.Current.User.UserId; model.CreatedDate = DateTime.Now; dba.ExecuteNonQuery("Security.Menu.Insert", model); } else { dba.UpdateFields(model, "Name", "Url", "IsExpand", "MobilePhone", "ModifiedById", "ModifiedDate"); } dba.CommitTran(); mjr.Success = true; mjr.Message = "保存成功!"; } catch (Exception ex) { dba.RollbackTran(); mjr.Success = false; mjr.Message = ex.Message; } } return Json(mjr); }
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> /// 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 username) { if (string.IsNullOrEmpty(username)) throw new ArgumentException("No user name specified in request"); var allRoles = this._accountService.GetAllRoles(); var userRoles = this._accountService.GetRolesForUser(username); var result = new MyJsonResult() { data = from role in allRoles select new { rolename = role, isInRole = userRoles.Contains(role) }, isSuccess = true }; return Json(result); }
public JsonResult Delete(string id) { MyJsonResult mjr = new MyJsonResult(); using (DbAccessor dba = DbAccessor.Create()) { try { dba.BeginTran(); _menuService.DeleteRecursive(id, dba); dba.CommitTran(); mjr.Success = true; } catch (Exception ex) { dba.RollbackTran(); mjr.Success = false; mjr.Message = ex.Message; } } return Json(mjr); }
public JsonResult Delete(string id) { MyJsonResult mjr = new MyJsonResult(); try { _organizationService.DeleteRecursive(id); mjr.Success = true; } catch (Exception ex) { mjr.Success = false; mjr.Message = ex.Message; } return Json(mjr); }
public JsonResult Delete(string id) { MyJsonResult mjr = new MyJsonResult(); try { var user = new SecUser(); user.UserId = id; user.Status =(int)StatusType.Deleted; _dba.UpdateFields(user, "Status"); mjr.Success = true; } catch (Exception ex) { mjr.Success = false; mjr.Message = ex.Message; } return Json(mjr); }