public IActionResult Quote(string id)
        {
            var quote = this.quoteService.GetQuote(id, this.ModelState);

            if (this.ModelState.IsValid)
            {
                var recieverName = quote.Author.UserName;

                var model =
                    new QuoteInputModel
                {
                    ReplyId    = quote.ReplyId,
                    Quote      = quote.Description,
                    RecieverId = quote.Reply.Author.Id,
                };

                this.ViewData["ReplierName"]     = quote.Reply.Author.UserName;
                this.ViewData["PostName"]        = quote.Reply.Post.Name;
                this.ViewData["QuoteRecieverId"] = quote.Author.Id;

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

                return(result);
            }
        }
        public async Task <IActionResult> AddQuote(QuoteInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            await this.quotesService.CreateAsync(model);

            return(this.RedirectToAction("AddQuote"));
        }
Beispiel #3
0
        public async Task <IActionResult> Create(int replyId)
        {
            var replyContent = await this.replyService.GetReplyContent(replyId);

            var model = new QuoteInputModel
            {
                ReplyContent = replyContent
            };

            return(this.View(model));
        }
Beispiel #4
0
        public async Task <IActionResult> Create(QuoteInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                await this.quoteService.CreateQuoteAsync(model);

                return(this.Redirect($"/Post/Index?Id={model}"));
            }
            else
            {
                return(this.View(model));
            }
        }
        public async Task CreateQuoteAsync(QuoteInputModel model)
        {
            var reply = await replyService.GetReplyByIdAsync(model.Id);
            var user = await userService.GetLoggedInUserAsync();

            model.AuthorId = user.Id;
            model.ReplyAuthorId = reply.AuthorId;
            model.ReplyContent = reply.Content;
            model.ReplyAuthorName = reply.Author.UserName;

            var quote = mapper.Map<QuoteInputModel, Quote>(model);

            await dbContext.Quotes.AddAsync(quote);
            await dbContext.SaveChangesAsync();

        }
        public void AddQuote_returns_one_result_when_correct()
        {
            var author = this.dbService.DbContext.Users.FirstOrDefault(u => u.Id == TestsConstants.TestId);

            var model = new QuoteInputModel
            {
                Quote       = TestsConstants.ParsedValidPostDescription,
                Description = TestsConstants.ValidPostDescription,
                RecieverId  = TestsConstants.TestId1,
                ReplyId     = TestsConstants.TestId2
            };

            var expectedResult = 1;

            var actualResult = this.quoteService.AddQuote(model, author, TestsConstants.TestUsername2);

            Assert.Equal(expectedResult, actualResult);
        }
Beispiel #7
0
        public ActionResult Add(QuoteInputModel quote)
        {
            if (!ModelState.IsValid)
            {
                return(View(quote));
            }
            var newQuote = new Quote()
            {
                Text   = quote.Text,
                Author = new Author()
                {
                    Name = quote.Author.Name
                }
            };

            var result = this.quotes.Add(newQuote);

            return(RedirectToAction("Details", new { id = result }));
        }
Beispiel #8
0
        public async Task CreateAsync(QuoteInputModel model)
        {
            var author = this.db.Authors.FirstOrDefault(x => x.Name == model.AuthorName);

            if (author == null)
            {
                author = new Author
                {
                    Name = model.AuthorName,
                };
            }

            var quote = new Quote
            {
                Content = model.Content,
                Author  = author,
            };

            await this.db.Quotes.AddAsync(quote);

            await this.db.SaveChangesAsync();
        }
        public IActionResult Create(QuoteInputModel model)
        {
            var reply = this.replyService.GetReply(model.ReplyId, this.ModelState);

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

                var recieverName = this.accountService.GetUserById(model.RecieverId, this.ModelState).UserName;

                model.Description = this.postService.ParseDescription(model.Description);

                this.quoteService.AddQuote(model, user, recieverName);

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

                return(result);
            }
        }