/// <summary> /// 保存主题 /// </summary> /// <param name="reply"></param> public void SaveReply(TopicReply reply) { using (var trans = db.Database.BeginTransaction()) { try { db.TopicReplies.Add(reply); var topic = db.Topices.FirstOrDefault(x => x.Id == reply.TopicId); topic.LastReplyDate = DateTime.Now; topic.LastReplyUserId = reply.UserId; topic.ReplyCount = topic.ReplyCount + 1; db.SaveChanges(); trans.Commit(); base.IsSuccess = true; base.ReturnMsg = "保存成功"; } catch (Exception ex) { base.IsSuccess = true; base.ReturnMsg = "保存成功"; } } }
public async Task <ActionResult <TopicReplyViewModel> > PostTopicReply(TopicReplySubmit topicReplyS) { if (topicReplyS.Description == null || topicReplyS.UserName == null || topicReplyS.Description == "" || topicReplyS.UserName == "" || topicReplyS == null) { return(null); } Topic top = new Topic(); User usr = new User(); top = _context.Topic.Where(x => x.Id == topicReplyS.TopicId).FirstOrDefault(); //Если ничего не нашли то записываем как анонимного пользователя usr = (topicReplyS.isAnonym ? _context.User.Where(x => x.DisplayName.ToLower() == "anonym").FirstOrDefault() : _context.User.Where(x => x.DisplayName == topicReplyS.UserName).FirstOrDefault()); TopicReply tempt = new TopicReply(); tempt.TopicId = top.Id; tempt.UserId = usr.Id; tempt.UserDisplayname = topicReplyS.UserName; tempt.Description = topicReplyS.Description; _context.TopicReply.Add(tempt); await _context.SaveChangesAsync(); var topicReplyView = await _context.TopicReply.TopicReplyToTopicReplyViewModel().Where(x => x.Id == tempt.Id).FirstOrDefaultAsync(); return(CreatedAtAction("GetTopicReply", new { id = tempt.Id }, topicReplyView)); }
public async Task <IActionResult> PutTopicReply(int id, TopicReply topicReply) { if (id != topicReply.Id) { return(BadRequest()); } _context.Entry(topicReply).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TopicReplyExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Post([FromBody] TopicReply model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await this._repo.TopicCommentExists(model.TopicCommentId)) { return(NotFound("トピックコメントが見つかりませんでした。 ID:" + model.TopicCommentId)); } var member = await this._repo.GetMemberProfile(model.MemberId.GetValueOrDefault()); if (member == null) { return(NotFound("メンバーが見つかりませんでした。 ID:" + model.MemberId)); } model.MainPhotoUrl = member.AppUser.MainPhotoUrl; model.DisplayName = member.AppUser.DisplayName; _repo.Add(model); if (await _repo.SaveAll() > 0) { return(CreatedAtRoute("GetTopicReply", new { id = model.Id }, _mapper.Map <TopicReplyForReturnDto>(model))); } return(BadRequest("投稿に失敗しました")); }
public IActionResult Index(TopicReply reply) { if (ModelState.IsValid) { reply.Id = 0; reply.CreateOn = DateTime.Now; _context.TopicReplys.Add(reply); _context.SaveChanges(); } return(RedirectToAction("Index", "Topic", new { Id = reply.TopicId })); }
public IActionResult Index(TopicReply reply) { if (ModelState.IsValid) { reply.Id = 0; reply.CreateOn = DateTime.Now; _context.TopicReplys.Add(reply); _context.SaveChanges(); } return(Redirect("/topic?id=" + reply.TopicId)); }
public IActionResult Index([Bind("TopicId,ReplyUserId,ReplyEmail,ReplyContent")] TopicReply reply) { if (ModelState.IsValid && !string.IsNullOrEmpty(reply.ReplyContent)) { reply.CreateOn = DateTime.Now; _reply.Add(reply); var topic = _topic.GetById(reply.TopicId); topic.LastReplyUserId = reply.ReplyUserId; topic.LastReplyTime = reply.CreateOn; topic.ReplyCount += 1; _topic.Edit(topic); } return(RedirectToAction("Index", "Topic", new { Id = reply.TopicId })); }
public IActionResult Index(TopicReply reply) { if (ModelState.IsValid) { reply.Id = 0; reply.CreateOn = DateTime.Now; _context.TopicReplys.Add(reply); var topic = _context.Topics.Single(r => r.Id == reply.TopicId); topic.LastReplyUserId = reply.UserId; topic.LastReplyTime = reply.CreateOn; topic.ReplyCount += 1; _context.SaveChanges(); } return(RedirectToAction("Index", "Topic", new { Id = reply.TopicId })); }
public IActionResult Reply(Guid TopicId, string ReplyEmail, string Description) { if (HttpContext.User.Identity.IsAuthenticated) { TopicReply reply = new TopicReply { CreateDate = DateTime.Now, ReplyContent = Description, ReplyEmail = ReplyEmail, TopicId = TopicId, UserId = CurrentUser.Id, }; askService.SaveReply(reply); } return(Redirect("/Ask/Show/" + TopicId)); }
public async Task AddAsync(string topicId, string userId, string value) { var topic = this.topicRepository.AllAsNoTracking().Where(x => x.Id == topicId).FirstOrDefault(); if (topic == null) { throw new Exception("Topic does not exist!"); } var entity = new TopicReply() { TopicId = topicId, Value = value, UserId = userId, }; await this.topicReplyRepository.AddAsync(entity); await this.topicReplyRepository.SaveChangesAsync(); }
public async Task <IActionResult> Post([FromBody] TopicReply model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var topicComment = await this._topicRepo.GetTopicComment(model.TopicCommentId); if (topicComment == null) { return(NotFound("トピックコメントが見つかりませんでした。 ID:" + model.TopicCommentId)); } var appUser = await this._appUserRepo.GetAppUser(model.AppUserId.GetValueOrDefault()); if (appUser == null) { return(NotFound("メンバーが見つかりませんでした。 ID:" + model.AppUserId)); } model.PhotoId = appUser.MainPhotoId; model.DisplayName = appUser.DisplayName; _notificationRepo.Add(model); if (topicComment.AppUserId == model.AppUserId) { await this._notificationRepo.AddNotificationRepliedForTopicComment(topicComment); } else { await this._notificationRepo.AddNotificationNewPostOnTopicComment(appUser.Id, topicComment); } if (await _notificationRepo.SaveAll() > 0) { return(CreatedAtRoute("GetTopicReply", new { id = model.Id }, _mapper.Map <TopicReplyForReturnDto>(model))); } return(BadRequest("投稿に失敗しました")); }
public void GroupsDiscussRepliesAddTest() { var topicId = "72157630982877126"; var message = "Test message reply\n" + DateTime.Now.ToString("o"); var newMessage = "New Message reply\n" + DateTime.Now.ToString("o"); TopicReply reply = null; TopicReplyCollection topicReplies; try { AuthInstance.GroupsDiscussRepliesAdd(topicId, message); Thread.Sleep(1000); topicReplies = AuthInstance.GroupsDiscussRepliesGetList(topicId, 1, 100); reply = topicReplies.FirstOrDefault(r => r.Message == message); Assert.IsNotNull(reply, "Cannot find matching message."); AuthInstance.GroupsDiscussRepliesEdit(topicId, reply.ReplyId, newMessage); var reply2 = AuthInstance.GroupsDiscussRepliesGetInfo(topicId, reply.ReplyId); Assert.AreEqual(newMessage, reply2.Message, "Message should have been updated."); } finally { if (reply != null) { AuthInstance.GroupsDiscussRepliesDelete(topicId, reply.ReplyId); topicReplies = AuthInstance.GroupsDiscussRepliesGetList(topicId, 1, 100); var reply3 = topicReplies.FirstOrDefault(r => r.ReplyId == reply.ReplyId); Assert.IsNull(reply3, "Reply should not exist anymore."); } } }
public PartialViewResult TopicReply(int Id, int?page, string viewName = "TopicReply", string ajaxvName = "TopicReplyList") { //if (!bllTopic.Exists(Id) || !bllTopic.UpdatePVCount(Id)) //{ // return RedirectToAction("Index", "Group"); // ViewBag.support = "nosupport"; if (null != CurrentUser) { HttpCookie cookie = Request.Cookies["topicFav_" + Id + CurrentUser.UserID]; if (null != cookie) //取消赞 { ViewBag.support = "support"; } } YSWL.MALL.ViewModel.SNS.TopicReply Model = new TopicReply(); Model.Topic = bllTopic.GetModel(Id); ViewBag.Activity = "invalid"; if (null != Model.Topic && null != CurrentUser) { if (Model.Topic.CreatedUserID == CurrentUser.UserID) //自己的帖子 { ViewBag.Activity = "active"; } } //重置页面索引 page = page.HasValue && page.Value > 1 ? page.Value : 1; ViewBag.page = page + 1; //页大小 int pagesize = 10; //计算分页起始索引 int startIndex = page.Value > 1 ? (page.Value - 1) * pagesize + 1 : 1; //计算分页结束索引 int endIndex = page.Value * pagesize; //总记录数 int toalcount = bllReply.GetRecordCount(" Status=1 and TopicID =" + Id); List <YSWL.MALL.Model.SNS.GroupTopicReply> list = bllReply.GetTopicReplyByTopic(Id, startIndex, endIndex); if (list != null && list.Count > 0) { Model.TopicsReply = new PagedList <YSWL.MALL.Model.SNS.GroupTopicReply>(list, page ?? 1, pagesize, toalcount); } if (Request.IsAjaxRequest()) { return(PartialView(ajaxvName, Model)); } Model.UserJoinGroups = bllGroups.GetUserJoinGroup(Model.Topic != null ? Model.Topic.CreatedUserID : 0, 9); Model.HotTopic = bllTopic.GetHotListByGroup(Model.Topic.GroupID, 9); Model.Group = bllGroups.GetModel(Model.Topic.GroupID); Model.UserPostTopics = bllTopic.GetTopicByUserId(Model.Topic.CreatedUserID, 9); #region SEO 优化设置 IPageSetting pageSetting = PageSetting.GetPageSetting("GroupDetail", ApplicationKeyType.SNS); pageSetting.Replace( new[] { PageSetting.RKEY_CNAME, Model.Group.GroupName }, //小组名称 new[] { PageSetting.RKEY_CTNAME, Model.Topic.Title }, //帖子标题 new[] { PageSetting.RKEY_CTAG, Model.Topic.Tags }, //帖子标签 new[] { PageSetting.RKEY_CDES, Model.Topic.Description }); //帖子内容 ViewBag.Title = pageSetting.Title; ViewBag.Keywords = pageSetting.Keywords; ViewBag.Description = pageSetting.Description; #endregion return(PartialView(viewName, Model)); }