public async Task <IActionResult> Detail(int?id) { if (id == null) { return(NotFound()); } Models.Reply reply = await _db.Replies.FindAsync(id); if (reply == null) { return(NotFound()); } return(View(reply)); }
private void SeedDb() { this.TruncateForumsTable(); this.TruncatePostsTable(); this.TruncateQuotesTable(); this.TruncateUsersTable(); var post = new Models.Post { Id = TestsConstants.TestId }; this.dbService.DbContext.Posts.Add(post); this.dbService.DbContext.SaveChanges(); var reply = new Models.Reply { Id = TestsConstants.TestId2, Post = post, PostId = post.Id }; this.dbService.DbContext.Replies.Add(reply); this.dbService.DbContext.SaveChanges(); var author = new ForumUser { Id = TestsConstants.TestId, UserName = TestsConstants.TestUsername1 }; var reciever = new ForumUser { Id = TestsConstants.TestId1, UserName = TestsConstants.TestUsername2 }; this.dbService.DbContext.Users.Add(author); this.dbService.DbContext.Users.Add(reciever); this.dbService.DbContext.SaveChanges(); var firstQuote = new Models.Quote { Id = TestsConstants.TestId1, Author = author, AuthorId = author.Id, Reply = reply, ReplyId = reply.Id }; this.dbService.DbContext.Quotes.Add(firstQuote); this.dbService.DbContext.SaveChanges(); for (int i = 0; i < 5; i++) { var quote = new Models.Quote { Id = Guid.NewGuid().ToString(), Author = author, AuthorId = author.Id, Reply = reply, ReplyId = reply.Id }; this.dbService.DbContext.Quotes.Add(quote); this.dbService.DbContext.SaveChanges(); } }
public async Task <IActionResult> Answer(int?id, ReplyAnswerVM answerVM) { if (id == null) { return(NotFound()); } Models.Reply reply = await _db.Replies.FindAsync(id); if (reply == null) { return(NotFound()); } answerVM.Reply = reply; if (!ModelState.IsValid) { return(View(answerVM)); } MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**", "No-Reply"); mail.To.Add(new MailAddress(reply.Email)); mail.Subject = answerVM.Subject; mail.Body = $"<h2>Hi {reply.Name}</h2> <p>{answerVM.Message}</p>"; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.Credentials = new NetworkCredential("*****@*****.**", "kb6853917"); smtp.Send(mail); if (reply.Checked == false) { reply.Checked = true; } await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
protected void Button3_Click(object sender, EventArgs e) { using (var context = new DatabaseContext()) { Models.Reply Replies = new Models.Reply(); Replies.Text = txtReply.Text; // Reply itself Replies.Parent = context.Parent.Single(p => p.ID == (Session["Account"] as Models.Parent).ID); // Checks to see if you are a parent (FromID) Replies.Mentor = context.Mentor.Single(m => m.Name.Equals(ddl_Mentor.SelectedValue)); // To know the mentor Replies.Message = context.Message.Single(n => n.Text.Equals(ddl_Message.SelectedValue)); // For the message they reply to context.Add(Replies); // INSERT into the database context.SaveChanges(); } Response.Redirect("Messages.aspx?Title= " + txtReply.Text); }
public async Task <IActionResult> Answer(int?id) { if (id == null) { return(NotFound()); } Models.Reply reply = await _db.Replies.FindAsync(id); if (reply == null) { return(NotFound()); } ReplyAnswerVM answerVM = new ReplyAnswerVM { Reply = reply }; return(View(answerVM)); }
public async Task <IActionResult> AddReply(ReplyForm model) { if (ModelState.IsValid) { var user = await _workContext.GetCurrentUser(); var reply = new Models.Reply { ReviewId = model.ReviewId, UserId = user.Id, Comment = model.Comment, ReplierName = model.ReplierName, }; _replyRepository.Add(reply); _replyRepository.SaveChanges(); return(PartialView("_ReplyFormSuccess", model)); } return(PartialView("_ReplyForm", model)); }
public async Task <IActionResult> Unread(int?id) { if (id == null) { return(NotFound()); } Models.Reply reply = await _db.Replies.FindAsync(id); if (reply == null) { return(NotFound()); } if (reply.Checked == false) { return(NotFound()); } reply.Checked = false; await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
private void SeedDb() { this.TruncateForumsTable(); this.TruncatePostsTable(); this.TruncateUsersTable(); this.TruncateRepliesTable(); var user = new ForumUser { Id = TestsConstants.TestId, UserName = TestsConstants.TestUsername1 }; this.dbService.DbContext.Users.Add(user); this.dbService.DbContext.SaveChanges(); var post = new Models.Post { Author = user, Description = TestsConstants.ValidPostDescription, AuthorId = user.Id, Id = TestsConstants.TestId3 }; this.dbService.DbContext.Posts.Add(post); this.dbService.DbContext.SaveChanges(); var firstReply = new Models.Reply { Id = TestsConstants.TestId, Author = user, AuthorId = user.Id, Post = post, PostId = post.Id }; this.dbService.DbContext.Replies.Add(firstReply); this.dbService.DbContext.SaveChanges(); for (int i = 0; i < 5; i++) { var reply = new Models.Reply { Id = Guid.NewGuid().ToString(), Author = user, AuthorId = user.Id, Post = post, PostId = post.Id }; this.dbService.DbContext.Replies.Add(reply); this.dbService.DbContext.SaveChanges(); } }
public void btnSend_Click(Object sender, EventArgs e) { if (Page.IsValid) { using (var context = new DatabaseContext()) { Models.Reply reply = new Models.Reply { Text = txtInput.Text, Message = context.Message .Single(m => m.ID == CurrentMessage.ID), Mentor = context.Mentor .Single(m => m.ID == CurrentMentor.ID), }; context.Add(reply); context.SaveChanges(); } txtInput.Text = String.Empty; Reset(); } }