public IActionResult AddHaragComment([FromBody] CommentForPostModel model) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Unauthorized()); } var currentUserId = _workContext.CurrentCustomer.Id; ViewBag.UserName = _workContext.CurrentCustomer.Username; if (_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Registered, true)) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <string> errors = new List <string>(); var commentCreated = _commentService.AddComment(model, currentUserId); var post = _postService.GetPost(model.PostId, ""); if (post.CustomerId != currentUserId) { var notifications = _notificationService.PushPostCommentNotification(new CommentForNotifyModel { CustomerId = currentUserId, Text = commentCreated.Text, PostId = model.PostId, Time = DateTime.Now, PostOwner = post.CustomerId }); var d = _notificationService.PushPostOwnerNotification(new CommentForNotifyModel { CustomerId = currentUserId, Text = commentCreated.Text, PostId = model.PostId, Time = DateTime.Now, PostOwner = post.CustomerId }); } else { } string userName = _workContext.CurrentCustomer.Username; var commentToReturn = commentCreated.ToCommentModel(); commentToReturn.CommentOwner = userName; commentToReturn.PostOwnerId = (int)commentCreated.CustomerId; return(PartialView("~/Themes/Pavilion/Views/Harag/Comment/_CommentTemplatePartial.cshtml", commentToReturn)); } else { return(Unauthorized()); } }
public IActionResult AddComment([FromBody] CommentForPostModel model) { var cities = _postService.GetCities(); if (!_workContext.CurrentCustomer.IsRegistered()) { return(Unauthorized()); } var currentUserId = _workContext.CurrentCustomer.Id; ViewBag.UserName = _workContext.CurrentCustomer.Username; var notifyModel = new NotificationModel(); if (_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Consultant, true)) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_postService.IsClosed(model.PostId)) { return(BadRequest("Post is closed")); } ViewBag.UserRole = "Consultant"; if (_postService.IsReserved(model.PostId)) { if (_postService.IsConsultantAuthToPost(model.PostId, currentUserId)) { List <string> errors = new List <string>(); var commentCreated = _commentService.AddCommentByConsultant(model, currentUserId, model.Files, errors); _postService.SetPostAnsweredByConsultant(model.PostId, currentUserId); string userName = _workContext.CurrentCustomer.Username; var commentToReturn = commentCreated.ToCommentModel(); commentToReturn.CommentOwner = userName; //--Notification-- var post = _postService.GetPostById(commentToReturn.PostId); if (post != null) { notifyModel.OwnerId = post.CustomerId; } notifyModel.PostId = commentCreated.PostId; notifyModel.UserId = _workContext.CurrentCustomer.Id; notifyModel.Type = 2; _notificationtService.AddCommentNotification(notifyModel); //--End Notification return(CreatedAtRoute("Consultant.Comment.GetComment", new { CommentId = commentToReturn.Id }, commentToReturn)); } else { return(Forbid()); } } else { List <string> errors = new List <string>(); var commentCreated = _commentService.AddCommentByConsultant(model, currentUserId, model.Files, errors); _postService.SetPostAnsweredByConsultant(model.PostId, currentUserId); string userName = _workContext.CurrentCustomer.Username; var commentToReturn = commentCreated.ToCommentModel(); commentToReturn.CommentOwner = userName; //--Notification-- var post = _postService.GetPostById(commentToReturn.PostId); if (post != null) { notifyModel.OwnerId = post.Customer.Id; } notifyModel.PostId = commentCreated.PostId; notifyModel.UserId = _workContext.CurrentCustomer.Id; notifyModel.Type = 2; _notificationtService.AddCommentNotification(notifyModel); //--End Notification return(GetComment(commentToReturn.Id)); } } else if (_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Registered, true)) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_postService.IsClosed(model.PostId)) { return(BadRequest("Post is closed")); } ViewBag.UserRole = "Registered"; if (_postService.IsCustomerAuthToPost(model.PostId, currentUserId)) { List <string> errors = new List <string>(); var commentCreated = _commentService.AddCommentByCustomer(model, currentUserId, model.Files, errors); string userName = _workContext.CurrentCustomer.Username; var commentToReturn = commentCreated.ToCommentModel(); commentToReturn.CommentOwner = userName; //--Notification-- var post = _postService.GetPostById(commentToReturn.PostId); if (post != null) { notifyModel.OwnerId = post.Consultant.Id; } notifyModel.PostId = commentCreated.PostId; notifyModel.UserId = _workContext.CurrentCustomer.Id; notifyModel.Type = 2; _notificationtService.AddCommentNotification(notifyModel); //--End Notification return(GetComment(commentToReturn.Id)); } else { return(Forbid()); } } else { return(Unauthorized()); } }