/// <summary> /// 创建话题 /// </summary> public async Task <Topic> CreateAsync(TopicEditModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (string.IsNullOrWhiteSpace(model.Name)) { throw new ModelException(nameof(model.Name), "话题名称不能为空"); } using (var work = this.dbFactory.StartWork()) { Topic old = await work.Topic.GetByNameAsync(model.Name.Trim()); if (old != null) { throw new ModelException(nameof(model.Name), "该话题名称已存在"); } Topic topic = ObjectMapper.Map <TopicEditModel, Topic>(model); topic.IsAnnounce = false; topic.Id = GuidHelper.CreateSequential(); await work.Topic.InsertAsync(topic); return(topic); } }
public async Task <ActionResult> Edit(Guid id) { Topic topic = await this.topicService.GetByIdAsync(id); TopicEditModel model = ObjectMapper.Map <Topic, TopicEditModel>(topic); return(View(model)); }
// GET: Topic/Create public ActionResult Create() { var topicEditModel = new TopicEditModel() { Topics = topicFacade.GetAllTopics() }; return(View(topicEditModel)); }
// GET: Topic/Edit/5 public ActionResult Edit(int id) { var topicEditModel = new TopicEditModel() { Topic = topicFacade.GetTopicByID(id), Topics = topicFacade.GetAllTopics() }; return(View(topicEditModel)); }
public ActionResult Edit(TopicEditModel model) { try { topicFacade.EditTopic(model.Topic, model.SelectedParent); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IActionResult> Edit(TopicEditModel model) { if (ModelState.IsValid) { await _postService.UpdateContent(model.HeadId, model.Content); await _topicService.UpdateTitle(model.Id, model.Title); return(RedirectToAction("Index", "Topic", new { id = model.Id })); } return(View(model)); }
public ActionResult Create() { pageResourceManager.InsertTitlePart("创建专题"); string errorMessage = null; if (!authorizer.Topic_Create(out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = errorMessage, StatusMessageType = StatusMessageType.Hint }))); } TopicEditModel group = new TopicEditModel(); return(View(group)); }
public async Task <Topic> ModifyAsync(TopicEditModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (model.Id == null) { throw new ArgumentNullException(nameof(model.Id)); } if (string.IsNullOrWhiteSpace(model.Name)) { throw new ModelException(nameof(model.Name), "话题名称不能为空"); } using (var work = this.dbFactory.StartWork()) { Topic topic = await work.Topic.SingleByIdAsync(model.Id.Value); if (topic == null) { throw new ModelException(nameof(model.Name), "该话题不存在或已被删除"); } if (!string.Equals(model.Name, topic.Name, StringComparison.OrdinalIgnoreCase)) { Topic old = await work.Topic.GetByNameAsync(model.Name.Trim()); if (old != null) { throw new ModelException(nameof(model.Name), "该话题名称已存在"); } } if (topic.IsAnnounce) { throw new ModelException(nameof(model.Name), "公告为系统默认,不能被修改"); } ObjectMapper.CopyValues <TopicEditModel, Topic>(model, topic); topic.IsAnnounce = false; await work.Topic.UpdateAsync(topic); return(await work.Topic.SingleByIdAsync(model.Id.Value)); } }
public IActionResult TopicEdit(TopicEditModel model, int id) { Topic topic = db.Topics.Find(id); if (ModelState.IsValid) { if (model.Description != null) { topic.Description = model.Description; } if (model.Name != null) { topic.Name = model.Name; } db.SaveChanges(); return(RedirectToAction("List", "Forum")); } ViewBag.CurrentTopic = topic; return(View()); }
public IActionResult Edit(int id) { var topic = _topicService.GetById(id); if (topic != null) { var head = topic.Posts.Where(post => post.IsHead == true).First(); var model = new TopicEditModel { ForumTitle = topic.Forum.Title, TopicStarterName = head.User.UserName, HeadId = head.Id, Title = topic.Title, Content = head.Content, }; return(View(model)); } return(RedirectToAction("Index", "Forum")); }
public ActionResult EditTopic(string spaceKey) { TopicEntity group = groupService.Get(spaceKey); //已修改 if (group == null) { return(HttpNotFound()); } pageResourceManager.InsertTitlePart(group.TopicName); pageResourceManager.InsertTitlePart("编辑专题"); //编辑的时候需要显示已添加的标签 IEnumerable <string> tags = group.TagNames; TopicEditModel groupEditModel = group.AsEditModel(); ViewData["tags"] = tags; TempData["TopicMenu"] = TopicMenu.TopicSettings; return(View(groupEditModel)); }
public async Task <ActionResult> Edit(TopicEditModel model) { if (ModelState.IsValid) { try { Topic topic = await topicService.ModifyAsync(model); return(this.Json(AjaxResult.CreateByContext(topic))); } catch (ModelException ex) { return(this.Json(ex.ToAjaxResult())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } } else { return(this.Json(ModelState.ToAjaxResult())); } }
public ActionResult Create(TopicEditModel 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.Topic_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().Topic()); 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; } TopicEntity topic = groupEditModel.AsTopicEntity(); bool result = topicService.Create(user.UserId, topic); if (stream != null) { topicService.UploadLogo(topic.TopicId, stream); } //设置分类 if (groupEditModel.CategoryId > 0) { categoryService.AddItemsToCategory(new List <long>() { topic.TopicId }, groupEditModel.CategoryId); } //设置标签 string relatedTags = Request.Form.Get <string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.AddTagsToItem(relatedTags, topic.TopicId, topic.TopicId); } //发送邀请 if (!string.IsNullOrEmpty(groupEditModel.RelatedUserIds)) { //已修改 IEnumerable <long> userIds = Request.Form.Gets <long>("RelatedUserIds", null); topicService.SendInvitations(topic, user, string.Empty, userIds); } return(Redirect(SiteUrls.Instance().TopicHome(topic.TopicKey))); }
public ActionResult EditTopic(string spaceKey, TopicEditModel groupEditModel) { IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!"))); } System.IO.Stream stream = null; HttpPostedFileBase groupLogo = Request.Files["TopicLogo"]; if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Topic()); 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; } TopicEntity group = groupEditModel.AsTopicEntity(); //设置分类 if (groupEditModel.CategoryId > 0) { categoryService.ClearCategoriesFromItem(group.TopicId, 0, TenantTypeIds.Instance().Topic()); categoryService.AddItemsToCategory(new List <long>() { group.TopicId }, groupEditModel.CategoryId); } //已修改 //设置标签 string relatedTags = Request.Form.Get <string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.ClearTagsFromItem(group.TopicId, group.TopicId); tagService.AddTagsToItem(relatedTags, group.TopicId, group.TopicId); } if (stream != null) { groupService.UploadLogo(group.TopicId, stream); } groupService.Update(currentUser.UserId, group); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!"); return(Redirect(SiteUrls.Instance().EditTopic(group.TopicKey))); }
public ActionResult Create() { TopicEditModel model = new TopicEditModel(); return(View(model)); }
public ActionResult EditTopic(string spaceKey, TopicEditModel topicEditModel) { IUser currentUser = UserContext.CurrentUser; if (currentUser == null) return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")); System.IO.Stream stream = null; HttpPostedFileBase topicLogo = Request.Files["TopicLogo"]; if (topicLogo != null && !string.IsNullOrEmpty(topicLogo.FileName)) { TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Topic()); if (!tenantLogoSettings.ValidateFileLength(topicLogo.ContentLength)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024))); return View(topicEditModel); } LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get(); if (!logoSettings.ValidateFileExtensions(topicLogo.FileName)) { ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions); return View(topicEditModel); } stream = topicLogo.InputStream; topicEditModel.Logo = topicLogo.FileName; } TopicEntity topic = topicEditModel.AsTopicEntity(); //设置分类 if (topicEditModel.CategoryId > 0) { categoryService.ClearCategoriesFromItem(topic.TopicId, 0, TenantTypeIds.Instance().Topic()); categoryService.AddItemsToCategory(new List<long>() { topic.TopicId }, topicEditModel.CategoryId); } //已修改 //设置标签 string relatedTags = Request.Form.Get<string>("RelatedTags"); if (!string.IsNullOrEmpty(relatedTags)) { tagService.ClearTagsFromItem(topic.TopicId, topic.TopicId); tagService.AddTagsToItem(relatedTags, topic.TopicId, topic.TopicId); } if (stream != null) { topicService.UploadLogo(topic.TopicId, stream); } topicService.Update(currentUser.UserId, topic); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!"); return Redirect(SiteUrls.Instance().EditTopic(topic.TopicKey)); }