Exemple #1
0
        public IHttpActionResult CreateComment(int pushId, string content)
        {
            var anunt = _anuntService.GetAnuntWithRole(pushId);

            if (User.IsInRole(anunt.Role))
            {
                var dto = new CommentCreateDto()
                {
                    Content = content,
                    Author  = User.Identity.GetUserName(),
                    Created = DateTime.Now,
                    PushId  = pushId
                };

                _commentsService.CreateComment(dto);

                var commentItem = new CommentItemDto()
                {
                    Author  = dto.Author,
                    Content = dto.Content,
                    Created = dto.Created
                };

                _signalRHelper.NotifyCommentsForPush(commentItem, pushId);

                return(Ok());
            }

            return(BadRequest());
        }
        public async Task<ActionResult<long>> CreateProject([FromBody] ProjectSettings projectSettings)
        {
            var projectId = await ProjectService.CreateProject(projectSettings);
            if (projectSettings.FromTemplateId.HasValue)
            {
                var templateId = projectSettings.FromTemplateId.Value;
                await CommentsService.CreateComment(new Comment{Content = $"TemplateId:{templateId}", ProjectId = projectId});
                var templateItems = await ItemService.GetItemsInProject(templateId);
                var sections = await SectionService.GetSectionsAsync(templateId);
                var firstSection = sections.First();
                var firstSectionItems = templateItems.Where(x => x.SectionId == firstSection.Id)
                    .ToList();

                firstSectionItems.ForEach(x =>
                    {
                        x.SectionId = null;
                        x.ProjectId = projectId;
                        x.DueDateTime = x.Due?.Datetime;
                        x.DueDate = x.Due?.Datetime == null ? x.Due?.Date : null;
                        x.UniqueId = $"{projectId}{x.Id}".GetHashCode().ToString();
                    });
                await ItemService.PostItems(firstSectionItems);
            }

            return CreatedAtAction(nameof(Get), projectId, new {projectId});
        }
        public async Task AddComment([FromBody] Comment comment)
        {
            using (Db)
            {
                await Db.Connection.OpenAsync();

                await CS.CreateComment(comment);
            }
        }
Exemple #4
0
        public IActionResult Create(string id, [FromForm] Comment comment)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Comment is not valid");
            }

            comment.ResponseId = new Guid(id);
            var user       = _userManager.GetUserAsync(HttpContext.User).Result;
            var newComment = _service.CreateComment(comment, user);

            return(View(newComment));
        }
        public async Task <IActionResult> Create([FromBody] Comment newComment)
        {
            try
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var comment = _commentsService.CreateComment(newComment, user);
                return(Created("", comment));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemple #6
0
        public ActionResult Create(Comment comment)
        {
            var postsWithCommentModel = _commentsService.GetPostsWithCommentModel("");

            if (ModelState.IsValid)
            {
                comment.CreatedAt = DateTime.Now;
                comment.Author    = User.Identity.GetUserId();
                _commentsService.CreateComment(comment);
                return(RedirectToAction("Index"));
            }

            postsWithCommentModel.Comment = comment;
            return(View(postsWithCommentModel));
        }
        public async Task <IActionResult> Create(string slug, [FromBody] CreateOrEditCommentDto model)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCodeAndDtoWrapper.BuilBadRequest(ModelState));
            }

            string          userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            ApplicationUser user   = await _usersService.GetCurrentUserAsync();

            Comment comment = await _commentService.CreateComment(user, slug, model.Content, userId);

            // return RedirectToAction("GetArticleBySlug", "Articles", new {slug = slug});
            return(StatusCodeAndDtoWrapper.BuildSuccess(CommentDetailsDto.Build(comment)));
        }
        public async Task <ActionResult> CreateComment([Bind("Body,ResponseId")] Comment newComment, int id)
        {
            try
            {
                newComment.ResponseId = id;
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var comment = _commentsService.CreateComment(newComment, user);
                return(RedirectToAction(nameof(GetComments), new { id = newComment.ResponseId }));
            }
            catch (Exception)
            {
                return(View(newComment));
            }
        }
Exemple #9
0
        public async Task <ActionResult <Comment> > Create([FromBody] Comment newComment)
        {
            try
            {
                Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>();

                Profile fullProfile = _profileService.GetOrCreateAccountProfile(userInfo);
                newComment.CreatorId = userInfo.Id;

                Comment comment = _service.CreateComment(newComment);
                comment.Creator = fullProfile;
                return(Ok(comment));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }