Esempio n. 1
0
        public IActionResult Comment(int id, AddCommentModel newComment)
        {
            int userId = int.Parse(HttpContext.User.FindFirstValue("Id"));

            _commentsService.Add(userId, ICommentsService.CommentType.Question, id, newComment.Message);
            return(RedirectToAction("Details", new { id }));
        }
Esempio n. 2
0
        public ResultModel AddComment(AddCommentModel model)
        {
            ResultModel result = new ResultModel();

            sqlCommand = new SqlCommand()
            {
                Connection  = connectionHelper.connection,
                CommandType = CommandType.StoredProcedure,
                CommandText = "AddCommentSP",
            };

            sqlCommand.Parameters.Add("@EventId", SqlDbType.Int).Value      = model.EventId;
            sqlCommand.Parameters.Add("@PersonId", SqlDbType.Int).Value     = model.PersonId;
            sqlCommand.Parameters.Add("@Title", SqlDbType.NVarChar).Value   = model.Title;
            sqlCommand.Parameters.Add("@Content", SqlDbType.NVarChar).Value = model.Content;

            connectionHelper.connection.Open();
            SqlDataReader sqlReader = sqlCommand.ExecuteReader();

            if (sqlReader.HasRows)
            {
                if (sqlReader.Read())
                {
                    result = new ResultModel()
                    {
                        IsSuccess = (bool)sqlReader["IsSuccess"],
                        Message   = sqlReader["Message"] as string
                    };
                }
            }

            connectionHelper.connection.Close();

            return(result);
        }
        public ActionResult AddComment(AddCommentModel model)
        {
            var controller = DependencyResolver.Current.GetService <HomeController>();

            controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller);
            User    user    = controller.GetActualUser();
            Comment comment = null;
            Post    post    = null;

            using (BlogContext context = new BlogContext())
            {
                post    = context.Posts.SingleOrDefault(p => p.PostId == model.Postid);
                comment = new Comment()
                {
                    Title   = model.Title,
                    Content = model.Content,
                    UserID  = user.UserId,
                    Post    = post
                };
                PairCommentWithPost(ref post, ref comment);
                context.Comments.Add(comment);
                context.SaveChanges();
                return(RedirectToAction("ViewPost", "Post", comment.Post));
                // return RedirectToAction("ViewSingleComment", new { @CommentID = comment.CommentId });
            }
        }
Esempio n. 4
0
        public IActionResult Comment([Bind(nameof(AddCommentModel.BlogComposesId),
                                           nameof(AddCommentModel.Name),
                                           nameof(AddCommentModel.Email),
                                           nameof(AddCommentModel.Message),
                                           nameof(AddCommentModel.IsAprove))]
                                     AddCommentModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.Add();
                    model.Response = new ResponseModel("Comment Successful Wating for Review", ResponseType.Success);

                    //logger code
                    _logger.LogInformation("Comment Create Sucessfully");

                    return(RedirectToAction("Post", new { id = model.BlogComposesId }));
                }

                catch (Exception ex)
                {
                    model.Response = new ResponseModel("Comment failued.", ResponseType.Failure);
                    _logger.LogError($"Comment Add 'Failed'. Excption is : {ex.Message}");
                }
            }

            return(View());
        }
Esempio n. 5
0
        public async Task <IBaseResponse <List <CommentModel> > > AddComment(AddCommentModel addCommentModel, int userId)
        {
            if (addCommentModel != null)
            {
                await _applicationContext.Comments.AddAsync
                (
                    new Comment
                {
                    DateTime  = DateTime.Now,
                    Text      = addCommentModel.Text,
                    UserId    = userId,
                    LectureId = addCommentModel.LectureId
                }
                );

                await _applicationContext.SaveChangesAsync();
            }

            var commentList = await _applicationContext.Comments.Where(com => com.LectureId == addCommentModel.LectureId).ToListAsync();

            var comments = new List <CommentModel>();

            comments = await CommonMethods.GetCommentList(commentList, comments, _applicationContext, _mapper, userId);

            return(new BaseResponse <List <CommentModel> >
            {
                Code = addCommentModel != null ? HttpStatusCode.Created : HttpStatusCode.BadRequest,
                Data = comments
            });
        }
Esempio n. 6
0
        public async Task <ActionResult> AddComment(AddCommentModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(User.Identity.Name);

                var message = new ForumMessage
                {
                    ForumId        = model.ForumId,
                    ReplyMessageId = null,
                    Message        = model.Comment,
                    UserId         = user.Id
                };

                db.ForumMessages.Add(message);
                await db.SaveChangesAsync();

                return(RedirectToAction("Messages", "Forum", new { id = model.ForumId }));
            }

            //ViewBag.ForumId = new SelectList(db.Forums, "ForumId", "ForumId", forumMessage.ForumId);
            //ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", forumMessage.UserId);
            ModelState.AddModelError("Error ", "Please enter a valid comment");
            return(RedirectToAction("Messages", "Forum", new { id = model.ForumId }));
        }
        /// <summary>
        /// Add comment by specified values
        /// </summary>
        /// <param name="addCommentModel">Comment values</param>
        /// <exception cref="ArgumentNullException">Parameter addCommentModel is null</exception>
        /// <exception cref="ArgumentNullException">Message isn't specified</exception>
        /// <returns>Identifier value of new created comment</returns>
        public Guid Add(AddCommentModel addCommentModel)
        {
            if (addCommentModel == null)
            {
                throw new ArgumentNullException(nameof(addCommentModel));
            }

            if (string.IsNullOrEmpty(addCommentModel.Message))
            {
                throw new ArgumentNullException(nameof(addCommentModel.Message));
            }

            var newId = Guid.NewGuid();

            CommentsDataProvider.Add(new Comment
            {
                Id = newId,
                AppearanceCount = 0,
                CreatedOn       = DateTime.UtcNow,
                Message         = addCommentModel.Message,
                Description     = addCommentModel.Description
            });

            return(newId);
        }
Esempio n. 8
0
        public async Task CommentForGasStation_Delete_CommentIsDeleted()
        {
            // given

            var gasStationId = await CreateGasStation();

            var addCommentModel = new AddCommentModel
            {
                Content   = "Comment",
                SubjectId = gasStationId.ToString(),
                Tag       = CommentTag.GasStation
            };

            var createdAt = await fixture.HttpClient.PostJsonAsync <CreatedResponse>(Routes.Comments.ToString(), addCommentModel);

            // when

            await fixture.HttpClient.DeleteAsync($"{ Routes.Comments }/{ createdAt.Id }");

            // then

            var response = await fixture.HttpClient.GetAsync($"{ Routes.PriceSubmissions }/{ createdAt.Id }");

            response.StatusCode.Should().Be(HttpStatusCode.NotFound);
        }
Esempio n. 9
0
        public async Task CommentForGasStation_UpdateContent_UpdatedContentCanBeRetrieved()
        {
            // given

            var gasStationId = await CreateGasStation();

            var addCommentModel = new AddCommentModel
            {
                Content   = "Comment",
                SubjectId = gasStationId.ToString(),
                Tag       = CommentTag.GasStation
            };

            var createdAt = await fixture.HttpClient.PostJsonAsync <CreatedResponse>(Routes.Comments.ToString(), addCommentModel);

            // when

            var updateCommentModel = new UpdateCommentModel {
                Content = "Updated Comment"
            };
            await fixture.HttpClient.PutJsonAsync($"{ Routes.Comments }/{ createdAt.Id }", updateCommentModel);

            // then

            var comment = await fixture.HttpClient.GetJsonAsync <Comment>($"{ Routes.Comments }/{ createdAt.Id }");

            comment.Should().BeEquivalentTo(updateCommentModel);
        }
Esempio n. 10
0
        public IHttpActionResult AddComment(int gameId, AddCommentModel model)
        {
            var comment = Mapper.Map <AddCommentModel, CommentDTO>(model);

            _commentService.AddComment(gameId, comment);

            return(Ok("Comment added"));
        }
Esempio n. 11
0
        public IHttpActionResult Reply(int commentId, AddCommentModel model)
        {
            var comment = Mapper.Map <AddCommentModel, CommentDTO>(model);

            _commentService.Reply(commentId, comment);

            return(Ok("Reply added"));
        }
Esempio n. 12
0
        public async Task EditCommentAsync(AddCommentModel addCommentModel, int id)
        {
            Comment comment = await _mySerialListDBContext.Comments.Where(c => c.Id == id).FirstOrDefaultAsync();

            comment.Description = addCommentModel.Description;
            comment.CreateAt    = DateTime.Now;

            await _mySerialListDBContext.SaveChangesAsync();
        }
Esempio n. 13
0
        public void ShouldReturnBaseServiceResultSuccess()
        {
            AddCommentModel model = null;

            BaseServiceResult <Guid> result = TestedController.Add(model);

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);
            Assert.Empty(result.ErrorMessage);
        }
Esempio n. 14
0
        public async Task CommentPost(AddCommentModel model)
        {
            var commentPostRequest = new CommentPostRequest
            {
                Content = model.Content,
                PostId  = model.PostId
            };

            await _postsManagementService.CommentPost(commentPostRequest);
        }
Esempio n. 15
0
        public async Task CreatComment(AddCommentModel addCommentModel)
        {
            var commentEntity = new Comment();

            commentEntity.ArticleId   = addCommentModel.ArticleId;
            commentEntity.AuthorId    = addCommentModel.AuthorId;
            commentEntity.Body        = addCommentModel.Body;
            commentEntity.CreatedDate = DateTime.UtcNow;
            context.Comments.Add(commentEntity);
            await context.SaveChangesAsync();
        }
Esempio n. 16
0
        public async Task <ActionResult> AddComment(AddCommentModel model)
        {
            if (ModelState.IsValid)
            {
                await model.AddComment(User.Identity.Name);

                return(RedirectToAction("Details", "Post", new { id = model.PostId }));
            }

            return(View(model));
        }
        public async Task AddCommentAsync(AddCommentModel addCommentModel, string userId)
        {
            await CheckFilmProductionExist(addCommentModel.FilmProductionId);

            if (!await _userFilmProductionsRepository.IsFilmProductionAddedAsync(addCommentModel.FilmProductionId, userId))
            {
                throw new HttpStatusCodeException(HttpStatusCode.BadRequest, "Dodaj Produkcje filmową do swojej list aby móc ją komentować.");
            }

            await _reviewFilmProductionRepository.AddCommentAsync(addCommentModel, userId);
        }
        public async Task <IActionResult> PostComment([FromBody] AddCommentModel addCommentModel)
        {
            var UserId  = int.Parse(HttpContext.User.Identity.Name);
            var PhotoId = addCommentModel.ProfilePhotoId;
            var Message = addCommentModel.Message;

            var comment = await Task.Run(() => _commentService.CreateComment(UserId, PhotoId, Message));

            var model = _mapper.Map <CommentModel>(comment);

            return(Ok(model));
        }
Esempio n. 19
0
        public void ShouldThrowArgumentNullExceptionWhenAddWithEmptyModel()
        {
            AddCommentModel model = null;

            var exception =
                Record.Exception(
                    () => TestedService.Add(model)
                    );

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
Esempio n. 20
0
        public async Task AddCommentAsync(AddCommentModel addCommentModel, string userId)
        {
            await _mySerialListDBContext.Comments.AddAsync(new Comment
            {
                FilmProductionId = addCommentModel.FilmProductionId,
                Description      = addCommentModel.Description,
                CreateAt         = DateTime.Now,
                UserId           = userId
            });

            await _mySerialListDBContext.SaveChangesAsync();
        }
Esempio n. 21
0
        public async Task <IActionResult> AddComment([FromBody] AddCommentModel addCommentModel)
        {
            var response = await _commentService.AddComment(addCommentModel, Convert.ToInt32(Request.Cookies["userId"]));

            if (response.Code <= HttpStatusCode.PermanentRedirect)
            {
                return(Json(response.Data));
            }
            else
            {
                return(BadRequest());
            }
        }
        public IHttpActionResult Create(int id, AddCommentModel model)
        {
            var userId = this.User.Identity.GetUserId();

            var comment = new Comment
            {
                Content = model.Content,
                BookId  = model.Id,
                UserId  = userId
            };

            return(this.Ok(comment));
        }
        public ActionResult Index(AddCommentModel model)
        {
            if (model.User != null && model.User.Avatar != null && model.User.Avatar.ContentLength > 0)
            {
                model.User.Avatar.SaveAs("C:/Users/Alexander/Documents/Temp/" + model.User.Avatar.FileName);
            }
            if (!string.IsNullOrWhiteSpace(model.Comment))
            {
                CommentsRepository.Comments.Add(model.Comment);
            }

            return(View(new ArticleModel()));
        }
        //AddComment Method allows to post a comment on a plant by taking information like plantID , Title and comment.
        public bool AddComment(AddCommentModel model)
        {
            Comments comments = new Comments
            {
                PlantID     = model.PlantID,
                Title       = model.Title,
                Comment     = model.Comment,
                UserID      = _userID,
                CreatedDate = DateTimeOffset.UtcNow
            };

            ctx.Comments.Add(comments);
            return(ctx.SaveChanges() == 1);
        }
        public async Task EditCommentAsync(AddCommentModel addCommentModel, int id, string userId)
        {
            if (!await _reviewFilmProductionRepository.CommentExsistsAsync(id))
            {
                throw new HttpStatusCodeException(HttpStatusCode.NotFound, "Komentarz nie istnieje.");
            }

            if (!await _reviewFilmProductionRepository.IsUserCommentAsync(id, userId))
            {
                throw new HttpStatusCodeException(HttpStatusCode.BadRequest, "Nie możesz edytować tego komentarza.");
            }

            await _reviewFilmProductionRepository.EditCommentAsync(addCommentModel, id);
        }
        public IHttpActionResult AddComment(AddCommentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateSocialInteractionsService();

            if (!service.AddComment(model))
            {
                return(InternalServerError());
            }
            return(Ok("Comment Added"));
        }
Esempio n. 27
0
        public async Task <long> Create(AddCommentModel model)
        {
            var comment = new Entities.Comment(
                content: model.Content,
                createdAt: DateTime.UtcNow,
                tag: model.Tag,
                subjectId: model.SubjectId);

            auditMetadataProvider.AddAuditMetadataToNewEntity(comment);
            dbContext.Add(comment);
            await dbContext.SaveChangesAsync();

            return(comment.Id);
        }
Esempio n. 28
0
        public IActionResult Edit(int id, AddCommentModel newComment)
        {
            int userId = int.Parse(HttpContext.User.FindFirstValue("Id"));

            try
            {
                _commentsService.Update(userId, id, newComment.Message);
            }
            catch (AskMateNotAuthorizedException)
            {
                return(Forbid());
            }
            return(RedirectToAction("Details", "Questions", new { id = newComment.QuestionId }));
        }
        public BaseServiceResult <Guid> Add([FromBody] AddCommentModel addCommentModel)
        {
            try
            {
                var newId = CommentService.Add(addCommentModel);

                return(BaseServiceResult <Guid> .Success(newId));
            }
            catch (Exception e)
            {
                Logger?.LogError(e, "Trying to: add comment.");
                return(BaseServiceResult <Guid> .Error(e));
            }
        }
Esempio n. 30
0
        public async Task <IActionResult> AddComment(long postId, AddCommentModel model)
        {
            var session = HttpContext.Session;
            var userId  = session.GetString(CommonConstants.USER_SESSION);

            if (userId == null)
            {
                return(Unauthorized());
            }
            var accessId = Convert.ToInt64(userId);
            var result   = await commentService.AddComment(accessId, postId, model);

            return(Ok(result));
        }
        public override bool Execute()
        {
            int numEvents = eventServices.GetAllEvents().Count();
            int numUserProfiles = accountServices.GetAllUserProfiles().Count();

            int eventId = random.Next(1, numEvents);
            int userProfileId = random.Next(1, numUserProfiles);

            AddCommentModel addCommentModel = new AddCommentModel();
            addCommentModel.EventId = eventId;
            addCommentModel.UserProfileId = userProfileId;
            addCommentModel.Comment = "OHOHOHO " + Name + " " + DateTime.Now.ToString();

            return eventServices.AddComment(addCommentModel);
        }