Esempio n. 1
0
        public IActionResult Create(CreateCommentModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                this.TempData.Put(TempDataKeyModel, model);

                return(Redirect(RedirectToLoginPath));
            }

            if (!ModelState.IsValid || !this.bookService.IfBookExists(model.BookId))
            {
                return(BadRequest());
            }

            var username = this.User.Identity.Name;

            if (this.commentsService.IfCurrentUserHaveCommentToCurrentBook(username, model.BookId))
            {
                return(Redirect(GlobalConstants.IndexPath));
            }

            this.commentsService.CreateComment(username, model.Rating, model.BookId, model.Content, model.Title);

            return(Redirect(GlobalConstants.IndexPath));
        }
Esempio n. 2
0
        public ActionResult Create(CreateCommentModel model)
        {
            var dateCreated = Common.CurrentTime();
            var response = _commandBus.Send<CreateComment, CreateCommentResponse>(new CreateComment
            {
                PostId = model.PostId,
                ParentId = model.ParentId,
                DateCreated = dateCreated,
                AuthorIpAddress = HttpContext.RemoteAddress(),
                AuthorUserName = _userContext.CurrentUser.UserName,
                Body = model.Body,
                SendReplies = model.SendReplies
            });

            if (!string.IsNullOrEmpty(response.Error))
                return CommonJsonResult(response.Error);

            if (!response.CommentId.HasValue)
                throw new Exception("No error was given, which indicates success, but no comment id was returned.");

            var node = _commentWrapper.Wrap(response.CommentId.Value, _userContext.CurrentUser);

            return Json(new
            {
                success = true,
                commentId = response.CommentId,
                html = RenderView("_CommentNode", new CommentNode(node))
            });
        }
Esempio n. 3
0
 public ActionResult CreateComment(CreateCommentModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (CurrenciesManager.CurrencyExists(model.Currency))
             {
                 return(Json(CurrenciesManager.CreateComment(model.Currency, model.Message, model.Vote, Username), JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
             }
         }
         else
         {
             return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
         }
     }
     catch
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
     }
 }
Esempio n. 4
0
        public ActionResult Create(CreateCommentModel model)
        {
            var dateCreated = Common.CurrentTime();
            var response    = _commandBus.Send <CreateComment, CreateCommentResponse>(new CreateComment
            {
                PostId          = model.PostId,
                ParentId        = model.ParentId,
                DateCreated     = dateCreated,
                AuthorIpAddress = HttpContext.RemoteAddress(),
                AuthorUserName  = _userContext.CurrentUser.UserName,
                Body            = model.Body,
                SendReplies     = model.SendReplies
            });

            if (!string.IsNullOrEmpty(response.Error))
            {
                return(CommonJsonResult(response.Error));
            }

            if (!response.CommentId.HasValue)
            {
                throw new Exception("No error was given, which indicates success, but no comment id was returned.");
            }

            var node = _commentWrapper.Wrap(response.CommentId.Value, _userContext.CurrentUser);

            return(Json(new
            {
                success = true,
                commentId = response.CommentId,
                html = RenderView("_CommentNode", new CommentNode(node))
            }));
        }
Esempio n. 5
0
        public ActionResult Create(long articleId)
        {
            var model = new CreateCommentModel {
                ArticleId = articleId
            };

            return(this.PartialView("CreateCommentPartial", model));
        }
        public IActionResult CreateComment([FromBody] CreateCommentModel new_comment)
        {
            if (new_comment == null)
            {
                return(BadRequest("Invalid request"));
            }

            if (new_comment.PlaceID < 0 ||
                String.IsNullOrWhiteSpace(new_comment.CommentText))
            {
                return(BadRequest("Can't add empty comment"));
            }

            string get_email          = null;
            var    identity           = HttpContext.User.Identity as ClaimsIdentity;
            IEnumerable <Claim> claim = identity.Claims;

            var usernameClaim = claim
                                .Where(x => x.Type == ClaimTypes.Name)
                                .FirstOrDefault();

            if (usernameClaim != null)
            {
                get_email = usernameClaim.Value;
            }

            if (String.IsNullOrWhiteSpace(get_email))
            {
                return(Unauthorized("Account not exists"));
            }

            using (var _context = new AppDBContext())
            {
                Users users = _context.Users.Where(users => (users.email == get_email))
                              .FirstOrDefault();
                if (users == null)
                {
                    return(Unauthorized("Account not exists"));
                }

                try
                {
                    Place_comments com = new Place_comments();
                    com.id_place     = Convert.ToInt32(new_comment.PlaceID);
                    com.id_user      = users.id_user;
                    com.comment      = new_comment.CommentText;
                    com.comment_date = DateTime.Now;
                    _context.Place_comments.Add(com);
                    _context.SaveChanges();
                }
                catch
                {
                    return(BadRequest("Can't add comment"));
                }
            }

            return(Ok());
        }
Esempio n. 7
0
        public void CreateCommentModel_Empty_Url()
        {
            var user    = Users.First().Value;
            var request = new CreateCommentModel(user, string.Empty, "test", AppSettings.AppInfo);

            var result = Validate(request);

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].ErrorMessage == Localization.Errors.EmptyUrlField);
        }
Esempio n. 8
0
        public async Task <ActionResult> Create(string type, int entityId, CreateCommentModel model)
        {
            var user = await _userService.GetUserByIdAsync(User.GetUserId());

            model.EntityType = type;
            model.EntityId   = entityId;

            var comment = await _commentService.CreateAsync(model, user);

            return(Created("", comment));
        }
Esempio n. 9
0
        public async Task <IActionResult> CreateComment([FromBody] CreateCommentModel model)
        {
            var result = await this.commentsService.CreateComment(model.UserId, model.PostId, model.Content);

            if (!result.Success)
            {
                return(Ok(result.Message));
            }

            return(Ok());
        }
        public IActionResult Create(CreateCommentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var ticket = _ticketFinder.Find(model.TicketId);

            ticket.AddComment(model.ToDomainObject());
            _ticketsModifier.UpdateTicket(ticket);
            return(RedirectToAction("Details", "Tickets", new { Id = model.TicketId }));
        }
Esempio n. 11
0
        public async Task <IActionResult> MakeComment(int id, [FromBody] CreateCommentModel comment)
        {
            CreateCommentDto create = new CreateCommentDto()
            {
                Body   = comment.Body,
                GameId = id,
                Name   = comment.Name
            };

            await gameService.CommentGame(create);

            return(StatusCode((int)HttpStatusCode.Created, "Comment was created"));
        }
        public ActionResult AddComment(CreateCommentModel model)
        {
            var comment = new Comment()
            {
                Body      = model.Body,
                CreatedOn = DateTime.Now,
                IdPost    = model.IdPost,
                IdUser    = Session.CurrentUser.IdUser,
            };

            Services.CommentLikeService.AddComment(comment);
            return(Json(new { success = true, responseText = "Comment successfuly sent!" }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 13
0
        public async Task <CommentModel> Add(Guid couponId, CreateCommentModel model)
        {
            model.UserId = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "userId").Value);
            var comment = _mapper.Map <Comment>(model);
            var coupon  = await _repository.GetById(couponId);

            coupon.AddComment(comment);

            _repository.Update(coupon);
            await _repository.SaveChanges();

            return(_mapper.Map <CommentModel>(comment));
        }
Esempio n. 14
0
        public async Task <ActionResult <Comment> > CreateAsync([FromBody] CreateCommentModel model)
        {
            var author = await userProvider.GetByIdAsync(model.AuthorId);

            var(domainResult, id) = await commentService
                                    .CreateAsync(model.Key, model.Content, model.ReplyCommentId, author);

            if (domainResult.Successed)
            {
                return(Created(Url.Action("GetById", new { id }), await commentService.GetByIdAsync(id)));
            }

            return(BadRequest(domainResult.ToProblemDetails()));
        }
        public ActionResult Create(CreateCommentModel model)
        {
            _postRepository.AddComment(
                model.Content, model.UserName,
                model.ReturnBlogSlug, model.ReturnPostSlug
                );

            return(RedirectToAction("Details", "Post",
                                    new
            {
                blogSlug = model.ReturnBlogSlug,
                postSlug = model.ReturnPostSlug
            }));
        }
Esempio n. 16
0
        public async Task <ActionResult <CreateCommentModel> > PostComment(CreateCommentModel commentModel)
        {
            if (await _identity.CreateCommentAsync(commentModel))
            {
                return(new OkResult());
            }

            return(new BadRequestResult());


            //_context.Comments.Add(comment);
            //await _context.SaveChangesAsync();

            //return CreatedAtAction("GetComment", new { id = comment.Id }, comment);
        }
Esempio n. 17
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                CreateCommentModel model = null;

                if (this.TempData.ContainsKey(CreateCommentModelKey))
                {
                    model     = this.TempData.Get <CreateCommentModel>(CreateCommentModelKey);
                    returnUrl = $"{RedirectToDetailsBookPageWithoutCurrentBookId}{model.BookId}";
                }

                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Username, Input.Password, Input.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");

                    if (model != null)
                    {
                        this.TempData.Put(CreateCommentModelKey, model);
                    }

                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }