public ActionResult SaveReply(Reply reply, int postId) { if (!ModelState.IsValid) { var viewModel = new ReplyViewModel { PostId = postId, Reply = reply }; return(View("ReplyForm", viewModel)); } if (reply.Id == 0) { reply.DateCreated = DateTime.Now; reply.AuthorId = User.Identity.GetUserId(); reply.Post = _unitOfWork.Posts.GetById(postId); _unitOfWork.Replies.Add(reply); } else { var replyInDb = _unitOfWork.Replies.SingleOrDefault(r => r.Id == reply.Id); if (replyInDb.AuthorId != User.Identity.GetUserId()) { return(HttpNotFound()); } replyInDb.Text = reply.Text; } _unitOfWork.Complete(); return(RedirectToAction("Post", "Forum", new { id = postId })); }
public static bool TrySaveReply(ReplyViewModel replyView, int postId) { bool emptyContent = !replyView.Content.Any(); if (emptyContent) { return(false); } var forumData = new ForumData(); int replyId = forumData.Replies.Any() ? forumData.Replies.Last().Id + 1 : 1; User author = UserService.GetUser(replyView.Author); int authorId = author.Id; var content = string.Join("", replyView.Content); Reply reply = new Reply(replyId, content, authorId, postId); forumData.Replies.Add(reply); forumData.Posts.First(p => p.Id == postId).ReplyIds.Add(replyId); forumData.SaveChages(); //replyView.PostId = postId; return(true); }
public ActionResult Create([Bind(Include = "Id,Title,Body,Created,TopicId")] ReplyViewModel replyViewModel) { if (ModelState.IsValid) { Reply reply = new Reply { //Id = replyViewModel.Id, Title = replyViewModel.Title, Body = replyViewModel.Body, Created = replyViewModel.Created, TopicId = replyViewModel.TopicId }; _repo.AddReply(reply); _repo.Save(); replyViewModel.Topics = _repo.GetTopics().ToList().Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Title }); //return RedirectToAction("Index"); } return(View(replyViewModel)); }
public ActionResult PostReply(ReplyViewModel obj) { int userId = Convert.ToInt32(Session["UserId"]); if (userId == 0) { return(RedirectToAction("Login", "Account")); } Reply reply = new Reply(); reply.Text = obj.Reply; reply.CommentId = obj.CID; reply.UserId = userId; reply.CreatedOn = DateTime.Now; User user = new User(); if (user.Id == userId) { user.Rank += 1; } db.Replies.Add(reply); db.SaveChanges(); return(RedirectToAction("QuestionDetail")); }
/// <summary> /// /// </summary> /// <param name="_data"></param> /// <returns>20200922</returns> public ReplyViewModel DataFrigo() { ReplyViewModel reply = new ReplyViewModel(); try { List <BancoBgViewModelReply> _model = new List <BancoBgViewModelReply>(); reply.messege = "success"; _model = _RedisCache.Get <List <BancoBgViewModelReply> >("_redisFrigo"); reply.status = "Ok"; //var _Reply = _taskCampaignDao.GetStatusTask(_data.IdAccount).Select(x => new CampaignModelReply //{ // Id = x.Id, // Name = x.Name //}).ToList(); ; reply.data = _model.ToList(); return(reply); } catch (Exception e) { reply.messege = "No existen datos"; reply.data = e.Message; reply.status = "Fallo la consulta"; return(reply); } }
public ActionResult Reply(ReplyViewModel replyViewModel) { ObjectId objectId = new ObjectId(replyViewModel.Id); var actor = userManager.GetUserAsync(HttpContext.User).Result; var post = mongoContext.Posts.Find(p => p.Id.Equals(objectId)).First(); Post reply = new Post { Id = ObjectId.GenerateNewId(), Date = DateTime.Now, Description = replyViewModel.Description, Photo = replyViewModel.Photo, Url = replyViewModel.Url, Writer = actor.Email, Replies = new List <ObjectId>(), Principal = false }; post.Replies.Add(reply.Id); this.mongoContext.Posts.InsertOne(reply); UpdateDefinition <Post> updateDefinition = Builders <Post> .Update.Set("Replies", post.Replies); mongoContext.Posts.FindOneAndUpdate(p => p.Id.Equals(objectId), updateDefinition); return(RedirectToAction(nameof(Index))); }
public IActionResult Reply(int commentId) { try { var comment = this.dbContext.Comments.FirstOrDefault(x => x.Id == commentId); if (comment == null) { return(this.RedirectToAction("All")); } var user = this.dbContext.Users.FirstOrDefault(x => x.Id == comment.UserId); var @event = this.dbContext.Events.FirstOrDefault(x => x.Id == comment.EventId); var replyComment = new ReplyCommentViewModel { EventId = comment.EventId, EventName = @event.Title, Messege = comment.Messege, PostedOn = comment.PostedOn, UserId = comment.UserId, Username = comment.Username }; var reply = new ReplyViewModel { Img = user.Img, ReplyComment = replyComment, UserId = comment.UserId, CommentId = comment.Id, Username = comment.Username }; return(this.View(reply)); } catch (Exception) { return(this.View("Error")); } }
public IActionResult <TopicDetailsViewModel> Details(HttpSession session, string topicTitle) { string topicDecoded = WebUtility.UrlDecode(topicTitle); var topic = this.data.Topics.FindByPredicate(t => t.Title == topicDecoded); var tdvm = new TopicDetailsViewModel() { Title = topic.Title, Author = topic.Author.Username, Content = topic.Content, PostedOn = topic.PublishDate.Value.ToString(), UserLogged = this.signInManager.IsAuthenticated(session) }; foreach (Reply reply in topic.Replies) { ReplyViewModel rvm = new ReplyViewModel() { Author = reply.Author.Username, Content = reply.Content, Date = reply.PublishDate.ToString(), ImgUrl = reply.ImageUrl }; tdvm.ReplyViewModels.Add(rvm); } return(this.View(tdvm)); }
public async Task <IActionResult> PostReply(ReplyViewModel replyView) { try { if (!this.ModelState.IsValid) { return(this.View("Reply", replyView)); } if (replyView == null) { return(this.RedirectToAction("All")); } var user = await this.userManager.GetUserAsync(this.User); var reply = new Reply { PostedOn = DateTime.Now, Username = user.UserName, CommentId = replyView.CommentId, Content = replyView.Content, UserId = replyView.UserId }; var comment = this.dbContext.Comments.FirstOrDefault(x => x.Id == reply.CommentId); reply.UserId = user.Id; await this.replyRepository.AddAsync(reply); await this.replyRepository.SaveChangesAsync(); return(this.RedirectToAction("ById", "Events", new { Id = comment.EventId })); } catch (Exception) { return(this.View("Error")); } }
public ActionResult Reply(ReplyViewModel model) { var report = _reportLogic.GetById(model.Id); report.Reply = model.Comment; report.RepliedDate = DateTime.Now; _reportLogic.Edit(report); try { var msg = new MailMessage(); msg.To.Add(new MailAddress(report.Email)); msg.Subject = "LAPOR-BRANTAS Jawaban Laporan"; msg.Body = model.Comment; msg.From = new MailAddress("*****@*****.**"); using (var client = new SmtpClient() { Host = "relay-hosting.secureserver.net", Port = 25, EnableSsl = false, UseDefaultCredentials = false }) { client.Send(msg); } } catch (Exception ex) { } return(RedirectToAction("Index")); }
public ActionResult _ReplyPartial([Bind(Include = "ReplyId,CommentId,UserId,RepComment,TimeRep")] ReplyViewModel replys) { if (Session["UserId"] != null) { replys.UserId = ((int)Session["UserId"]); } else if (Session["AdminId"] != null) { replys.UserId = ((int)Session["AdminId"]); } else { ViewBag.Message = "Bạn cần phải đăng nhập"; return(PartialView()); } if (ModelState.IsValid) { var reply = Mapper.Map <ReplyViewModel, Replys>(replys); replyService.CreateReply(reply); replyService.SaveReply(); var r = GetListReplys().Where(i => i.ReplyId == reply.ReplyId).FirstOrDefault(); //replyService.GetReply(reply.ReplyId); return(PartialView(r)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Reply(int?id) { if (id == null) { return(NotFound()); } var identity = (ClaimsIdentity)this.User.Identity; var claim = identity.FindFirst(ClaimTypes.NameIdentifier); Message message = await _context.Messages.Where(m => m.ReceiverID == claim.Value || m.WriterID == claim.Value).FirstOrDefaultAsync(m => m.ID == id); if (message == null) { return(NotFound()); } ReplyViewModel replyModel = new ReplyViewModel() { Message = message, Reply = new Message() }; return(View(replyModel)); }
public ActionResult Reply(int id) { ReplyViewModel assign = new ReplyViewModel(); assign.Id = id; return(View(assign)); }
public static bool TryAddReply(PostViewModel post, ReplyViewModel reply) { if (reply.Content is null) { return(false); } var replyContent = string.Join("", reply.Content); if (string.IsNullOrWhiteSpace(replyContent)) { return(false); } var replies = ForumData.GetInstance().Replies; var author = ForumData.GetInstance().Users.Find(u => u.Username == reply.Author); var replyId = replies.Any() ? replies.Last().Id + 1 : 1; var replyModel = new Reply(replyId, replyContent, author.Id, post.PostId); replies.Add(replyModel); ForumData.GetInstance().SaveChanges(); return(true); }
internal static bool TryAddReply(int postId, ReplyViewModel replyView) { bool emptyAuthor = string.IsNullOrWhiteSpace(replyView.Author); bool emptyContent = !replyView.Content.Any(x => x.Trim().Length > 0); if (emptyContent || emptyAuthor) { return(false); } var forumData = new ForumData(); var replies = forumData.Replies; int replyId = replies.Any() ? replies.Last().Id + 1 : 1; User author = UserService.GetUser(replyView.Author); Post post = forumData.Posts.Find(p => p.Id == postId); int authorId = author.Id; string content = string.Join("", replyView.Content); var reply = new Reply(replyId, content, authorId, postId); forumData.Replies.Add(reply); post.ReplyIds.Add(replyId); forumData.SaveChanges(); return(true); }
public static bool TrySaveReply(ReplyViewModel replyViewModel, int postId) { if (!replyViewModel.Content.Any()) { return(false); } var forumData = new ForumData(); var author = UserService.GetUser(replyViewModel.Author, forumData); var post = forumData.Posts.Single(p => p.Id == postId); var replyId = forumData.Replies.LastOrDefault()?.Id + 1 ?? 1; var content = string.Join("", replyViewModel.Content); var reply = new Reply(replyId, content, author.Id, postId); forumData.Replies.Add(reply); post.ReplyIds.Add(replyId); forumData.SaveChanges(); return(true); }
public IActionResult ReplyForm(ReplyViewModel vm) { if (vm.MessageReply.Body.ToLower().Contains("haha")) { string prop = "MessageReply.Body"; ModelState.AddModelError(prop, "Why are you laughing??"); } if (ModelState.IsValid) { Message message = repository.GetAllMessages().Where(m => m.MessageID == vm.MessageID).FirstOrDefault(); message.MessageReplies.Add(new Reply { Body = vm.MessageReply.Body, DateCreated = DateTime.Now }); repository.Update(message); return(RedirectToAction("Index", "Message")); } else { return(View(vm)); } }
public async Task <IActionResult> Reply(int id) { ReplyViewModel vm = new ReplyViewModel() { Topic = await _topicRepository.GetById(id) }; // Manually set breadcrumb nodes var childNode1 = new MvcBreadcrumbNode("Forum", "Home", vm.Topic.Forum.Title) { RouteValues = new { id = vm.Topic.Forum.Id } }; var childNode2 = new MvcBreadcrumbNode("Topic", "Home", vm.Topic.Title) { RouteValues = new { id = vm.Topic.Id }, OverwriteTitleOnExactMatch = true, Parent = childNode1 }; var childNode3 = new MvcBreadcrumbNode("Reply", "Home", "Reply") { RouteValues = new { id = vm.Topic.Id }, OverwriteTitleOnExactMatch = true, Parent = childNode2 }; ViewData["BreadcrumbNode"] = childNode3; return(View(vm)); }
public ReplyViewModel login(AccessViewModel DataAcess) { ReplyViewModel reply = new ReplyViewModel(); try { var result = db.usuarios.Where(x => x.usuario == DataAcess.User && x.password == DataAcess.Password && x.idstate == 1).FirstOrDefault(); if (result != null) { int IdUser = result.iduser; string Nombre = result.nombre.ToString(); reply.result = 1; reply.data = CreateToken(IdUser); reply.message = "Bienvenido " + Nombre; } else { reply.result = 0; reply.message = "Datos Incorrectos"; } } catch (Exception ex) { reply.data = ex.Message; reply.result = 0; reply.message = "Ocurrio Un Error"; } return(reply); }
public static bool TrySaveReply(ReplyViewModel replyView) { bool emptyAuthor = string.IsNullOrWhiteSpace(replyView.Author); bool emptyContent = !replyView.Content.Any(); if (emptyAuthor || emptyContent) { return(false); } ForumData forumData = new ForumData(); User author = UserService.GetUser(replyView.Author); int postId = forumData.Posts.Any() ? forumData.Posts.Last().Id + 1 : 1; int replyId = forumData.Replies.Any() ? forumData.Replies.Last().Id + 1 : 1; int authorId = author.Id; string content = string.Join("", replyView.Content); Reply reply = new Reply(replyId, content, authorId, postId); //forumData.Posts.Add(post); //author.PostIds.Add(post.Id); //category.PostIds.Add(post.Id); //forumData.SaveChanges(); //postView.PostId = postId; forumData.Replies.Add(reply); author.PostIds.Add(replyId); forumData.SaveChanges(); return(true); }
internal static bool TryAddReply(int postId, ReplyViewModel replyViewModel) { ForumData forumData = new ForumData(); bool emptyReply = !replyViewModel.Content.Any(); if (emptyReply) { return(false); } else { int replyId = forumData.Replies.Any() ? forumData.Replies.Last().Id + 1 : 1; string content = string.Join(string.Empty, replyViewModel.Content); int authorId = UserService.GetUserByName(replyViewModel.Author).Id; Reply reply = new Reply(replyId, content, authorId, postId); Post post = forumData.Posts.FirstOrDefault(p => p.Id == postId); forumData.Replies.Add(reply); post.ReplyIds.Add(replyId); forumData.SaveChanges(); return(true); } }
public void ResetReply() { ErrorMessage = String.Empty; Reply = new ReplyViewModel(); TextArea = new TextArea(centerLeft - 18, centerTop - 6, TEXT_AREA_WIDTH, TEXT_AREA_HEIGHT, POST_MAX_LENGTH); }
public static bool TrySaveReply(int postId, ReplyViewModel replyView) { ForumData forumData = new ForumData(); bool emptyContent = !replyView.Content.Any(); if (emptyContent) { return(false); } int replyId = forumData.Replies.Any() ? forumData.Replies.Last().Id + 1 : 1; string content = string.Join("", replyView.Content); var authorId = UserService.GetUser(replyView.Author).Id; Reply reply = new Reply(replyId, content, authorId, postId); Post post = forumData.Posts.FirstOrDefault(p => p.Id == postId); forumData.Replies.Add(reply); post.ReplyIds.Add(replyId); forumData.SaveChanges(); return(true); }
internal static bool TryAddReply(int postId, ReplyViewModel replyViewModel) { var forumData = new ForumData(); var emptyReply = !replyViewModel.Content.Any(); if (emptyReply) { return(false); } var replyId = forumData.Replies.Any() ? forumData.Replies.Last().Id + 1 : 1; var content = string.Join("", replyViewModel.Content); var authorId = UserService.GetUser(replyViewModel.Author).Id; var reply = new Reply(replyId, content, authorId, postId); var post = forumData.Posts.FirstOrDefault(p => p.Id == postId); forumData.Replies.Add(reply); post.ReplyIds.Add(replyId); forumData.SaveChanges(); return(true); }
public ActionResult Update(int?id, ReplyViewModel model) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (!ModelState.IsValid) { return(View(model)); } var dbReply = _replyService.GetReplyById(id.Value); if (dbReply == null) { return(View(model)); } if (SignInUser.User.IsAdmin || SignInUser.User.Id == dbReply.CreateUserId) { _replyService.UpdateReply(model); return(RedirectToAction("Index", "Post")); } return(View(model)); }
public async Task <IActionResult> AuthEWP(String username, String password) { if (ModelState.IsValid) { var _userInfo = autSurti(username, password); if (_userInfo != null && _userInfo.message != "Usuario o contraseña incorrecto") { surtilogin _modellogin = new surtilogin(); _modellogin.access_token = generateJwtSurtiWP(_userInfo); _modellogin.token_type = "Bearer"; _modellogin.expires_in = 1213232; _modellogin.refresh_token = _modellogin.access_token; _modellogin.Responce = "Ok"; return(Ok(_modellogin)); } ReplyViewModel reply = new ReplyViewModel(); reply.status = username; reply.messege = "Usuario o contraseña incorecta"; return(Ok(reply)); } return(BadRequest()); }
public ForumProfileViewModel GenerateForumProfileViewModel(HttpSession session, int id) { ForumProfileViewModel fpvm = new ForumProfileViewModel(); NavbarViewModel nvm = new NavbarViewModel(); List <TopicViewModel> ltvp = new List <TopicViewModel>(); fpvm.ProfileId = id; fpvm.ProfileName = this.Context.Users.Where(i => i.Id == id).Select(n => n.Username).FirstOrDefault(); if (this.signInManagerService.IsAuthenticated(session)) { var user = this.signInManagerService.GetAuthenticatedUser(session); nvm.LoggedIn = true; nvm.UserId = user.Id; nvm.Username = user.Username; nvm.UserLevel = (int)user.Role; } else { nvm.LoggedIn = false; } // May throw exception foreach (var topic in this.Context.Topics.Where(i => i.Author.Id == id)) { TopicViewModel tvm = new TopicViewModel(); tvm.TopicName = topic.Title; tvm.TopicId = topic.Id; tvm.PublishedOn = topic.PublishDate; CategoryViewModel cvm = new CategoryViewModel() { CategoryName = topic.Category.Name, CategoryId = topic.Category.Id }; tvm.Category = cvm; List <ReplyViewModel> lrvm = new List <ReplyViewModel>(); foreach (var reply in topic.Replies) { ReplyViewModel rvm = new ReplyViewModel(); lrvm.Add(rvm); } tvm.Replies = lrvm; ltvp.Add(tvm); } fpvm.Navbar = nvm; fpvm.Topics = ltvp; return(fpvm); }
public void ResetReply() { Error = false; Reply = new ReplyViewModel(); int postTitleLines = PostView?.Content.Count + 1 ?? 1; TextArea = new TextArea(centerLeft - 18, centerTop + postTitleLines - 7, TextAreaWidth, TextAreaHeight, PostMaxLength); }
/// <summary> /// 更新文章 /// </summary> /// <param name="model">The model.</param> public void UpdateReply(ReplyViewModel model) { var entity = ConvertToEntity(model); entity.Content = model.Content; entity.UpdateUserId = SignInUser.User.Id; _replyRepo.Update(_conn, entity); }
/// <summary> /// 刪除某筆回覆 /// </summary> /// <param name="model">要刪除的回覆entity</param> public void DeleteReply(ReplyViewModel model) { _replyRepo.Delete(_conn, model.Id); if (model.CreateUserId == SignInUser.User.Id) { SignInUser.AdjustReplyCnt(-1); } }
public PartialViewResult Reply(int replyingToId) { var userMessage = _messageManager.GetUserMessageByMessageId(replyingToId); var model = new ReplyViewModel() { ReplyingToMessage = userMessage.Message.Message1, Subject = userMessage.Message.Subject, To = userMessage.Sender}; return PartialView("_Reply", model); }
public RedirectToRouteResult Reply(ReplyViewModel model) { var userMessage = new User_Message() { Sender = "test-username", Reciever = model.To, Message = new Message() { Sent_Date = DateTime.Now, Subject = model.Subject, Message1 = model.Message } }; _messageManager.SendMessage(userMessage); return RedirectToAction("Inbox"); }
public IHttpActionResult PostAddNewReply(int postId, NewReplyBindingModel model) { var post = this.Data.Posts.GetById(postId); if (post == null) { return this.BadRequest(Messege.NoSuchPostError); } if (model == null) { return this.BadRequest("Empty reply is not allowed!"); } if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var user = this.Data.ApplicationUsers.GetById(this.User.Identity.GetUserId()); var reply = new Reply() { Author = user, Comment = model.Comment, Post = post }; var replyView = new ReplyViewModel() { AuthorName = user.UserName, Comment = model.Comment, CreateAt = reply.CreatedAt, RepliedPostId = postId }; post.Replies.Add(reply); this.Data.SaveChanges(); return this.Ok(replyView); }