/// <summary> /// 操作结果提示信息 /// </summary> /// <param name="statusMessageData">信息实体,参数为null时会自动检查ViewData和TempData是否有Key=“StatusMessageData”对应的值</param> /// <param name="hintMillisecondForHide">消息类型为提示信息时是否自动隐藏的秒数(小于零时不自动隐藏,默认不自动隐藏)</param> /// <param name="successMillisecondForHide">消息类型为成功时是否自动隐藏的秒数(小于零时不自动隐藏,默认为2秒)</param> public static MvcHtmlString StatusMessage(this HtmlHelper htmlHelper, StatusMessageData statusMessageData = null, int hintMillisecondForHide = -1, int successMillisecondForHide = 2) { if (statusMessageData == null) { if (htmlHelper.ViewData != null) { statusMessageData = htmlHelper.ViewData.Get <StatusMessageData>("StatusMessageData", null); } if (statusMessageData == null && htmlHelper.ViewContext.TempData != null) { statusMessageData = htmlHelper.ViewContext.TempData.Get <StatusMessageData>("StatusMessageData", null); if (statusMessageData != null) { htmlHelper.ViewContext.TempData.Remove("StatusMessageData"); } } } if (statusMessageData == null) { return(MvcHtmlString.Empty); } htmlHelper.ViewData["StatusMessageData"] = statusMessageData; htmlHelper.ViewData["HintMillisecondForHide"] = hintMillisecondForHide; htmlHelper.ViewData["SuccessMillisecondForHide"] = successMillisecondForHide; return(htmlHelper.DisplayForModel("StatusMessage")); }
public ActionResult _EditUserRank(UserRankEditModel userRankEditModel) { if (userRankEditModel == null || !ModelState.IsValid) { return(View()); } UserRank userRank = userRankEditModel.AsUserRank(); bool isCreated = true; if (userRankEditModel.IsEdit) { userRankService.Update(userRank); } else { UserRank rank = userRankService.Get(userRankEditModel.Rank ?? 0); if (rank != null) { WebUtility.SetStatusCodeForError(Response); ViewData["statusMessageData"] = new StatusMessageData(StatusMessageType.Error, "已经存在的用户等级"); return(View(userRankEditModel)); } isCreated = userRankService.Create(userRank); if (!isCreated) { WebUtility.SetStatusCodeForError(Response); ViewData["statusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建失败"); return(View(userRankEditModel)); } } return(View(userRankEditModel)); }
public JsonResult _DeleteRecommend(long recommendId) { RecommendItem recommendItem = recommendService.Get(recommendId); if (recommendItem == null) { return(Json(new StatusMessageData(StatusMessageType.Error, "找不到所要删除的推荐内容!"))); } if (!authorizer.RecommendItem_Manage(recommendItem.TenantTypeId)) { return(Json(new StatusMessageData(StatusMessageType.Error, "您没有管理权限"))); } StatusMessageData message = null; bool result = recommendService.Delete(recommendId); if (result) { message = new StatusMessageData(StatusMessageType.Success, "删除成功!"); } else { message = new StatusMessageData(StatusMessageType.Error, "删除失败!"); } return(Json(message)); //已修改 }
public ActionResult _CreateUser(ManageUsersCreateEditModel model) { User user = model.AsUser(); UserCreateStatus status = UserCreateStatus.UnknownFailure; user.IsActivated = true; IUser createdUser = iMembershipService.CreateUser(user, model.Password, out status); UserProfile profile = UserProfile.New(); profile.UserId = createdUser.UserId; new UserProfileService().Create(profile); StatusMessageData statusMessageData = null; switch (status) { case UserCreateStatus.DisallowedUsername: WebUtility.SetStatusCodeForError(Response); statusMessageData = new StatusMessageData(StatusMessageType.Error, "对不起,您输入的帐号禁止使用,请输入其他名称"); break; case UserCreateStatus.DuplicateEmailAddress: WebUtility.SetStatusCodeForError(Response); statusMessageData = new StatusMessageData(StatusMessageType.Error, "对不起,您输入的电子邮箱地址已经被使用,请输入其他邮箱"); break; case UserCreateStatus.DuplicateUsername: WebUtility.SetStatusCodeForError(Response); statusMessageData = new StatusMessageData(StatusMessageType.Error, "对不起,您输入的帐号已经被使用,请输入其他名称"); break; case UserCreateStatus.InvalidPassword: WebUtility.SetStatusCodeForError(Response); statusMessageData = new StatusMessageData(StatusMessageType.Error, "您的密码长度少于本站要求的最小密码长度,请重新输入"); break; case UserCreateStatus.UnknownFailure: WebUtility.SetStatusCodeForError(Response); statusMessageData = new StatusMessageData(StatusMessageType.Error, "对不起,注册新用户的时候产生了一个未知错误"); break; default: break; } ViewData["statusMessageData"] = statusMessageData; if (statusMessageData == null) { return(Json(new StatusMessageData(StatusMessageType.Success, "创建成功!"))); } else { return(View(model)); } }
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 _RecommendItem(RecommendItemEditModel recommendItemEditModel) { if (!authorizer.RecommendItem_Manage(recommendItemEditModel.TenantTypeId)) { return(Json(new StatusMessageData(StatusMessageType.Error, "您没有管理权限"))); } StatusMessageData message = null; System.IO.Stream stream = null; HttpPostedFileBase logoImage = Request.Files["LogoImage"]; if (logoImage != null && !string.IsNullOrEmpty(logoImage.FileName)) { stream = logoImage.InputStream; recommendItemEditModel.FeaturedImage = logoImage.FileName; } RecommendItem item = recommendItemEditModel.AsRecommendItem(); if (recommendItemEditModel.Id == 0) { bool result = recommendService.Create(item); if (result) { message = new StatusMessageData(StatusMessageType.Success, "推荐成功!"); } else { message = new StatusMessageData(StatusMessageType.Error, "推荐失败!"); } } else { recommendService.Update(item); message = new StatusMessageData(StatusMessageType.Success, "编辑成功!" + "&" + StringUtility.Trim(item.ItemName, 18) + "&" + item.ItemName); } //已修改 if (stream != null) { recommendService.UploadLogo(item.Id, stream); } return(Content(System.Web.Helpers.Json.Encode(message))); }
public ActionResult BannedUsers() { if (Request.Form["BanDeadline"] == null || string.IsNullOrEmpty(Request.Form["BanReason"])) { WebUtility.SetStatusCodeForError(Response); ViewData["statusMessageData"] = new StatusMessageData(StatusMessageType.Error, "对不起,截止日期或封禁原因不能为空"); return(View("_BannedUser")); } DateTime result = DateTime.UtcNow.AddDays(1); if (!DateTime.TryParse(Request.Form["BanDeadline"], out result)) { WebUtility.SetStatusCodeForError(Response); ViewData["statusMessageData"] = new StatusMessageData(StatusMessageType.Error, "对不起,截止日期不是日期类型"); return(View("_BannedUser")); } DateTime banDay = result; string banReason = Request.Form["BanReason"]; string selectedUserIDsString = Request.Form["UserIds"]; IEnumerable <long> uids = Request.Form.Gets <long>("UserIds"); if (uids != null && uids.Count() > 0) { foreach (long Id in uids) { if (!authorizer.User_Manage(Id)) { return(Json(new StatusMessageData(StatusMessageType.Error, "对不起,您没有权限对此用户操作"))); } try { userService.BanUser(Id, result, banReason); } catch { } } } return(Json(new StatusMessageData(StatusMessageType.Success, "操作成功!"))); }
public ActionResult EditTask(TaskDetailEditModel model) { InitRules(model); if (!ModelState.IsValid) { return(View(model)); } try { taskService.Update(model.AsTaskDetail()); } catch (Exception e) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "更新失败!"); return(View(model)); } TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!"); return(this.RedirectToAction("ManageTasks")); }
public ActionResult AddCommonOperations(List <int> navigationIds) { var userId = UserContext.CurrentUser.UserId; List <CommonOperation> commonOperations = new List <CommonOperation>(); if (navigationIds != null) { foreach (var navigationId in navigationIds) { CommonOperation commonOperation = new CommonOperation(); commonOperation.UserId = userId; commonOperation.NavigationId = navigationId; commonOperations.Add(commonOperation); } navigationService.AddCommonOperations(userId, commonOperations); } else { navigationService.ClearUserCommonOperations(userId); } TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功"); return(RedirectToAction("UpdateCommonOperations")); }
/// <summary> /// 操作结果提示信息 /// </summary> /// <param name="statusMessageData">信息实体,参数为null时会自动检查ViewData和TempData是否有Key=“StatusMessageData”对应的值</param> /// <param name="hintMillisecondForHide">消息类型为提示信息时是否自动隐藏的秒数(小于零时不自动隐藏,默认不自动隐藏)</param> /// <param name="successMillisecondForHide">消息类型为成功时是否自动隐藏的秒数(小于零时不自动隐藏,默认为2秒)</param> public static MvcHtmlString StatusMessage(this HtmlHelper htmlHelper, StatusMessageData statusMessageData = null, int hintMillisecondForHide = -1, int successMillisecondForHide = 2) { if (statusMessageData == null) { if (htmlHelper.ViewData != null) { statusMessageData = htmlHelper.ViewData.Get<StatusMessageData>("StatusMessageData", null); } if (statusMessageData == null && htmlHelper.ViewContext.TempData != null) { statusMessageData = htmlHelper.ViewContext.TempData.Get<StatusMessageData>("StatusMessageData", null); if (statusMessageData != null) htmlHelper.ViewContext.TempData.Remove("StatusMessageData"); } } if (statusMessageData == null) return MvcHtmlString.Empty; htmlHelper.ViewData["StatusMessageData"] = statusMessageData; htmlHelper.ViewData["HintMillisecondForHide"] = hintMillisecondForHide; htmlHelper.ViewData["SuccessMillisecondForHide"] = successMillisecondForHide; return htmlHelper.DisplayForModel("StatusMessage"); }
public ActionResult _ValidateQuestion(long groupId, string myAnswer) { StatusMessageData message = null; GroupEntity group = groupService.Get(groupId); if (group == null) return Json(new StatusMessageData(StatusMessageType.Error, "找不到群组!")); //已修改 IUser currentUser = UserContext.CurrentUser; if (currentUser == null) return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")); if (group.JoinWay != JoinWay.ByQuestion) return Json(new StatusMessageData(StatusMessageType.Error, "当前加入方式不是问题验证")); bool isMember = groupService.IsMember(group.GroupId, currentUser.UserId); if (!isMember) { if (group.Answer == myAnswer) { GroupMember member = GroupMember.New(); member.UserId = UserContext.CurrentUser.UserId; member.GroupId = group.GroupId; member.IsManager = false; groupService.CreateGroupMember(member); message = new StatusMessageData(StatusMessageType.Success, "加入群组成功!"); } else { message = new StatusMessageData(StatusMessageType.Error, "答案错误!"); } } else { message = new StatusMessageData(StatusMessageType.Hint, "您已加入过该群组!"); } return Json(message); }
public ActionResult Create(GroupEditModel groupEditModel) { string errorMessage = null; if (ModelState.HasBannedWord(out errorMessage)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "创建失败", StatusMessageType = StatusMessageType.Hint })); } System.IO.Stream stream = null; HttpPostedFileBase groupLogo = Request.Files["GroupLogo"]; //已修改 IUser user = UserContext.CurrentUser; if (user == null) return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")); if (!authorizer.Group_Create(out errorMessage)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = errorMessage, StatusMessageType = StatusMessageType.Hint })); } if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group()); if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return View(groupEditModel); } LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get(); if (!logoSettings.ValidateFileExtensions(groupLogo.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return View(groupEditModel); } stream = groupLogo.InputStream; groupEditModel.Logo = groupLogo.FileName; } GroupEntity group = groupEditModel.AsGroupEntity(); bool result = groupService.Create(user.UserId, group); if (stream != null) { groupService.UploadLogo(group.GroupId, stream); } //设置分类 if (groupEditModel.CategoryId > 0) { categoryService.AddItemsToCategory(new List<long>() { group.GroupId }, groupEditModel.CategoryId); } //设置标签 string relatedTags = Request.Form.Get<string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId); } //发送邀请 if (!string.IsNullOrEmpty(groupEditModel.RelatedUserIds)) { //已修改 IEnumerable<long> userIds = Request.Form.Gets<long>("RelatedUserIds", null); groupService.SendInvitations(group, user, string.Empty, userIds); } return Redirect(SiteUrls.Instance().GroupHome(group.GroupKey)); }
public ActionResult ManagePrivacyItemsPost() { List<PrivacyItem> systemPrivacyItems = new List<PrivacyItem>(); IEnumerable<PrivacyItemGroup> PrivacyItemGroups = PrivacyItemGroup.GetAll(); foreach (var item in PrivacyItemGroups) { IEnumerable<PrivacyItem> privacyItems = privacyService.GetPrivacyItems(item.TypeId, null); foreach (var privacyItem in privacyItems) { PrivacyItem adminPrivacyItem = new PrivacyItem { ApplicationId = privacyItem.ApplicationId, Description = privacyItem.Description, ItemKey = privacyItem.ItemKey, ItemName = privacyItem.ItemName, DisplayOrder = privacyItem.DisplayOrder, ItemGroupId = privacyItem.ItemGroupId, PrivacyStatus = Request.Form.Get<PrivacyStatus>(privacyItem.ItemKey, PrivacyStatus.Part) }; systemPrivacyItems.Add(adminPrivacyItem); } } privacyService.UpdatePrivacyItems(systemPrivacyItems); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新隐私规则成功"); return Redirect(SiteUrls.Instance().ManagePrivacyItems()); }
public ActionResult _EditOutBox(SmtpSettingsEditModel model) { ViewData["NeedAutoCompletion"] = false; if (!ModelState.IsValid || !model.IsValidate) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "数据验证失败,请检查数据是否填写完整"); return View(model); } emailService.SaveSmtpSetting(model.AsSmtpSettings()); return Json(new StatusMessageData(StatusMessageType.Success, "保存成功")); }
public ActionResult EditAnnouncement(AnnouncementEditModel model, string type, string home, string userspace) { if (home == null && userspace == null) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "请至少选择一个显示区域"); TempData["model"] = model; return RedirectToAction("EditAnnouncement"); } model.DisplayArea = string.Format("{0},{1}", home, userspace); if (type == "disenabled") { model.EnabledDescription = false; model.IsHyperLink = false; } if (type == "text") { model.EnabledDescription = true; model.IsHyperLink = false; } if (type == "hyperlink") { model.EnabledDescription = true; model.IsHyperLink = true; } if (model.ReleaseDate == DateTime.MinValue || model.ExpiredDate == DateTime.MinValue) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "请正确填写日期"); TempData["model"] = model; return RedirectToAction("EditAnnouncement"); } if (model.ReleaseDate > model.ExpiredDate) { DateTime changDate = model.ReleaseDate; model.ReleaseDate = model.ExpiredDate; model.ExpiredDate = changDate; } model.UserId = UserContext.CurrentUser.UserId; if (model.Id == 0 || model.Id == null) { announcementService.Create(model.AsAnnouncement()); } else { announcementService.Update(model.AsAnnouncement()); } return RedirectToAction("ManageAnnouncements"); }
public ActionResult CreateSection(BarSectionEditModel model) { if (!authorizer.BarSection_Create()) return HttpNotFound(); if (!ModelState.IsValid) { return View(model); } HttpPostedFileBase logoImage = Request.Files["LogoImage"]; string logoImageFileName = string.Empty; Stream stream = null; if (logoImage != null && !string.IsNullOrEmpty(logoImage.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().BarSection()); if (!tenantLogoSettings.ValidateFileLength(logoImage.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(logoImage.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return View(model); } stream = logoImage.InputStream; logoImageFileName = logoImage.FileName; } IEnumerable<long> managerUserIds = Request.Form.Gets<long>("ManagerUserIds"); BarSection barSection = model.AsBarSection(); barSection.IsEnabled = true; barSection.LogoImage = logoImageFileName; barSection.UserId = UserContext.CurrentUser.UserId; //独立帖吧应用中帖吧拥有者指定为0 barSection.OwnerId = 0; barSectionService.Create(barSection, UserContext.CurrentUser.UserId, managerUserIds, stream); if (model.CategoryId > 0) categoryService.AddItemsToCategory(new List<long> { barSection.SectionId }, model.CategoryId); return Redirect(SiteUrls.Instance().SectionDetail(barSection.SectionId)); }
public ActionResult AddCommonOperations(List<int> navigationIds) { var userId = UserContext.CurrentUser.UserId; List<CommonOperation> commonOperations = new List<CommonOperation>(); if (navigationIds != null) { foreach (var navigationId in navigationIds) { CommonOperation commonOperation = new CommonOperation(); commonOperation.UserId = userId; commonOperation.NavigationId = navigationId; commonOperations.Add(commonOperation); } navigationService.AddCommonOperations(userId, commonOperations); } else { navigationService.ClearUserCommonOperations(userId); } TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功"); return RedirectToAction("UpdateCommonOperations"); }
public ActionResult _EditPosition(AdvertisingPositionEditModel positionEditModel) { StatusMessageData message = null; AdvertisingPosition position = advertisingService.GetPosition(positionEditModel.PositionId); Stream stream = null; HttpPostedFileBase positionImage = Request.Files["positionImage"]; if (positionImage != null && !string.IsNullOrEmpty(positionImage.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().AdvertisingPosition()); if (!tenantLogoSettings.ValidateFileLength(positionImage.ContentLength)) { message = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return Json(message); } LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get(); if (!logoSettings.ValidateFileExtensions(positionImage.FileName)) { message = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return Json(message); } stream = positionImage.InputStream; positionEditModel.FeaturedImage = positionImage.FileName; } else if (position != null) { positionEditModel.FeaturedImage = position.FeaturedImage; } if (position == null) { advertisingService.CreatePosition(positionEditModel.AsAdvertisingPosition(), stream); message = new StatusMessageData(StatusMessageType.Success, "创建广告位成功!"); } else { advertisingService.UpdatePosition(positionEditModel.AsAdvertisingPosition(), stream); message = new StatusMessageData(StatusMessageType.Success, "编辑广告位成功!"); } return Content(System.Web.Helpers.Json.Encode(message)); }
public ActionResult _RecommendItem(string tenantTypeId, long itemId = 0, string itemName = null, string recommendItemTypeId = null, bool showLink = false, long recommendId = 0, bool showInList = true, long userId = 0) { RecommendItem recommendItem = null; if (recommendId > 0) { recommendItem = recommendService.Get(recommendId); if (recommendItem == null) return HttpNotFound(); tenantTypeId = recommendItem.TenantTypeId; itemId = recommendItem.ItemId; recommendItemTypeId = recommendItem.TypeId; ViewData["RecommendTypeName"] = recommendItem.RecommendItemType.Name; ViewData["RecommendTypeId"] = recommendItem.TypeId; } if (!authorizer.RecommendItem_Manage(tenantTypeId)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有管理推荐内容的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint })); } IEnumerable<RecommendItemType> itemTypes = recommendService.GetRecommendTypes(tenantTypeId); IEnumerable<RecommendItem> recommendItems = recommendService.Gets(itemId, tenantTypeId); //已修改 RecommendItemEditModel itemEditModel = new RecommendItemEditModel(); ViewData["recommendItems"] = recommendItems; //已修改 ViewData["TypeId"] = new SelectList(itemTypes, "TypeId", "Name", recommendItemTypeId); if (recommendId != 0) { itemEditModel = recommendItem.AsEditModel(); ViewData["HasFeaturedImage"] = recommendItem.RecommendItemType.HasFeaturedImage; } else { if (itemTypes != null && itemTypes.Count() > 0 && string.IsNullOrEmpty(recommendItemTypeId)) { //已修改 recommendItemTypeId = itemTypes.First().TypeId; } if (!string.IsNullOrEmpty(recommendItemTypeId)) { recommendItem = recommendService.Get(itemId, recommendItemTypeId); RecommendItemType recommendType = recommendService.GetRecommendType(recommendItemTypeId); ViewData["HasFeaturedImage"] = recommendType.HasFeaturedImage; ViewData["RecommendTypeName"] = recommendType.Name; ViewData["RecommendTypeId"] = recommendType.TypeId; if (recommendItem != null && !recommendItem.IsLink) { ViewData["ExpiredDate"] = recommendItem.ExpiredDate; itemEditModel = recommendItem.AsEditModel(); } else { RecommendItem newItem = RecommendItem.New(); newItem.ItemName = itemName; newItem.ItemId = itemId; newItem.TenantTypeId = tenantTypeId; newItem.ExpiredDate = DateTime.UtcNow.AddMonths(1); newItem.UserId = userId; itemEditModel = newItem.AsEditModel(); } } else { StatusMessageData message = null; TenantTypeService tenantTypeService = new TenantTypeService(); TenantType tenantType = tenantTypeService.Get(tenantTypeId); if (tenantType == null) { message = new StatusMessageData(StatusMessageType.Hint, "没有推荐类别"); } else { message = new StatusMessageData(StatusMessageType.Hint, tenantType.Name + "下没有推荐类别"); } ViewData["statusMessageData"] = message; } } ViewData["showLink"] = showLink || itemEditModel.IsLink; ViewData["showInList"] = showInList; return View(itemEditModel); }
public ActionResult _RecommendItem(RecommendItemEditModel recommendItemEditModel) { if (!authorizer.RecommendItem_Manage(recommendItemEditModel.TenantTypeId)) return Json(new StatusMessageData(StatusMessageType.Error, "您没有管理权限")); StatusMessageData message = null; System.IO.Stream stream = null; HttpPostedFileBase logoImage = Request.Files["LogoImage"]; if (logoImage != null && !string.IsNullOrEmpty(logoImage.FileName)) { stream = logoImage.InputStream; recommendItemEditModel.FeaturedImage = logoImage.FileName; } RecommendItem item = recommendItemEditModel.AsRecommendItem(); if (recommendItemEditModel.Id == 0) { bool result = recommendService.Create(item); if (result) { message = new StatusMessageData(StatusMessageType.Success, "推荐成功!"); } else { message = new StatusMessageData(StatusMessageType.Error, "推荐失败!"); } } else { recommendService.Update(item); message = new StatusMessageData(StatusMessageType.Success, "编辑成功!" + "&" + StringUtility.Trim(item.ItemName, 18) + "&" + item.ItemName); } //已修改 if (stream != null) { recommendService.UploadLogo(item.Id, stream); } return Content(System.Web.Helpers.Json.Encode(message)); }
public JsonResult _DeleteRecommend(long recommendId) { RecommendItem recommendItem = recommendService.Get(recommendId); if (recommendItem == null) return Json(new StatusMessageData(StatusMessageType.Error, "找不到所要删除的推荐内容!")); if (!authorizer.RecommendItem_Manage(recommendItem.TenantTypeId)) return Json(new StatusMessageData(StatusMessageType.Error, "您没有管理权限")); StatusMessageData message = null; bool result = recommendService.Delete(recommendId); if (result) { message = new StatusMessageData(StatusMessageType.Success, "删除成功!"); } else { message = new StatusMessageData(StatusMessageType.Error, "删除失败!"); } return Json(message); //已修改 }
public ActionResult ManageLogin(LoginEditModel model) { if (!ModelState.IsValid) return View(model); User user = model.AsUser(); UserLoginStatus userLoginStatus = membershipService.ValidateUser(user.UserName, user.Password); if (userLoginStatus == UserLoginStatus.InvalidCredentials) { IUser userByEmail = userService.FindUserByEmail(user.UserName); if (userByEmail != null) { user = userByEmail as User; userLoginStatus = membershipService.ValidateUser(userByEmail.UserName, model.Password); } } else { user = userService.GetFullUser(model.UserName); } if (userLoginStatus == UserLoginStatus.InvalidCredentials) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "帐号或密码错误,请重新输入!"); } if (userLoginStatus == UserLoginStatus.Success) { if (user.IsAllowEntryControlPannel()) { HttpCookie adminCookie = new HttpCookie("SpacebuilderAdminCookie" + user.UserId); adminCookie.Value = Utility.EncryptTokenForAdminCookie(true.ToString()); if (!string.IsNullOrEmpty(FormsAuthentication.CookieDomain)) adminCookie.Domain = FormsAuthentication.CookieDomain; adminCookie.HttpOnly = true; Response.Cookies.Add(adminCookie); FormsAuthentication.SetAuthCookie(model.UserName, false); } else return Redirect(SiteUrls.Instance().ManageLogin()); string redirectUrl = null; if (!string.IsNullOrEmpty(model.ReturnUrl)) redirectUrl = model.ReturnUrl; else redirectUrl = SiteUrls.Instance().ManageHome(); return Redirect(redirectUrl); } return View(model); }
public ActionResult EditTask(TaskDetailEditModel model) { InitRules(model); if (!ModelState.IsValid) return View(model); try { taskService.Update(model.AsTaskDetail()); } catch (Exception e) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "更新失败!"); return View(model); } TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!"); return this.RedirectToAction("ManageTasks"); }
public ActionResult _EditApply(long groupId, string applyReason) { StatusMessageData message = null; GroupEntity group = groupService.Get(groupId); if (group == null) return Json(new StatusMessageData(StatusMessageType.Error, "找不到群组!")); IUser currentUser = UserContext.CurrentUser; if (currentUser == null) return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")); if (group.JoinWay != JoinWay.ByApply) return Json(new StatusMessageData(StatusMessageType.Error, "当前加入方式不是需要申请")); //已修改 bool isApplied = groupService.IsApplied(currentUser.UserId, group.GroupId); if (!isApplied) { GroupMemberApply apply = GroupMemberApply.New(); apply.ApplyReason = applyReason; apply.ApplyStatus = GroupMemberApplyStatus.Pending; apply.GroupId = group.GroupId; apply.UserId = UserContext.CurrentUser.UserId; groupService.CreateGroupMemberApply(apply); message = new StatusMessageData(StatusMessageType.Success, "申请已发出,请等待!"); } else { message = new StatusMessageData(StatusMessageType.Hint, "您已给该群组发送过申请!"); } return Json(message); }
public ActionResult ManageLogin(LoginEditModel model) { if (!ModelState.IsValid) { return(View(model)); } User user = model.AsUser(); UserLoginStatus userLoginStatus = membershipService.ValidateUser(user.UserName, user.Password); if (userLoginStatus == UserLoginStatus.InvalidCredentials) { IUser userByEmail = userService.FindUserByEmail(user.UserName); if (userByEmail != null) { user = userByEmail as User; userLoginStatus = membershipService.ValidateUser(userByEmail.UserName, model.Password); } } else { user = userService.GetFullUser(model.UserName); } if (userLoginStatus == UserLoginStatus.InvalidCredentials) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "帐号或密码错误,请重新输入!"); } if (userLoginStatus == UserLoginStatus.Success) { if (user.IsAllowEntryControlPannel()) { HttpCookie adminCookie = new HttpCookie("SpacebuilderAdminCookie" + user.UserId); adminCookie.Value = Utility.EncryptTokenForAdminCookie(true.ToString()); if (!string.IsNullOrEmpty(FormsAuthentication.CookieDomain)) { adminCookie.Domain = FormsAuthentication.CookieDomain; } adminCookie.HttpOnly = true; Response.Cookies.Add(adminCookie); FormsAuthentication.SetAuthCookie(model.UserName, false); } else { return(Redirect(SiteUrls.Instance().ManageLogin())); } string redirectUrl = null; if (!string.IsNullOrEmpty(model.ReturnUrl)) { redirectUrl = model.ReturnUrl; } else { redirectUrl = SiteUrls.Instance().ManageHome(); } return(Redirect(redirectUrl)); } return(View(model)); }
public ActionResult Register(RegisterEditModel model) { InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get(); SystemMessageViewModel message; bool isContinue = InviteRegister(out message); if (!isContinue) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, message)); } if (!ModelState.IsValid) return View(model); User user = model.AsUser(); //根据站点配置设置用户属性 user.IsActivated = userSettings.AccountActivation == AccountActivation.Automatic; //尝试创建用户 IMembershipService membershipService = DIContainer.Resolve<IMembershipService>(); UserCreateStatus userCreateStatus = UserCreateStatus.UnknownFailure; membershipService.CreateUser(user, model.Password, out userCreateStatus); if (userCreateStatus != UserCreateStatus.Created) { switch (userCreateStatus) { case UserCreateStatus.DisallowedUsername: ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "不允许的用户名"); break; case UserCreateStatus.DuplicateEmailAddress: ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的邮箱"); break; case UserCreateStatus.DuplicateMobile: ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的手机号"); break; case UserCreateStatus.DuplicateUsername: ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "重复的用户名"); break; case UserCreateStatus.InvalidPassword: ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "不合法的密码"); break; case UserCreateStatus.InvalidQuestionAnswer: ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "不合法的问题答案"); break; default: ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "发生未知错误"); break; } model.Password = string.Empty; model.ConfirmPassword = string.Empty; return View(model); } UserProfileService userProfileService = new UserProfileService(); UserProfile userProfile = UserProfile.New(); userProfile.UserId = user.UserId; userProfileService.Create(userProfile); if (userSettings.EnableNotActivatedUsersToLogin || user.IsActivated) authenticationService.SignIn(user, false); if (Request.Cookies["invite"] != null) { string invite = Request.Cookies["invite"].Value; InvitationCode invitationCode = inviteFriendService.GetInvitationCodeEntity(invite); if (invitationCode != null) { string errorMessage; InviteFriendRecord inviteFriendRecord = new InviteFriendRecord { Code = invitationCode.Code, DateCreated = DateTime.UtcNow, InvitedUserId = user.UserId, UserId = invitationCode.UserId }; inviteFriendService.CreateInviteFriendRecord(inviteFriendRecord); if (!invitationCode.IsMultiple) { bool isSuccess = MutualFollow(invitationCode, userService.GetFullUser(user.UserName), out errorMessage); Response.Cookies.Remove("invite"); if (!isSuccess) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "关注失败", Body = errorMessage, StatusMessageType = StatusMessageType.Hint })); } } else { User userFromDB = userService.GetFullUser(user.UserName); if (userFromDB != null) { string token = Utility.EncryptTokenForInviteFriend(0.01, userFromDB.UserId); return Redirect(SiteUrls.Instance().ConfirmFollow(token, Request.Cookies["invite"].Value)); } } } //IUser userFromDB = userService.GetFullUser(model.UserName); //string token = null; //if (!userSettings.EnableNotActivatedUsersToLogin) //{ // token = Utility.EncryptTokenForInviteFriend(0.01, userFromDB.UserId); // return Redirect(SiteUrls.Instance().ConfirmFollow(token)); //} //User userFormDB = userService.GetFullUser(model.UserName); //string errorMessage; //AcceptInvitation(Request.Cookies["invite"].Value, userFormDB, out errorMessage); } return RegisterJumpByconfig(user); }
public ActionResult _RecommendItem(string tenantTypeId, long itemId = 0, string itemName = null, string recommendItemTypeId = null, bool showLink = false, long recommendId = 0, bool showInList = true, long userId = 0) { RecommendItem recommendItem = null; if (recommendId > 0) { recommendItem = recommendService.Get(recommendId); if (recommendItem == null) { return(HttpNotFound()); } tenantTypeId = recommendItem.TenantTypeId; itemId = recommendItem.ItemId; recommendItemTypeId = recommendItem.TypeId; ViewData["RecommendTypeName"] = recommendItem.RecommendItemType.Name; ViewData["RecommendTypeId"] = recommendItem.TypeId; } if (!authorizer.RecommendItem_Manage(tenantTypeId)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有管理推荐内容的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint }))); } IEnumerable <RecommendItemType> itemTypes = recommendService.GetRecommendTypes(tenantTypeId); IEnumerable <RecommendItem> recommendItems = recommendService.Gets(itemId, tenantTypeId); //已修改 RecommendItemEditModel itemEditModel = new RecommendItemEditModel(); ViewData["recommendItems"] = recommendItems; //已修改 ViewData["TypeId"] = new SelectList(itemTypes, "TypeId", "Name", recommendItemTypeId); if (recommendId != 0) { itemEditModel = recommendItem.AsEditModel(); ViewData["HasFeaturedImage"] = recommendItem.RecommendItemType.HasFeaturedImage; } else { if (itemTypes != null && itemTypes.Count() > 0 && string.IsNullOrEmpty(recommendItemTypeId)) { //已修改 recommendItemTypeId = itemTypes.First().TypeId; } if (!string.IsNullOrEmpty(recommendItemTypeId)) { recommendItem = recommendService.Get(itemId, recommendItemTypeId); RecommendItemType recommendType = recommendService.GetRecommendType(recommendItemTypeId); ViewData["HasFeaturedImage"] = recommendType.HasFeaturedImage; ViewData["RecommendTypeName"] = recommendType.Name; ViewData["RecommendTypeId"] = recommendType.TypeId; if (recommendItem != null && !recommendItem.IsLink) { ViewData["ExpiredDate"] = recommendItem.ExpiredDate; itemEditModel = recommendItem.AsEditModel(); } else { RecommendItem newItem = RecommendItem.New(); newItem.ItemName = itemName; newItem.ItemId = itemId; newItem.TenantTypeId = tenantTypeId; newItem.ExpiredDate = DateTime.UtcNow.AddMonths(1); newItem.UserId = userId; itemEditModel = newItem.AsEditModel(); } } else { StatusMessageData message = null; TenantTypeService tenantTypeService = new TenantTypeService(); TenantType tenantType = tenantTypeService.Get(tenantTypeId); if (tenantType == null) { message = new StatusMessageData(StatusMessageType.Hint, "没有推荐类别"); } else { message = new StatusMessageData(StatusMessageType.Hint, tenantType.Name + "下没有推荐类别"); } ViewData["statusMessageData"] = message; } } ViewData["showLink"] = showLink || itemEditModel.IsLink; ViewData["showInList"] = showInList; return(View(itemEditModel)); }
public ActionResult EditAdvertising(AdvertisingEditModel advertisingEditModel) { Stream stream = null; HttpPostedFileBase uploadImageFileName = Request.Files["UploadImageFileName"]; Advertising advertising = advertisingService.GetAdvertising(advertisingEditModel.AdvertisingId); if (uploadImageFileName != null && !string.IsNullOrEmpty(uploadImageFileName.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Advertising()); if (!tenantLogoSettings.ValidateFileLength(uploadImageFileName.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return View(advertisingEditModel); } LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get(); if (!logoSettings.ValidateFileExtensions(uploadImageFileName.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return View(advertisingEditModel); } stream = uploadImageFileName.InputStream; advertisingEditModel.UploadImageFileName = uploadImageFileName.FileName; } else //当取不到上传的图片文件名时UploadFileName值保持不变 { advertisingEditModel.UploadImageFileName = advertising != null ? advertising.AttachmentUrl : string.Empty; } var positionIds = advertisingEditModel.PositionIds ?? new List<string>(); if (advertisingEditModel.AdvertisingId <= 0) { if (advertisingService.CreateAdvertising(advertisingEditModel.AsAdvertising(), positionIds, stream)) { return Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Success, "创建广告成功!"))); } return Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Error, "创建广告失败!"))); } advertisingService.UpdateAdvertising(advertisingEditModel.AsAdvertising(), positionIds, stream); return Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Success, "编辑广告成功!"))); }
public ActionResult Login(LoginEditModel model) { pageResourceManager.InsertTitlePart("登录"); ViewData["CanRegister"] = userSettings.RegistrationMode == RegistrationMode.All; if (!ModelState.IsValid) { model.Password = string.Empty; return View(model); } //尝试登录 User user = model.AsUser(); //使用用户名作为用户名和邮件分别尝试登录 UserLoginStatus userLoginStatus = membershipService.ValidateUser(user.UserName, user.Password); if (userLoginStatus == UserLoginStatus.InvalidCredentials) { IUser userByEmail = userService.FindUserByEmail(user.UserName); if (userByEmail != null) { user = userByEmail as User; userLoginStatus = membershipService.ValidateUser(userByEmail.UserName, model.Password); } if (userLoginStatus != UserLoginStatus.InvalidCredentials && !userByEmail.IsEmailVerified) { ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "您的邮箱没有激活,请您使用帐号登录"); model.Password = string.Empty; return View(model); } } else { user = userService.GetUser(model.UserName) as User; } if (userLoginStatus == UserLoginStatus.Success || (userLoginStatus == UserLoginStatus.NotActivated && userSettings.EnableNotActivatedUsersToLogin)) { //让用户登录 user.UserId = UserIdToUserNameDictionary.GetUserId(user.UserName); authenticationService.SignIn(user, model.RememberPassword); } if (userLoginStatus == UserLoginStatus.Success) { if (Request.Cookies["invite"] != null) { InvitationCode invitationCode = inviteFriendService.GetInvitationCodeEntity(Request.Cookies["invite"].Value); if (invitationCode != null) { Response.Cookies.Remove("invite"); string token = Utility.EncryptTokenForInviteFriend(0.01, user.UserId); return Redirect(SiteUrls.Instance().ConfirmFollow(token, invitationCode.Code)); } } if (Request.Cookies.Get("returnUrl") != null) { Response.Cookies["returnUrl"].Expires = DateTime.Now; } if (!string.IsNullOrEmpty(model.ReturnUrl)) return Redirect(Tunynet.Utilities.WebUtility.UrlDecode(model.ReturnUrl)); if (Request.Cookies != null) { string returnUrl = Request.Cookies.Get("returnUrl") != null ? Request.Cookies.Get("returnUrl").Value : string.Empty; if (!string.IsNullOrEmpty(returnUrl)) return Redirect(Tunynet.Utilities.WebUtility.UrlDecode(returnUrl)); } if (model.loginInModal && Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.AbsoluteUri); //判断站点设置选择登录之后的页面 if (userSettings.MyHomePageAsSiteEntry) return Redirect(SiteUrls.Instance().MyHome(user.UserId)); return Redirect(SiteUrls.Instance().SiteHome()); } else if (userLoginStatus == UserLoginStatus.InvalidCredentials) { ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "帐号密码不匹配,请检查您的帐号密码"); model.Password = string.Empty; return View(model); } else if (userLoginStatus == UserLoginStatus.Banned) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "帐号被封禁!", Body = "不好意思,由于您的非法操作,帐号已经被封禁,封禁截止到" + user.BanDeadline.ToFriendlyDate(), StatusMessageType = StatusMessageType.Error }, model.ReturnUrl)); } else if (userLoginStatus == UserLoginStatus.NotActivated) { string token = Utility.EncryptTokenForValidateEmail(0.004, user.UserId); return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "帐号未激活!", Body = "您的帐号还未激活,请尽快{0}您的帐号,以方便您更多操作!", BodyLink = new Dictionary<string, string> { { "激活", SiteUrls.Instance()._ActivateByEmail(user.AccountEmail, token) } }, StatusMessageType = StatusMessageType.Hint }, model.ReturnUrl)); } ViewData["StatusMessage"] = new StatusMessageData(StatusMessageType.Error, "系统发生未知错误"); model.Password = string.Empty; return View(model); }
public ActionResult EditPost(BarPostEditModel post) { //1.没有判断创建、编辑回帖的权限 //2.代码组织乱,先判断异常情况,正常情况留至最后处理; //3.如果返回错误信息情况较多,可以抽出一个私有方法(已帮忙写好,查看StatusMessage方法),在其内部判断是同步还是异步; BarPost barPost = post.AsBarPost(); if (barPost == null) return StatusMessage(StatusMessageType.Error, "没有找到编辑的内容"); string errorMessage = string.Empty; if (ModelState.HasBannedWord(out errorMessage)) { return StatusMessage(StatusMessageType.Error, errorMessage); } if (post.PostId.HasValue && post.PostId.Value > 0) { if (!authorizer.BarPost_Edit(post.PostId ?? 0)) return StatusMessage(StatusMessageType.Error, "您没有权限编辑此回帖"); barPostService.Update(barPost, UserContext.CurrentUser.UserId); if (Request.IsAjaxRequest()) return Json(new { PostId = barPost.PostId }); else return Redirect(SiteUrls.Instance().ThreadDetailGotoPost(barPost.PostId)); } else { StatusMessageData hint = null; if (!authorizer.BarPost_Create(barPost.SectionId, out errorMessage)) return StatusMessage(StatusMessageType.Error, errorMessage); bool isCreat = barPostService.Create(barPost); if (barPost.AuditStatus == AuditStatus.Pending) { hint = new StatusMessageData(StatusMessageType.Hint, "您的回复需要通过审核"); } if (isCreat) { if (Request.IsAjaxRequest()) return Json(new { PostId = barPost.PostId, auditStatus = hint }); else return Redirect(SiteUrls.Instance().ThreadDetailGotoPost(barPost.PostId)); } return StatusMessage(StatusMessageType.Error, "创建失败"); } }
/// <summary> /// 包裹消息 /// </summary> /// <remarks>用于解决ajaxform在IE下异步上传文件时,返回不了json数据问题</remarks> /// <param name="data"></param> /// <returns></returns> private string WarpJsonMessage(StatusMessageData data) { return(System.Web.Helpers.Json.Encode(data)); }
public ActionResult EditSection(BarSectionEditModel model) { if (authorizer.BarSection_Manage(model.SectionId)) { HttpPostedFileBase logoImage = Request.Files["LogoImage"]; string logoImageFileName = string.Empty; Stream stream = null; if (logoImage != null && !string.IsNullOrEmpty(logoImage.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().BarSection()); if (!tenantLogoSettings.ValidateFileLength(logoImage.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("Logo文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return View(model); } LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get(); if (!logoSettings.ValidateFileExtensions(logoImage.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "Logo文件是不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return View(model); } stream = logoImage.InputStream; logoImageFileName = logoImage.FileName; } BarSection section = model.GetBarSectionByEditForManager(); if (!string.IsNullOrEmpty(logoImageFileName)) section.LogoImage = logoImageFileName; IEnumerable<long> managerUserIds = barSectionService.GetSectionManagers(model.SectionId).Select(n => n.UserId); if (authorizer.BarSection_SetManager(model.SectionId)) { managerUserIds = Request.Form.Gets<long>("ManagerUserIds") == null ? null : Request.Form.Gets<long>("ManagerUserIds"); } barSectionService.Update(section, UserContext.CurrentUser.UserId, managerUserIds, stream); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新设置成功"); return RedirectToAction("EditSection", new { sectionId = model.SectionId }); } else { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "保存失败,您可能没有权限编辑帖子描述", Title = "保存失败", StatusMessageType = StatusMessageType.Hint })); } }
public ActionResult EditTag(TagEditModel tagEditModel) { System.IO.Stream stream = null; //是否创建 bool isCreate = tagEditModel.TagId == 0; if (isCreate) { ViewData["editTagTitle"] = "创建标签"; } else { ViewData["editTagTitle"] = "编辑标签"; } TagService tagService = new TagService(tagEditModel.TenantTypeId); //是特色标签 if (tagEditModel.IsFeatured) { HttpPostedFileBase tagLogo = Request.Files["tagLogo"]; string fileName = tagLogo == null ? "" : tagLogo.FileName; if (string.IsNullOrEmpty(fileName) && string.IsNullOrEmpty(tagEditModel.FeaturedImage)) { //所属租户类型下拉框 SelectList tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId); ViewData["tenants"] = tenants; //标签分组下拉框 SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId); ViewData["tagGroups"] = tagGroups; //取到用户设置的相关标签 ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>(); ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "图片不能为空"); return(View(tagEditModel)); } else if (!string.IsNullOrEmpty(fileName)) { //校验附件的扩展名 ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>(); if (!logoSettingsManager.Get().ValidateFileExtensions(fileName)) { //所属租户类型下拉框 SelectList tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId); ViewData["tenants"] = tenants; //标签分组下拉框 SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId); ViewData["tagGroups"] = tagGroups; //取到用户设置的相关标签 ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>(); ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为 .gif .jpg .jpeg .png 的文件"); return(View(tagEditModel)); } //校验附件的大小 TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Tag()); if (!tenantLogoSettings.ValidateFileLength(tagLogo.ContentLength)) { //所属租户类型下拉框 SelectList tenants = GetTenantSelectList(MultiTenantServiceKeys.Instance().Tag(), tagEditModel.TenantTypeId); ViewData["tenants"] = tenants; //标签分组下拉框 SelectList tagGroups = GetTagGroupSelectList(tagEditModel.GroupId, tagEditModel.TenantTypeId); ViewData["tagGroups"] = tagGroups; //取到用户设置的相关标签 ViewData["seletedTagNames"] = tagEditModel.RelatedTags[1].Split(',').ToList <string>(); ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength)); return(View(tagEditModel)); } stream = tagLogo.InputStream; tagEditModel.FeaturedImage = fileName; } } //获取相关标签 string relatedTags = tagEditModel.RelatedTags[1]; //创建 if (isCreate) { Tag tag = tagEditModel.AsTag(); tagService.Create(tag, stream); //添加到分组 if (tagEditModel.GroupId > 0) { tagService.BatchAddGroupsToTag(new List <long>() { tagEditModel.GroupId }, tagEditModel.TagName); } //创建相关标签 if (!string.IsNullOrEmpty(relatedTags)) { tagService.AddRelatedTagsToTag(relatedTags, 0, tag.TagId); } }//更新 else { Tag tag = tagEditModel.AsTag(); tagService.Update(tag, stream); //添加到分组 if (tagEditModel.GroupId > 0) { tagService.BatchAddGroupsToTag(new List <long>() { tagEditModel.GroupId }, tagEditModel.TagName); } //创建相关标签 if (!string.IsNullOrEmpty(relatedTags)) { tagService.ClearRelatedTagsFromTag(tagEditModel.TagId); tagService.AddRelatedTagsToTag(relatedTags, 0, tagEditModel.TagId); } } return(RedirectToAction("ManageTags")); }
public ActionResult _AutoCompletionSmtpSetting(SmtpSettingsEditModel model) { if (string.IsNullOrEmpty(model.UserEmailAddress) || model.UserEmailAddress.IndexOf("@") < 0) return Json(new StatusMessageData(StatusMessageType.Error, "请输入正确的邮箱之后,在继续尝试")); EmailServiceProvider emailProvider; string domainName = model.UserEmailAddress.Substring(model.UserEmailAddress.LastIndexOf('@') + 1); try { emailProvider = EmailServiceProviderService.Instance().GetEmailConfig()[domainName]; string userName = model.UserEmailAddress.Substring(0, model.UserEmailAddress.LastIndexOf('@')); model.EnableSsl = emailProvider.SmtpSettings.EnableSsl; model.ForceSmtpUserAsFromAddress = emailProvider.SmtpSettings.ForceSmtpUserAsFromAddress; model.Host = emailProvider.SmtpSettings.Host; model.Port = emailProvider.SmtpSettings.Port; model.RequireCredentials = emailProvider.SmtpSettings.RequireCredentials; model.UserName = emailProvider.SmtpSettings.UserName.Replace("username", userName); } catch (KeyNotFoundException) { //return Json(new StatusMessageData(StatusMessageType.Error, "检测失败,请完善更多设置")); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "检测失败,请手动设置更多选项"); } TempData["SmtpSettingsEditModel"] = model; return _EditOutBox(); }
public ActionResult EditTopic(TagEditModel tagEditModel) { System.IO.Stream stream = null; //是否创建 bool isCreate = tagEditModel.TagId == 0; if (isCreate) { ViewData["editTopicTitle"] = "创建话题"; } else { ViewData["editTopicTitle"] = "编辑话题"; } TagService tagService = new TagService(tagEditModel.TenantTypeId); IEnumerable<long> userIds = Request.Form.Gets<long>("RelatedObjectIds"); //是特色标签 if (tagEditModel.IsFeatured) { HttpPostedFileBase tagLogo = Request.Files["tagLogo"]; string fileName = tagLogo == null ? "" : tagLogo.FileName; if (string.IsNullOrEmpty(fileName) && string.IsNullOrEmpty(tagEditModel.FeaturedImage)) { //标签分组下拉框 SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId); ViewData["topicGroups"] = topicGroups; //取到用户设置的相关标签 ViewData["seletedUserIds"] = userIds; ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "图片不能为空"); return View(tagEditModel); } else if (!string.IsNullOrEmpty(fileName)) { //校验附件的扩展名 LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get(); if (!logoSettings.ValidateFileExtensions(fileName)) { //标签分组下拉框 SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId); ViewData["topicGroups"] = topicGroups; //取到用户设置的相关标签 ViewData["seletedUserIds"] = userIds; ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "只允许上传后缀名为 .gif .jpg .jpeg .png 的文件"); return View(tagEditModel); } //校验附件的大小 TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Tag()); if (!tenantLogoSettings.ValidateFileLength(tagLogo.ContentLength)) { //标签分组下拉框 SelectList topicGroups = GetTagGroupSelectList(tagEditModel.TopicGroupId, tagEditModel.TenantTypeId); ViewData["topicGroups"] = topicGroups; //取到用户设置的相关标签 ViewData["seletedUserIds"] = userIds; ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}KB", tenantLogoSettings.MaxLogoLength)); return View(tagEditModel); } stream = tagLogo.InputStream; tagEditModel.FeaturedImage = fileName; } } //获取相关微博 IEnumerable<long> seletedUserIds = userIds; //创建 if (isCreate) { Tag tag = tagEditModel.AsTag(); tagService.Create(tag, stream); //添加到分组 if (tagEditModel.TopicGroupId > 0) { tagService.BatchAddGroupsToTag(new List<long>() { tagEditModel.TopicGroupId }, tagEditModel.TagName); } }//更新 else { Tag tag = tagEditModel.AsTag(); tagService.Update(tag, stream); //添加到分组 if (tagEditModel.TopicGroupId > 0) { tagService.BatchAddGroupsToTag(new List<long>() { tagEditModel.TopicGroupId }, tagEditModel.TagName); } } return RedirectToAction("ManageMicroblogTopics"); }
public ActionResult ExtractEmoticon() { var emotionName = Request.Files["emotionName"]; if (emotionName.ContentLength == 0) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "您没有选择文件"); return RedirectToAction("ManageEmotionCategories"); } if (emotionName.FileName.IndexOf(".zip") == -1) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "您需要选择.zip格式的文件"); return RedirectToAction("ManageEmotionCategories"); } var judge = emotionService.GetEmotionCategory(emotionName.FileName.Remove(emotionName.FileName.IndexOf(".zip"))); if (judge != null) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "已存在同名文件"); return RedirectToAction("ManageEmotionCategories"); } try { emotionService.ExtractEmoticon(emotionName.FileName, emotionName.InputStream); } catch (Exception e) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, e.Message); return RedirectToAction("ManageEmotionCategories"); } TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "表情上传成功"); return RedirectToAction("ManageEmotionCategories"); }
public ActionResult _CreateRecommendType(RecommentItemTypeCreateModel recommendItemTypeCreateModel) { if (recommendItemTypeCreateModel == null || !ModelState.IsValid) return View(); RecommendItemType recommend = recommendItemTypeCreateModel.AsRecommendItemType(); ViewData["tenantList"] = GetTenantSelectList(recommendItemTypeCreateModel.TenantTypeId); RecommendItemType recommendType = recommendService.GetRecommendType(recommendItemTypeCreateModel.TypeId); if (recommendType != null) { WebUtility.SetStatusCodeForError(Response); ViewData["statusMessageData"] = new StatusMessageData(StatusMessageType.Error, "已经存在的Id"); return View(recommendItemTypeCreateModel); } bool isCreated = recommendService.CreateRecommendType(recommend); if (!isCreated) { WebUtility.SetStatusCodeForError(Response); ViewData["statusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建失败"); return View(recommendItemTypeCreateModel); } return Json(new StatusMessageData(StatusMessageType.Success, "创建成功")); }
public ActionResult BlockGroups(string spaceKey, List<long> groupIds) { int addCount = 0; long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); UserBlockService service = new UserBlockService(); if (userId > 0 && groupIds != null && groupIds.Count > 0) foreach (var groupId in groupIds) { GroupEntity group = groupService.Get(groupId); if (group == null || service.IsBlockedGroup(userId, groupId)) continue; service.BlockGroup(userId, group.GroupId, group.GroupName); addCount++; } if (addCount > 0) TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, string.Format("成功添加{0}个群组添加到屏蔽列表", addCount)); else TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "没有任何群组被添加到屏蔽列表中"); return Redirect(SiteUrls.Instance().BlockGroups(spaceKey)); }
public ActionResult _CustomCreateMessage(string spaceKey, MessageEditModel model) { EmotionService emotionService = DIContainer.Resolve<EmotionService>(); model.Body = emotionService.EmoticonTransforms(model.Body); User currentSpaceUser = (User)UserContext.CurrentUser; if (currentSpaceUser == null) return HttpNotFound(); IEnumerable<long> toUserIds = Request.Form.Gets<long>("ToUserIds"); IEnumerable<User> toUsers = userService.GetFullUsers(toUserIds); Message message = null; foreach (var toUser in toUsers) { if (DIContainer.Resolve<Authorizer>().Message(toUser.UserId)) { message = model.AsMessage(); message.MessageType = MessageType.Common; message.Receiver = toUser.DisplayName; message.ReceiverUserId = toUser.UserId; message.SenderUserId = (long)BuildinMessageUserId.CustomerService; message.Sender = "客服消息"; bool value = messageService.Create(message); } } if (message != null) return Json(new { messageId = message.MessageId }); else TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Hint, "您没有权限对此用户发送私信"); return Json(new { messageId = 0, hint = new StatusMessageData(StatusMessageType.Hint, "您没有权限对此用户发送私信") }); }
public ActionResult JoinGroup(long groupId) { //需判断是否已经加入过群组 StatusMessageData message = null; GroupEntity group = groupService.Get(groupId); if (group == null) return Json(new StatusMessageData(StatusMessageType.Error, "找不到群组!")); IUser currentUser = UserContext.CurrentUser; if (currentUser == null) return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")); if (group.JoinWay != JoinWay.Direct) return Json(new StatusMessageData(StatusMessageType.Error, "当前加入方式不是直接加入")); //已修改 //判断是否加入过该群组 bool isMember = groupService.IsMember(groupId, currentUser.UserId); //未加入 if (!isMember) { GroupMember member = GroupMember.New(); member.UserId = currentUser.UserId; member.GroupId = group.GroupId; member.IsManager = false; groupService.CreateGroupMember(member); message = new StatusMessageData(StatusMessageType.Success, "加入群组成功!"); } else { message = new StatusMessageData(StatusMessageType.Hint, "您已加入过该群组!"); } return Json(message); }
public JsonResult _DeletePosition(IEnumerable<string> positionIds) { StatusMessageData message = null; foreach (var positionId in positionIds) { advertisingService.DeletePosition(positionId); } message = new StatusMessageData(StatusMessageType.Success, "删除广告位成功!"); return Json(message); }
public JsonResult _QuitGroup(long groupId) { StatusMessageData message = new StatusMessageData(StatusMessageType.Success, "退出群组成功!"); GroupEntity group = groupService.Get(groupId); if (group == null) return Json(new StatusMessageData(StatusMessageType.Error, "找不到群组!")); IUser currentUser = UserContext.CurrentUser; if (currentUser == null) return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")); try { groupService.DeleteGroupMember(group.GroupId, currentUser.UserId); } catch { message = new StatusMessageData(StatusMessageType.Error, "退出群组失败!"); } return Json(message); }
public ActionResult LoginInModel(LoginEditModel model) { if (!ModelState.IsValid) { Tunynet.Utilities.WebUtility.SetStatusCodeForError(Response); return View("_LoginInModal", model); } //尝试登录 User user = model.AsUser(); //使用用户名作为用户名和邮件分别尝试登录 UserLoginStatus userLoginStatus = membershipService.ValidateUser(user.UserName, user.Password); if (userLoginStatus == UserLoginStatus.InvalidCredentials) { IUser userByEmail = userService.FindUserByEmail(user.UserName); if (userByEmail != null) { user = userByEmail as User; userLoginStatus = membershipService.ValidateUser(userByEmail.UserName, model.Password); } if (userLoginStatus != UserLoginStatus.InvalidCredentials && !userByEmail.IsEmailVerified) { return Json(new StatusMessageData(StatusMessageType.Error, "您的邮箱没有通过验证,请使用帐号登录")); } } else { user = userService.GetUser(model.UserName) as User; } if (userLoginStatus == UserLoginStatus.Success || (userLoginStatus == UserLoginStatus.NotActivated && userSettings.EnableNotActivatedUsersToLogin)) { Response.Cookies["returnUrl"].Expires = DateTime.Now; //让用户登录 user.UserId = UserIdToUserNameDictionary.GetUserId(user.UserName); authenticationService.SignIn(user, model.RememberPassword); return Json(new StatusMessageData(StatusMessageType.Success, "登录成功")); } string message; switch (userLoginStatus) { case UserLoginStatus.Banned: message = "用户被封禁"; break; case UserLoginStatus.InvalidCredentials: message = "用户名、密码不匹配"; break; case UserLoginStatus.NotActivated: message = "帐号未激活"; break; default: message = "未知错误"; break; } ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, message); Tunynet.Utilities.WebUtility.SetStatusCodeForError(Response); return View("_LoginInModal", model); }