Beispiel #1
0
        public ReplyInputModel GetReplyInputForm(Post post)
        {
            ReplyInputModel model = new ReplyInputModel()
            {
                PostId = post.Id,
                Post   = post
            };

            return(model);
        }
Beispiel #2
0
        public async Task MakeAsync(ReplyInputModel model, GamingForumUser Replier)
        {
            Reply reply = this.mapper.Map <ReplyInputModel, Reply>(model);

            reply.Replier   = Replier;
            reply.RepliedOn = DateTime.UtcNow;

            await this.context.Replies.AddAsync(reply);

            await this.context.SaveChangesAsync();
        }
Beispiel #3
0
        public void AddReply_returns_entity_result_when_correct()
        {
            var user = this.dbService.DbContext.Users.FirstOrDefault(u => u.Id == TestsConstants.TestId);

            var model = new ReplyInputModel {
                Description = TestsConstants.ValidPostDescription, Author = user, PostId = TestsConstants.TestId3
            };

            var expectedResult = 1;

            var actualResult = this.replyService.AddReply(model, user).GetAwaiter().GetResult();

            Assert.Equal(expectedResult, actualResult);
        }
Beispiel #4
0
        public async Task <IActionResult> Create(ReplyInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await this.userService.GetLoggedInUserAsync();

                await this.replyService.CreateReplyAsync(model, user);

                return(this.Redirect($"/Post/Index?Id={model.Id}"));
            }
            else
            {
                return(this.View(model));
            }
        }
Beispiel #5
0
        public async Task CreateReplyAsync(ReplyInputModel model, User user)
        {
            var post = await postService.GetPostByIdAsync(model.Id);

            Reply reply = new Reply
            {
                AuthorId  = user.Id,
                Content   = model.Content,
                CreatedOn = DateTime.UtcNow,
                PostId    = post.Id
            };

            await dbContext.Replies.AddAsync(reply);

            await dbContext.SaveChangesAsync();
        }
Beispiel #6
0
        public async Task <IActionResult> Make(ReplyInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                GamingForumUser replier = await this.accountService.GetLoggedInUserAsync(this.User);

                await this.replyService.MakeAsync(model, replier);

                return(this.Redirect($"/Post/Details/{model.PostId}"));
            }
            else
            {
                ViewResult result = this.View("Error", this.ModelState);

                result.StatusCode = (int)HttpStatusCode.BadRequest;

                return(result);
            }
        }
Beispiel #7
0
        public IActionResult Create(ReplyInputModel model)
        {
            var post = this.postService.GetPost(model.PostId, 0, this.User, this.ModelState);

            if (ModelState.IsValid)
            {
                var user = this.accountService.GetUser(this.User);

                this.replyService.AddReply(model, user).GetAwaiter().GetResult();

                return(this.Redirect($"/Post/Details?id={post.Id}"));
            }
            else
            {
                var result = this.View("Error", this.ModelState);
                result.StatusCode = (int)HttpStatusCode.NotFound;

                return(result);
            }
        }
Beispiel #8
0
        public async Task <IActionResult> Make(string id)
        {
            if (!this.User.Identity.IsAuthenticated)
            {
                return(this.Redirect("/Account/Login"));
            }

            Post post = await this.postService.GetByIdAsync(id, this.ModelState);

            if (this.ModelState.IsValid)
            {
                ReplyInputModel model = this.replyService.GetReplyInputForm(post);

                return(this.View(model));
            }
            else
            {
                ViewResult result = this.View("Error", this.ModelState);
                result.StatusCode = (int)HttpStatusCode.BadRequest;

                return(result);
            }
        }