public ActionResult CreateOrEdit(Comment comment) { if (!ModelState.IsValid) { return(View(nameof(Edit), comment)); } TblComment dbComment = _context.TblComment.Find(comment.CommentId); if (dbComment == null) { dbComment = new TblComment(); dbComment.CreatedDate = DateTime.Now; dbComment.PostId = comment.PostId; } dbComment.Content = comment.Content; if (!TryValidateModel(dbComment)) { return(View(nameof(Edit), comment)); } TempData["message"] = "Comment Updated/Created!"; TempData["messageColorClass"] = "alert-success"; _context.TblComment.AddOrUpdate(dbComment); _context.SaveChanges(); return(RedirectToAction(nameof(Show), new { id = dbComment.CommentId })); }
public async Task <ActionResult <TblComment> > Post([FromBody] TblComment item) { item.UpdateTime = DateTime.Now; _context.Comments.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = item.Id }, item)); }
public bool DoesExist(Guid id) { TblComment movie = _context.TblComment.FirstOrDefault(x => x.CommentId == id); if (movie != null) { return(true); } return(false); }
public async Task TestAddComment() { var comment = new TblComment(); comment.Comment = "Soo awesome"; comment.CommentId = Guid.NewGuid(); comment.UserId = Guid.NewGuid(); comment.CommentId = Guid.NewGuid(); Assert.True(await repo.Add(comment)); }
public async Task <IActionResult> Put(string id, [FromBody] TblComment item) { if (id != item.Id) { return(BadRequest()); } item.UpdateTime = DateTime.Now; _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public ActionResult Show(int id) { TblComment comment = _context.TblComment .FirstOrDefault(c => c.CommentId == id); var model = new Comment { CommentId = comment.CommentId, Content = comment.Content, PostId = comment.PostId }; return(View(model)); }
public async Task <bool> Add(TblComment item) { await _context.TblComment.AddAsync(item); var result = await _context.SaveChangesAsync(); if (result == 1) { return(true); } else { return(false); } }
public async Task <bool> Delete(Guid id) { TblComment movie = _context.TblComment.FirstOrDefault(x => x.CommentId == id); _context.TblComment.Remove(movie); var result = await _context.SaveChangesAsync(); if (result == 1) { return(true); } else { return(false); } }
public ActionResult TblCommentDelete(long id) { try { TblComment o = new TblComment(); o.Id = id; new TblCommentDao().Delete(o); return(RedirectToAction("TblNewsDraffUpdate", "Admin")); } catch (Exception ex) { logger.Info(ControllerName + "::TblCommentDelete::" + ex.Message); return(RedirectToAction("Index", "Error")); } }
public async Task <IActionResult> Create(IFormCollection formField, Guid movieId) { TblComment tblComment = new TblComment(); tblComment.CommentId = Guid.NewGuid(); tblComment.MovieId = movieId; tblComment.UserId = CurrentUser.Users[HttpContext.Session.GetString("token")].UserId; tblComment.Comment = formField["txtComment"].ToString(); //tblComment.User = CurrentUser.Users[HttpContext.Session.GetString("token")]; if (tblComment.Comment.Trim() == "") { return(RedirectToAction("Details", "Movie", new { id = tblComment.MovieId })); } tblComment.Date = DateTime.Now; await _commentRepository.Add(tblComment); return(RedirectToAction("Details", "Movie", new { id = tblComment.MovieId })); }
public ActionResult TblCommentAdminCreate(long newsid, string uck, TblNewsDraffModel model) { try { TblComment o = new TblComment(); o.Name = GetUserName(); o.Content = model.Comment; o.NewsId = newsid; o.CreateDate = DateTime.Now; o.IsAd = true; new TblCommentDao().Create(o); return(RedirectToAction("TblNewsDraffUpdate", "Admin", new { id = newsid })); } catch (Exception ex) { logger.Info(ControllerName + "::TblCommentAdminCreate::" + ex.Message); return(RedirectToAction("Index", "Error")); } }
public ActionResult Quotation(string metatitle, long id, TblCommentModel model, FormCollection form) { try { const string verifyUrl = "https://www.google.com/recaptcha/api/siteverify"; var secret = ConfigurationManager.AppSettings["SecretKey"]; var response = form["g-recaptcha-response"]; var remoteIp = Request.ServerVariables["REMOTE_ADDR"]; var myParameters = String.Format("secret={0}&response={1}&remoteip={2}", secret, response, remoteIp); using (var wc = new WebClient()) { wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var json = wc.UploadString(verifyUrl, myParameters); var js = new DataContractJsonSerializer(typeof(CapchaRespond)); var ms = new MemoryStream(Encoding.ASCII.GetBytes(json)); var result = js.ReadObject(ms) as CapchaRespond; if (result != null && result.Success) // SUCCESS!!! { if (ModelState.IsValid) { TblComment o = new TblComment(); o.Name = model.Name; o.Content = model.Content; o.NewsId = id; o.CreateDate = DateTime.Now; o.IsAd = false; new TblCommentDao().Create(o); return(RedirectToAction("NewsDetail", "Home", new { id = id, metatitle = HttpUtility.UrlDecode(metatitle) })); } } } return(View()); } catch (Exception ex) { logger.Info("Home" + "::Quotation::" + ex.Message); return(RedirectToAction("Index", "Error")); } }
public void Create(TblComment o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { db.TblComments.Add(o); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblCommentDao::Create::" + ex.Message); } else { throw new Exception("TblCommentDao::Create::" + ex.InnerException.Message); } } }
public void Delete(TblComment o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblComments.Where(x => x.Id == o.Id).SingleOrDefault(); db.TblComments.Remove(res); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblCommentDao::Delete::" + ex.Message); } else { throw new Exception("TblCommentDao::Delete::" + ex.InnerException.Message); } } }