Example #1
0
        public ActionResult Create(CreateCommentBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var comment = new Comment()
                {
                    Content      = model.Content,
                    Author       = service.GetCurrentUser(),
                    CreationDate = DateTime.Now,
                    Song         = service.FindSongById(model.SongId)
                };

                this.service.AddComment(comment);
            }

            return(RedirectToAction("Details", "Songs", new { id = model.SongId }));
        }
Example #2
0
        public async Task <IHttpActionResult> PostComment(CreateCommentBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Service service = unitOfWork.Services.Get(model.ServiceId);

            if (service == null)
            {
                return(NotFound());
            }

            RAIdentityUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (!CanComment(user.Id, service))
            {
                return(BadRequest("You can not commenting on the service until your first renting is completed."));
            }

            Comment comment = new Comment
            {
                Text     = model.Text,
                DateTime = DateTime.Now,
                UserId   = user.Id
            };

            try
            {
                lock (lockObjectForComments)
                {
                    service.Comments.Add(comment);
                    unitOfWork.Comments.Add(comment);
                    unitOfWork.Complete();
                }
            }
            catch (DBConcurrencyException)
            {
                return(NotFound());
            }
            return(Ok("Service successfully commented."));
        }
Example #3
0
        public async Task <IActionResult> AddComment(CreateCommentBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction("Read", new { articleId = model.ArticleId }));
            }

            var authorId = this.userManager.GetUserId(this.User);
            var comment  = new Comment
            {
                ArticleId       = model.ArticleId,
                AuthorId        = authorId,
                Content         = model.Content,
                PublicationDate = DateTime.UtcNow
            };

            await this._as.CreateComment(comment);

            return(this.RedirectToAction("Read", new { articleId = model.ArticleId }));
        }
Example #4
0
        public async Task <IHttpActionResult> CommentReply(CreateCommentBindingModel model)
        {
            try
            {
                var userId = Convert.ToInt32(User.GetClaimValue("userid"));

                using (RiscoContext ctx = new RiscoContext())
                {
                    Comment comment = new Comment
                    {
                        Text             = model.Text,
                        Post_Id          = model.Post_Id,
                        ParentComment_Id = model.ParentComment_Id,
                        User_Id          = userId,
                        CreatedDate      = DateTime.UtcNow,
                    };

                    ctx.Comments.Add(comment);
                    ctx.SaveChanges();

                    SetTrends(Text: comment.Text, User_Id: userId, Comment_Id: comment.Id);

                    int SecondUser_Id = ctx.Posts.FirstOrDefault(x => x.Id == model.Post_Id && x.IsDeleted == false).User_Id;
                    SetTopFollowerLog(FirstUser_Id: userId, SecondUser_Id: SecondUser_Id);

                    CustomResponse <Comment> response = new CustomResponse <Comment>
                    {
                        Message    = Global.ResponseMessages.Success,
                        StatusCode = (int)HttpStatusCode.OK,
                        Result     = comment
                    };
                    return(Ok(response));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(Utility.LogError(ex)));
            }
        }