public async Task <IActionResult> Create(Comment comment) { try { await _repository.Add(comment); } catch { return(StatusCode(500)); } return(RedirectToAction(nameof(Index))); }
public IActionResult Post(Comment comment) { Post post = _postRepository.GetById(comment.PostId); if (comment.Subject.Length > 255 || post == null) { return(BadRequest()); } comment.UserProfileId = GetCurrentUserProfile().Id; comment.CreateDateTime = DateTime.Now; _commentRepository.Add(comment); return(Ok()); }
public IActionResult Comment(IFormCollection frm, Guid Id) { var pnrNo = frm["txtPNRNumber"].ToString(); var comment = frm["txtComment"]; var rateGiven = frm["starRate"]; var user = userRepo.FirstOrDefaultBy(x => x.Id == Id); var res = reservationRepo.FirstOrDefaultBy(x => x.Id == Id); var pnr = reservationRepo.FirstOrDefaultBy(x => x.PNRNumber == pnrNo); if (!(User.Identity.IsAuthenticated)) { TempData["Info"] = "Yorum yapabilmek için giriş yapmalısınız.."; return(RedirectToAction("Index", "Comment")); } else if (string.IsNullOrWhiteSpace(comment)) { TempData["Info"] = "Lütfen yorum yapacağınız alanı boş bırakmayın"; return(RedirectToAction("Index", "Comment")); } //else if (string.IsNullOrWhiteSpace(rateGiven)) //{ // TempData["Info"] = "Lütfen puanlama yapınız "; // return RedirectToAction("Index", "Comment"); //} else if (pnr != null) { commentRepo.Add(new Comment { ReservationID = res.Id, PNRNumber = pnrNo, CommentText = comment, RateGiven = decimal.Parse(rateGiven) / (10), UserID = CurrentUserID, FullName = CurrentUserName + " " + CurrentUserLastName }); TempData["Info"] = "Yorum işleminiz başarıyla sonuçlanmıştır."; return(RedirectToAction("Index", "Comment")); } else { TempData["Info"] = "Hatalı işlem yaptınız."; return(RedirectToAction("Index", "Comment")); } }
//Yorum ekleme public ServiceStatus AddComment(CommentVM model, int postId) { var serviceStatus = new ServiceStatus(); var httpUser = _httpContextAccessor.HttpContext.User; var claims = int.Parse(httpUser.Claims.ToList().Where(x => x.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value); var comment = new Comment(); comment.CreateDate = DateTime.Now; comment.PostId = postId; comment.UserId = claims; comment.Text = model.Content; _commentRepository.Add(comment); try { _commentRepository.SaveChanges(); serviceStatus.Status = true; return(serviceStatus); } catch (Exception) { throw; } }
static void Main(string[] args) { Console.WriteLine("Start!"); Board board = new Board("Хватит "); _boardRepository.Add(board); Post post = new Post(board.Id, "хватит", "хватит"); _postRepository.Add(post); Comment comment = new Comment(post.Id, "хватит"); _commentRepository.Add(comment); }
public ActionResult CreateComment(String Name, String Email, String CComment) { Comment comment = new Comment { CComment = CComment, Name = Name, Email = Email }; if (ModelState.IsValid) { _commentRepository.Add(comment); } return(RedirectToAction("Index", "CommentSection")); }
public async Task <IActionResult> Add([FromBody] CommentDto data) { if (ModelState.IsValid) { var SaveData = _mapper.Map <Comments>(data); _CommentRepository.Add(SaveData); await _CommentRepository.SaveAll(); return(Ok(SaveData)); } return(BadRequest("Kayıt Yapılamadı ")); }
public HttpResponseMessage Post(string idCandidate, int idUser, [FromBody] Comment comment) { try { comment.idUser = idUser; comment.idCandidate = idCandidate; _repository.Add(comment); object o = getCommentsUser(idCandidate, idUser); return(this.Request.CreateResponse(HttpStatusCode.OK, o)); } catch (Exception e) { return(HttpUtil.TrataException(e, Request)); } }
public ActionResult NhanXet(int id, string content) { var subjectID = id; if (subjectRepository.GetByID(subjectID) == null) { return(HttpNotFound()); } commentRepository.Add(new Comment { Content = content, CreateAt = DateTime.Now }); return(RedirectToChiTiet(subjectID)); }
public async Task <IActionResult> AddComment(CommentForm model) { if (ModelState.IsValid) { var user = await _workContext.GetCurrentUser(); var comment = new Comment { CommentText = model.CommentText, CommenterName = model.CommenterName, Status = _isCommentsRequireApproval ? CommentStatus.Pending : CommentStatus.Approved, EntityId = model.EntityId, EntityTypeId = model.EntityTypeId, UserId = user.Id }; _commentRepository.Add(comment); _commentRepository.SaveChanges(); return(PartialView("_CommentFormSuccess", model)); } return(PartialView("_CommentForm", model)); }
public IActionResult Add([FromBody] CommentTemplate comment) { try { var commentMap = _mapper.Map <Comment>(comment); _commentRepository.Add(commentMap); return(Ok(new ServiceResponse <CommentServiceResponse, CommentTemplate>(CommentServiceResponse.Success))); } catch (System.Exception ex) { _logger.Error($"Comment Add :{ex}"); return(BadRequest(new ServiceResponse <CommentServiceResponse, CommentTemplate>(CommentServiceResponse.Exception))); } }
public IActionResult Create(Comment comment) { try { comment.CreateDateTime = DateAndTime.Now; comment.UserProfileId = GetCurrentUserId(); _commentRepo.Add(comment); return(RedirectToAction("Index", new { id = comment.PostId })); } catch { return(View(comment)); } }
public JsonResult AddOrReplyComment(Comment comment) { Comment _comment = new Comment() { Message = comment.Message, ParentId = string.IsNullOrEmpty(comment.ParentId) ? string.Empty : comment.ParentId, Id = Guid.NewGuid().ToString(), CreatedBy = User.Identity.GetUserId(), PostId = comment.PostId, CreatedOn = DateTime.Now }; commentRepository.Add(_comment); return(Json(GetCommentObject(_comment, 10), JsonRequestBehavior.AllowGet)); }
public ActionResult <CommentViewModel> Post([FromBody] CommentCreationViewModel model) { var creationTime = ((DateTimeOffset)DateTime.UtcNow).ToUnixTimeSeconds(); var comm = new Model.Comment { BlogId = model.BlogId, UserId = NVLInt64(HttpContext.User.Identity.Name, 0), Content = model.Content, CreationTime = creationTime, }; _commentRepository.Add(comm); _commentRepository.Commit(); return(_mapper.Map <Model.Comment, CommentViewModel>(comm)); }
public IActionResult Create([Bind("Id,GymId,UserId,CommentText,Rate,PublicationDate")] Comment comment) { comment.PublicationDate = DateTime.Now; if (ModelState.IsValid) { _comRepo.Add(comment); return(RedirectToAction("Index")); } ViewData["CurrentUserId"] = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; ViewData["GymsIds"] = new SelectList(_gymRepo.GetAll(), "Id", "GymName", comment.GymId); return(View("Views/Admin/Comment/Create.cshtml", comment)); }
public async Task <NewCommentResponseViewModel> CreateComment(int postId, NewCommentViewModel comment) { var newComment = _mapper.Map <Comment>(comment); var post = await _postRepository.Get(postId); newComment.Post = post; newComment.PostId = post.Id; var addedComment = await _commentRepository.Add(newComment); var response = new NewCommentResponseViewModel() { Id = addedComment.Id }; return(response); }
public bool Create(CreateUpdateCommentViewModel model) { try { var comment = new Comment(); comment.CreationTime = DateTime.UtcNow; comment = model.AsComment(); comment.CommentId = 0; commentRepository.Add(comment); return(true); } catch { return(false); } }
public JsonResult AddComment(int idsanPham, string noidung_cmt) { Comment comment = new Comment() { IdSanPham = idsanPham, NgayCmt = DateTime.Now, NoiDungCmt = noidung_cmt }; _commentRepository.Add(comment); _unitOfWork.Commit(); return(Json(new { message = "Thêm mới thành công!" }, JsonRequestBehavior.AllowGet)); }
public Comment SubmitComment(int entryId, string comment, int parentId, int account_id) { if (comment == string.Empty) { throw new Exception("Comment is required."); } return(_commentRepository.Add(new Comment { EntryId = entryId , ParentCommentId = parentId , account_id = account_id , CommentText = comment , CreatedDate = DateTime.Now })); }
public async Task <CommentDto> Create(NewCommentDto newItem) { if (newItem == null) { throw new ArgumentNullException(); } var comment = _mapper.Map <Comment>(newItem); comment.DateCreated = DateTime.Now; await _repository.Add(comment); var commentDto = _mapper.Map <CommentDto>(comment); return(commentDto); }
public async Task <IActionResult> Create([FromBody] CommentViewModel comment) { var commentModel = new Comment { Body = comment.Body, Rating = 0, UserId = comment.UserId, PostId = comment.PostId }; await _commentRepository.Add(commentModel); await _unitOfWork.CompleteAsync(); return(Ok()); }
/// <summary> /// Gelen modele göre yorum database'e ekleniyor. /// </summary> /// <param name="model">Model</param> /// <returns>Db'ye kaydedilip sonuç int olarak dönülüyor.</returns> public async Task <int> AddComment(DtoAddComments model) { Comments comment = new Comments(); comment.MarketId = model.MarketId; comment.IsDelete = false; comment.CommentIp = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); comment.CommentParentId = model.CommentParentId; comment.CreatedDateTime = DateTime.Now; comment.IsPinned = false; comment.Message = model.Message; comment.UserId = model.UserId; await _commentRepository.Add(comment); return(comment.Id); }
public IActionResult AddComment(string comment, CourseMaterialViewModel cmvm, ICollection <Comment> notifications) { if (cmvm != null) { //viewModel uit session halen CourseMaterial course = _courseMaterialRepository.GetById(cmvm.SelectedCourseMaterial.MaterialId); Member member = (Member)_userRepository.GetById(cmvm.SelectedMember.UserId); if (course == null || member == null) { return(NotFound()); } Comment c = new Comment(comment, course, member); _commentRepository.Add(c); _commentRepository.SaveChanges(); SendMail(c); TempData["message"] = "Het commentaar is succesvol verstuurd!"; //Notificaties if (notifications != null) { notifications.Add(c); ICollection <Comment> tempList = notifications.OrderByDescending(com => com.CommentId).ToList(); while (notifications.Count() > 0) { notifications.Remove(notifications.Last()); } foreach (Comment loopComment in tempList) { notifications.Add(loopComment); } while (notifications.Where(n => n.IsRead).Count() > 0 && notifications.Count() > 5) { notifications.Remove(notifications.Last()); } } else { notifications = new List <Comment>(); notifications.Add(c); } return(RedirectToAction(nameof(SelectCourse), new { sessionId = cmvm.Session.SessionId, rank = cmvm.SelectedRank, selectedUserId = cmvm.SelectedMember.UserId, matId = cmvm.SelectedCourseMaterial.MaterialId })); } return(View("Training")); }
public HttpResponseMessage Post(HttpRequestMessage request, AddCommentViewModel comment) { //var user = userRepository.FindById(comment.UserId); var user = userRepository.GetAll().ToList()[new Random().Next(5)]; var post = postRepository.Get(comment.PostId); commentRepository.Add(new Comment { DateCreated = DateTime.Now, Text = comment.Text, User = user, Post = post }); commentRepository.Save(); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public List <TaskViewModel> AddComment(CommentView NewComment, string UserID) { Comment Comment = new Comment() { CommentDescription = NewComment.CommentDescription, UserID = UserID, //current logged in user ParentCommentID = NewComment.ParentID == 0?null : NewComment.ParentID, CreationDate = DateTime.Now, TaskID = NewComment.TaskID }; CommentRepository.Add(Comment); SaveTask(); List <TaskViewModel> Tasks = GetTasks(); return(Tasks); }
public async Task SendComment(CreateCommentModel comment) { var userId = Context.UserIdentifier; var userIdInt = int.Parse(userId); var commentResponse = await _commentRepository.Add(comment, userIdInt); if (commentResponse.IsError) { return; } var commentData = commentResponse.Data; var userToTask = Clients.User(commentData.UserMessageToId.ToString()).SendAsync(SendCommentMethod, commentData); var userFromTask = Clients.User(userId).SendAsync(SendCommentMethod, commentData); Task.WaitAll(userToTask, userFromTask); }
//[ValidateAntiForgeryToken] //Pass in PostId and Comment object from create form public ActionResult Create(int id, CommentFormViewModel vm) { try { vm.Comment.CreateDateTime = DateAndTime.Now; vm.Comment.PostId = id; vm.Comment.UserProfileId = GetCurrentUserProfileId(); _commentRepository.Add(vm.Comment); return(RedirectToAction("Index", "Comment", new { Id = id })); } catch { return(View(vm)); } }
public ActionResult Create([Bind(Include = "Id,Comentario")] CommentViewModel comment, int bookId) { if (ModelState.IsValid) { _commentRepository.Add(CommentMapper.Map(comment), bookId); var book = VerifyData(bookId); if (book == null) { return(HttpNotFound("El Id bo corresponde a un Book")); } return(RedirectToAction("Create", "Comments", new { bookId = bookId })); } return(View()); }
public IActionResult Create(CommentCreateViewModel model) { if (ModelState.IsValid) { Comments comment = new Comments { Title = model.Title, Content = model.Content, Product = model.Product, User = model.User }; Comments newComment = _commentRepository.Add(comment); return(RedirectToAction("ProductDetails", new { id = newComment.ID })); } return(View()); }
public IActionResult CreateComment([Bind("Id,GymId,UserId,CommentText,Rate,PublicationDate")] Comment comment) { comment.PublicationDate = DateTime.Now; if (ModelState.IsValid) { _comRepo.Add(comment); var gym = _gymRepo.Get(comment.GymId); var comments = gym.Comments; int sumRate = 0; for (int i = 0; i < comments.Count; i++) { sumRate += comments[i].Rate; } double rateGym = sumRate / comments.Count; int rate = (int)Math.Round(rateGym); gym.GymRate = rate; try { _gymRepo.Edit(gym); } catch (DbUpdateException e) { Console.WriteLine(e.InnerException.Message); ModelState.AddModelError("0", e.InnerException.Message); return(BadRequest(ModelState)); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); return(BadRequest($"{e.Message}")); } return(RedirectToAction($"{comment.GymId}")); } else if (comment.UserId == null) { return(RedirectToAction("Login", "Account")); } else { return(RedirectToAction($"{comment.GymId}", "GymPage", "error")); } }