public void InsertComment(Comment comment) { if (comment.GetType() == typeof(DiscussionComment)) { DiscussionComment c = (DiscussionComment)comment; using (OracleConnection connection = Connection) { string Insert = "INSERT INTO \"COMMENT\" (commentID, discussionID, loginName, commentBody, datePosted) VALUES (COMM_FCSEQ.NEXTVAL, :DISCUSSIONID, :LOGINNAME, :COMMENTBODY, :DATEPOSTED)"; using (OracleCommand command = new OracleCommand(Insert, connection)) { command.Parameters.Add(new OracleParameter("DISCUSSIONID", c.DiscussionID)); command.Parameters.Add(new OracleParameter("LOGINNAME", c.Writer.LoginName)); command.Parameters.Add(new OracleParameter("COMMENTBODY", c.CommentBody)); command.Parameters.Add(new OracleParameter("DATEPOSTED", c.DatePosted)); command.ExecuteNonQuery(); } } } else { NewsComment c = (NewsComment)comment; using (OracleConnection connection = Connection) { string Insert = "INSERT INTO \"COMMENT\" (commentID, newsItemID, loginName, commentBody, datePosted) VALUES (COMM_FCSEQ.NEXTVAL, :NEWSITEMID, :LOGINNAME, :COMMENTBODY, :DATEPOSTED)"; using (OracleCommand command = new OracleCommand(Insert, connection)) { command.Parameters.Add(new OracleParameter("NEWSITEMID", c.NewsItemID)); command.Parameters.Add(new OracleParameter("LOGINNAME", c.Writer.LoginName)); command.Parameters.Add(new OracleParameter("COMMENTBODY", c.CommentBody)); command.Parameters.Add(new OracleParameter("DATEPOSTED", c.DatePosted)); command.ExecuteNonQuery(); } } } }
public CommentForApiContract CreateComment(int topicId, CommentForApiContract contract) { return(repository.HandleTransaction(ctx => { return Comments(ctx).Create <DiscussionTopic>(topicId, contract, (topic, con, agent) => { var comment = new DiscussionComment(topic, contract.Message, agent); topic.Comments.Add(comment); return comment; }); })); }
public JsonResult CommentOnDiscussion(string comm) { JsonComment c = new JsonComment(); c.IsCommentOK = false; LoginDetails loginDetails = (LoginDetails)Session["loginDetails"]; if (loginDetails == null) { return(this.Json(c)); } if (Session["discussionSelected"] == null) { return(this.Json(c)); } if (Session["selectedClass"] == null) { return(this.Json(c)); } int user = (int)Session["user"]; if (user != 1) { return(this.Json(c)); } if (comm == null) { return(this.Json(c)); } int did = (int)Session["discussionSelected"]; int cid = (int)Session["selectedClass"]; DiscussionComment comment = new DiscussionComment(); comment.Body = comm; comment.Time = DateTime.Now.ToString(); Teacher t = data.GetInstructor(cid); comment.FullName = t.FirstName + " " + t.LastName; comment.Username = t.Username; data.AddComment(did, comment); c.IsCommentOK = true; c.Username = comment.Username; c.FullName = comment.FullName; c.CommentBody = comment.Body; c.CommentTime = comment.Time; Discussion d = data.GetDiscussion(did); c.IsFirstComment = (d.Comments.Count == 1); return(this.Json(c)); }
private DiscussionComment CreateComment(string message) { var user = _db.Users.Find(UserSession.CurrentUserId); var comment = new DiscussionComment { Date = DateTime.UtcNow, Text = message, SenderId = user.UserId, SenderName = user.FullName, }; return(comment); }
public ActionResult AddComment(string comment, int postId) { //bool result = false; //DiscussionComment commentEntity = null; string userId = User.Identity.GetUserId(); //Console.WriteLine(postId); //var user = db.AspNetUsers.FirstOrDefault(u => u.Id == userId); //var post = db.Discussions.FirstOrDefault(p => p.Id == postId); string commentMsg = Request.Form["commentMsg"]; //Console.WriteLine(commentMsg); if (commentMsg != null) { var commentEntity = new DiscussionComment { CommentMessage = commentMsg, // CommentDate = comment.CommentDate, CommentDate = DateTime.Now, UserId = userId, DiscussionId = postId }; //Console.WriteLine(commentEntity); db.DiscussionComments.Add(commentEntity); db.DiscussionComments.Add(commentEntity); //db.SaveChangesAsync(); db.SaveChanges(); // db.SaveChanges(); /*if (user != null && post != null) * { * //post.DiscussionComments.Add(commentEntity); * //user.DiscussionComments.Add(commentEntity); * * db.DiscussionComments.Add(commentEntity); * * db.SaveChanges(); * //result = true; * }*/ } return(RedirectToAction("GetComments", "Discussion", new { postId = postId })); }
public void AddComment(string comment, int discussionId) { var user = _db.Users.Find(UserSession.CurrentUserId); var msg = new DiscussionComment { SenderId = user.UserId, SenderName = user.FullName, Text = comment, Date = DateTime.UtcNow, DiscussionId = discussionId, }; _db.DiscussionComments.Add(msg); _db.SaveChanges(); }
// GET: Meetings/Delete/5 public ActionResult Delete(int id) { /* if (id == null) * { * return new HttpStatusCodeResult(HttpStatusCode.BadRequest); * } * if (comment == null) * { * return HttpNotFound(); * }*/ DiscussionComment comment = db.DiscussionComments.Find(id); return(View("GetPosts")); //return RedirectToAction("GetComments", "Discussion", new { postId = comment.DiscussionId }); //return RedirectToAction("Delete", "Discussion"); //return PartialView("~/Views/Discussion/GetComments.cshtml", new { postId =comment.DiscussionId }); }
public ReturnValues AddComment(DiscussionComment obj) { using (TransactionScope trans = new TransactionScope()) { try { ReturnValues ret = null; using (RepsistoryEF <DiscussionComment> _o = new RepsistoryEF <DiscussionComment>()) { var result = _o.Save(obj); if (result != null) { ret = new ReturnValues { Success = "Comment posted successfully.", Source = "0", }; } else { ret = new ReturnValues { Success = "Failed to save", Source = "0", }; } trans.Complete(); } return(ret); } catch (Exception ex) { trans.Dispose(); ReturnValues objex = new ReturnValues { Failure = ex.Message, }; throw ex; } finally { trans.Dispose(); } } }
protected void submit(object sender, EventArgs e) { foreach (User u in admin.Users) { if (u.LoginName == (string)Session["loginName"]) { User writer = u; DiscussionComment comment = new DiscussionComment(0, writer, tbxComment.Text, DateTime.Now, discussion.DiscussionID); admin.AddComment(comment); //admin.RefreshDiscussions(); //LoadComments(); //tbxComment.Text = ""; Response.Redirect(Request.Url.ToString()); return; } } Response.Write("<script language=\"javascript\">alert('Invalid User!');</script>"); }
//[ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { var subComments = db.SubComments.Where(x => x.CommentId == id).ToList(); for (var i = 0; i < subComments.Count(); i++) { db.SubComments.Remove(subComments[i]); db.SaveChanges(); } DiscussionComment comment = db.DiscussionComments.Find(id); db.DiscussionComments.Remove(comment); db.SaveChanges(); IQueryable <CommentsVM> DiscussionComment = db.DiscussionComments.Where(c => c.Discussion.Id == comment.DiscussionId) .Select(c => new CommentsVM { Id = c.Id, CommentDate = c.CommentDate, CommentMessage = c.CommentMessage, Users = new UserVM { UserId = c.AspNetUser.Id, UserName = c.AspNetUser.UserName, imageProfile = "" } }).AsQueryable(); IQueryable <DiscussionsVM> Discussion = db.Discussions .Select(p => new DiscussionsVM { Id = p.Id, Topic = p.Topic, Posted_Date = p.Posted_Date }).AsQueryable(); //return View("~/Views/Discussion/GetPosts.cshtml", Discussion); // return View("GetPosts"); //return RedirectToAction("GetComments", "Discussion", new { postId = comment.DiscussionId }); return(PartialView("~/Views/Discussion/_MyComments.cshtml", DiscussionComment)); //return PartialView("~/Views/Discussion/_MySubComments.cshtml", subComments); //return View("GetPosts"); }
public ActionResult AddComment(string comment, int postId) { //bool result = false; //DiscussionComment commentEntity = null; string userId = User.Identity.GetUserId(); //Console.WriteLine(postId); //var user = db.AspNetUsers.FirstOrDefault(u => u.Id == userId); //var post = db.Discussions.FirstOrDefault(p => p.Id == postId); string commentMsg = Request.Form["commentMsg"]; //Console.WriteLine(commentMsg); if (commentMsg != null) { var commentEntity = new DiscussionComment { CommentMessage = commentMsg, // CommentDate = comment.CommentDate, CommentDate = DateTime.Now, UserId = userId, DiscussionId = postId }; //Console.WriteLine(commentEntity); db.DiscussionComments.Add(commentEntity); db.DiscussionComments.Add(commentEntity); //db.SaveChangesAsync(); db.SaveChanges(); var discussion = db.Discussions.Where(x => x.Id == postId).FirstOrDefault(); var preference = GetUserNotificationPreference("discussion", discussion.UserId); var userModel = GetUserInfoByUserId(discussion.UserId); var loginUser = GetUserInfoByUserId(userId); string body = "A new comment has been posted on discussion: " + discussion.Topic + " by " + loginUser.FullName; if (preference.IsEmail) { var recipients = new List <EmailAddress>(); recipients.Add(new EmailAddress(userModel.Email, userModel.FullName)); SendEmailViaSendGrid("Interest showed in meeting", body, recipients); } if (preference.IsSms) { SendSmsViaClickaTell(userModel.PhoneNumber, body); } // db.SaveChanges(); /*if (user != null && post != null) * { * //post.DiscussionComments.Add(commentEntity); * //user.DiscussionComments.Add(commentEntity); * * db.DiscussionComments.Add(commentEntity); * * db.SaveChanges(); * //result = true; * }*/ } return(RedirectToAction("GetComments", "Discussion", new { postId = postId })); }