public ActionResult CreateRole(RoleEditModel model) { Stream stream = null; HttpPostedFileBase roleImage = Request.Files["RoleImage"]; Role role = roleService.Get(model.RoleName); if (roleImage != null && !string.IsNullOrEmpty(roleImage.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Role()); if (!tenantLogoSettings.ValidateFileLength(roleImage.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return(View(model)); } LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get(); if (!logoSettings.ValidateFileExtensions(roleImage.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return(View(model)); } stream = roleImage.InputStream; model.RoleImage = roleImage.FileName; } else //当取不到上传的图片文件名时RoleImage值保持不变 { model.RoleImage = role != null ? role.RoleImage : string.Empty; } if (ModelState.IsValid) { if (role != null) { WebUtility.SetStatusCodeForError(Response); EditUserRole_GenerateFormItem(); model.RoleName = string.Empty; ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "角色名已存在!"); return(View("_CreateRole", model)); } role = model.AsRole(); roleService.Create(role, stream); } return(RedirectToAction("ManageUsers")); }
public ActionResult _CreateRole(string roleName) { RoleEditModel model = new RoleEditModel(); if (!string.IsNullOrEmpty(roleName)) { Role role = new Role(); role = roleService.Get(roleName); if (role != null) { model = role.AsEditModel(); } } EditUserRole_GenerateFormItem(); return(View(model)); }
public ActionResult _CreateRole(string roleName) { RoleEditModel model = new RoleEditModel(); if (!string.IsNullOrEmpty(roleName)) { Role role = new Role(); role = roleService.Get(roleName); if (role != null) model = role.AsEditModel(); } EditUserRole_GenerateFormItem(); return View(model); }
public ActionResult EditRole(RoleEditModel model) { Stream stream = null; HttpPostedFileBase roleImage = Request.Files["RoleImage"]; Role role = roleService.Get(model.RoleName); if (roleImage != null && !string.IsNullOrEmpty(roleImage.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Role()); if (!tenantLogoSettings.ValidateFileLength(roleImage.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return View(model); } LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get(); if (!logoSettings.ValidateFileExtensions(roleImage.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return View(model); } stream = roleImage.InputStream; model.RoleImage = roleImage.FileName; } else //当取不到上传的图片文件名时RoleImage值保持不变 { model.RoleImage = role != null ? role.RoleImage : string.Empty; } if (model != null && !string.IsNullOrEmpty(model.RoleName)) { if (role != null) { role = model.AsRole(); roleService.Update(role, stream); } } return RedirectToAction("ManageUsers"); }