public ActionResult _EditPhoto(string spaceKey, PhotoEditModel photoEditModel) { IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(Json(new StatusMessageData(StatusMessageType.Hint, "您尚未登录!"))); } Photo photo = photoEditModel.AsPhoto(); if (!authorizer.Photo_Edit(photo)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有编辑照片的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint }))); } //设置标签 string relatedTags = Request.Form.Get <string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.ClearTagsFromItem(photo.PhotoId, photo.UserId); tagService.AddTagsToItem(relatedTags, photo.UserId, photo.PhotoId); } photoService.UpdatePhoto(photo, currentUser.UserId); return(Json(new { description = photo.Description })); }
public JsonResult _SetTags(string photoIds, string tagNames) { photoIds = photoIds.TrimEnd(','); string[] photoIdsArray = photoIds.Split(','); tagNames = Request.Form.Get <string>("tagNames", string.Empty); for (int i = 0; i < photoIdsArray.Length; i++) { long photoId = Convert.ToInt64(photoIdsArray[i]); tagService.AddTagsToItem(tagNames, photoService.GetPhoto(photoId).UserId, photoId); } return(Json(new StatusMessageData(StatusMessageType.Success, "操作成功"))); }
public ActionResult _SetPhotoTag(long photoId) { string tags = Request.Form.Get <string>("tags", null); ISettingsManager <TagSettings> tagSettingsManager = DIContainer.Resolve <ISettingsManager <TagSettings> >(); TagSettings tagSettings = tagSettingsManager.Get(); if (tags != null && tags.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries).Count() > tagSettings.MaxTagsCount) { return(Json(new StatusMessageData(StatusMessageType.Error, "由于标签超过设置,所以贴标签失败"))); } Photo photo = photoService.GetPhoto(photoId); tagService.ClearTagsFromItem(photoId, photo.UserId); tagService.AddTagsToItem(tags, photo.UserId, photo.PhotoId); return(Json(new StatusMessageData(StatusMessageType.Success, "贴标签成功"))); }
public ActionResult EditContentItem(ContentItemEditModel model) { ContentItem item = model.AsContentItem(Request); try { if (item.ContentItemId > 0) { contentItemService.Update(item); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功"); //清除标签 tagService.ClearTagsFromItem(item.ContentItemId, item.UserId); } else { item.GlobalStickyDate = ValueUtility.GetSafeSqlDateTime(DateTime.MinValue); item.FolderStickyDate = ValueUtility.GetSafeSqlDateTime(DateTime.MinValue); contentItemService.Create(item); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "创建成功"); } } catch (Exception) { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建或者更新失败,请重试"); TempData["ContentItemEditModel"] = model; return(Redirect(SiteUrls.Instance().EditContentItem(item.ContentItemId))); } if (model.TagNames != null) { string tags = string.Join(",", model.TagNames); if (!string.IsNullOrEmpty(tags)) { tagService.AddTagsToItem(tags, item.UserId, item.ContentItemId); } } if (item.ContentType != null && item.ContentType.ContentTypeKey == ContentTypeKeys.Instance().NewsLink()) { return(Redirect(SiteUrls.Instance().FolderDetail(item.ContentFolderId))); } return(Redirect(SiteUrls.Instance().ContentItemDetail(item.ContentItemId))); }
public ActionResult EditPage(WikiPageEditModel editModel) { if (UserContext.CurrentUser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } //声明必要的变量 WikiPage page = null; WikiPageVersion pageVersion = null; #region 敏感词过滤 string errorMessage = string.Empty; if (ModelState.HasBannedWord(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = errorMessage, StatusMessageType = StatusMessageType.Error }))); } #endregion if (editModel.PageId < 1)//新建词条 { page = editModel.AsWikiPage(); bool valid = wikiService.IsExists(page.Title); if (valid) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布同名词条失败", Body = "发布失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } bool isCreated = wikiService.Create(page, editModel.Body); if (page.PageId < 1) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = "发布失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } pageVersion = page.LastestVersion; } else//编辑词条 { //userFocusCategoryService.del page = wikiService.Get(editModel.PageId); if (page == null) { return(HttpNotFound()); } //判断一下是否可以编辑 bool IsCanEdit = !page.IsLocked; IUser user = UserContext.CurrentUser; if (page.OwnerId == user.UserId || DIContainer.Resolve <Authorizer>().IsAdministrator(ApplicationIds.Instance().Wiki())) { IsCanEdit = true; } if (!IsCanEdit) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "编辑失败", Body = "编辑失败,该词条已经被锁定,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } categoryService.DeleteItemInCategory(page.SiteCategory.CategoryId, page.PageId); page = editModel.AsWikiPage(); wikiService.Update(page); pageVersion = editModel.AsWikiPageVersion(); pageVersion.PageId = page.PageId; wikiService.CreatePageVersion(pageVersion); if (pageVersion.VersionId < 1) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "编辑失败", Body = "编辑失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } } #region 分类、标签 if (editModel.SiteCategoryId > 0) { categoryService.AddCategoriesToItem(new List <long> { editModel.SiteCategoryId }, page.PageId); } string tags = string.Join(",", editModel.TagNames); if (!string.IsNullOrEmpty(tags)) { tagService.ClearTagsFromItem(page.PageId, pageVersion.UserId); tagService.AddTagsToItem(tags, pageVersion.UserId, page.PageId); } #endregion return(Redirect(SiteUrls.Instance().PageDetail(page.PageId))); }
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.Error }))); } System.IO.Stream stream = null; HttpPostedFileBase groupLogo = Request.Files["GroupLogo"]; //已修改 IUser user = UserContext.CurrentUser; if (user == null) { return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!"))); } if (!new Authorizer().Group_Create(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = errorMessage, StatusMessageType = StatusMessageType.Error }))); } 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 <ILogoSettingsManager>().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, 0); } //设置标签 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 Edit(string spaceKey, BlogThreadEditModel model) { string errorMessage = string.Empty; if (ModelState.HasBannedWord(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = errorMessage, StatusMessageType = StatusMessageType.Error }))); } BlogThread blogThread = null; //写日志 if (model.ThreadId == 0) { if (!authorizer.BlogThread_Create(spaceKey, out errorMessage)) { if (model.IsDraft) { return(Json(new StatusMessageData(StatusMessageType.Error, "没有权限创建新的日志!"))); } else { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = errorMessage, StatusMessageType = StatusMessageType.Error }))); } } blogThread = model.AsBlogThread(); bool isCreated = blogService.Create(blogThread); if (!isCreated) { if (model.IsDraft) { return(Json(new StatusMessageData(StatusMessageType.Error, "发布失败,请稍后再试!"))); } else { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发布失败", Body = "发布失败,请稍后再试!", StatusMessageType = StatusMessageType.Error }))); } } } //编辑日志 else { blogThread = model.AsBlogThread(); if (!authorizer.BlogThread_Edit(blogThread)) { if (model.IsDraft) { return(Json(new StatusMessageData(StatusMessageType.Error, "没有权限编辑" + blogThread.Subject + "!"))); } else { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = "没有权限编辑" + blogThread.Subject + "!", StatusMessageType = StatusMessageType.Error }))); } } //如果之前是草稿,现在正式发布,那么需要先删除草稿,然后创建新的日志 BlogThread oldBlogThread = blogService.Get(blogThread.ThreadId); if (oldBlogThread.IsDraft && !blogThread.IsDraft) { blogService.Delete(oldBlogThread); bool isCreated = blogService.Create(blogThread); } else { blogService.Update(blogThread); //清除用户分类 categoryService.ClearCategoriesFromItem(blogThread.ThreadId, blogThread.OwnerId, TenantTypeIds.Instance().BlogThread()); if (blogSettings.AllowSetSiteCategory) { //清除站点分类(投稿到) categoryService.ClearCategoriesFromItem(blogThread.ThreadId, 0, TenantTypeIds.Instance().BlogThread()); } //清除标签 tagService.ClearTagsFromItem(blogThread.ThreadId, blogThread.UserId); } } //设置隐私状态 UpdatePrivacySettings(blogThread, model.PrivacyStatus1, model.PrivacyStatus2); //设置用户分类 if (!string.IsNullOrEmpty(model.OwnerCategoryIds)) { string[] ownerCategoryIds = model.OwnerCategoryIds.TrimEnd(',').Split(','); categoryService.AddCategoriesToItem(ownerCategoryIds.Select(n => long.Parse(n)), blogThread.ThreadId, blogThread.OwnerId); } if (blogSettings.AllowSetSiteCategory) { //设置站点分类(投稿到) if (model.SiteCategoryId.HasValue) { categoryService.AddCategoriesToItem(new List <long> { model.SiteCategoryId.Value }, blogThread.ThreadId, 0); } } string tags = string.Join(",", model.TagNames); if (!string.IsNullOrEmpty(tags)) { tagService.AddTagsToItem(tags, blogThread.UserId, blogThread.ThreadId); } //如果是保存草稿,则返回Json if (blogThread.IsDraft) { return(Json(new { MessageType = StatusMessageType.Success, MessageContent = "保存成功!", ThreadId = blogThread.ThreadId })); } else { return(Redirect(SiteUrls.Instance().BlogDetail(spaceKey, blogThread.ThreadId))); //return Json(new { MessageType = StatusMessageType.Success, MessageContent = SiteUrls.Instance().BlogDetail(spaceKey, blogThread.ThreadId), ThreadId = blogThread.ThreadId }); } }
public ActionResult EditGroup(string spaceKey, GroupEditModel groupEditModel) { IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!"))); } System.IO.Stream stream = null; HttpPostedFileBase groupLogo = Request.Files["GroupLogo"]; 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 <ILogoSettingsManager>().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(); //设置分类 if (groupEditModel.CategoryId > 0) { categoryService.ClearCategoriesFromItem(group.GroupId, 0, TenantTypeIds.Instance().Group()); categoryService.AddItemsToCategory(new List <long>() { group.GroupId }, groupEditModel.CategoryId, 0); } //已修改 //设置标签 string relatedTags = Request.Form.Get <string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.ClearTagsFromItem(group.GroupId, group.GroupId); tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId); } if (stream != null) { groupService.UploadLogo(group.GroupId, stream); } groupService.Update(currentUser.UserId, group); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!"); return(Redirect(SiteUrls.Instance().EditGroup(group.GroupKey))); }
public ActionResult Contribute(ContentItemEditModel model) { ContentItem item = model.AsContentItem(Request); var contentItemService = new ContentItemService(); string errorMessage = string.Empty; if (item.ContentItemId > 0) { if (!authorizer.CMS_EditContentItem(item)) { errorMessage = "没有权限编辑资讯:" + item.Title; return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Hint }, Request.RawUrl))); } } else { if (!authorizer.CMS_Contribute(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Hint }, Request.RawUrl))); } } try { if (item.ContentItemId > 0) { contentItemService.Update(item); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功"); //清除标签 tagService.ClearTagsFromItem(item.ContentItemId, item.UserId); } else { if (!authorizer.CMS_ManageContentFolder(item.ContentFolder)) { item.IsContributed = true; } item.ReleaseDate = DateTime.UtcNow; contentItemService.Create(item); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "创建成功"); } } catch { TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建或者更新失败,请重试"); TempData["ContentItemEditModel"] = model; return(Redirect(SiteUrls.Instance().Contribute(item.ContentItemId))); } string tags = string.Join(",", model.TagNames); if (!string.IsNullOrEmpty(tags)) { tagService.AddTagsToItem(tags, item.UserId, item.ContentItemId); } return(Redirect(SiteUrls.Instance().ContentItemDetail(item.ContentItemId))); }