コード例 #1
0
        //[ProducesResponseType(StatusCodes.Status422UnprocessableEntity,
        //    Type = typeof(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary))]
        public async Task <ActionResult <QuoteModel> > CreateQuote([FromBody] QuoteCreationModel quoteCreationModel)
        {
            try
            {
                //fetch the samurai from the db for profle mapping to use
                var samurai = await _samuraiRepository.GetSamuraiAsync(quoteCreationModel.SamuraiId);

                if (samurai == null)
                {
                    return(NotFound());
                }

                var quoteEntity = _mapper.Map <Quote>(quoteCreationModel);
                _quoteRepository.AddQuote(quoteEntity);

                await _quoteRepository.SaveChangeAsync();

                return(CreatedAtRoute("GetQuote",
                                      new { quoteId = quoteEntity.Id },
                                      _mapper.Map <QuoteModel>(quoteEntity)));
            }
            catch (Exception ex)
            {
                _logger.LogError($"{ex.Message}");
                throw;
            }
        }
コード例 #2
0
        public IActionResult GetUsers([FromBody] QuoteModel quote)
        {
            try{
                var quoteId = _quotesRepository.AddQuote(quote);

                return(Ok(quoteId));
            }catch (Exception e) {
                _logger.LogError($"Não foi possivel adicionar quote: {e}");
                return(BadRequest());
            }
        }
コード例 #3
0
 public Response AddQuote(QuoteModel quoteModel)
 {
     return(_quoteRepository.AddQuote(
                new Quote
     {
         Author = quoteModel.Author,
         TextQuote = quoteModel.TextQuote,
         Category = quoteModel.Category,
         CreatedAt = DateTime.Now,
         UpdatedAt = DateTime.Now
     }));
 }
コード例 #4
0
        public async Task <ActionResult <IEnumerable <QuoteModel> > > CreateQuoteCollection([FromBody] IEnumerable <QuoteCreationModel> quoteCollection)
        {
            var quoteEntities = _mapper.Map <IEnumerable <Quote> >(quoteCollection);

            foreach (var quoteEntity in quoteEntities)
            {
                _quoteRepository.AddQuote(quoteEntity);
            }

            await _quoteRepository.SaveChangeAsync();

            //get back list of quote id we just created
            var quotesToReturn = await _quoteRepository.GetQuotesAsync(
                quoteEntities.Select(q => q.Id).ToList());

            var quoteIds = string.Join(",", quotesToReturn.Select(q => q.Id));

            return(CreatedAtRoute("GetQuoteCollections",
                                  new { quoteIds = quoteIds },
                                  quotesToReturn));
        }
コード例 #5
0
ファイル: QuizController.cs プロジェクト: dblasher/QuoteQuiz
        public RedirectToActionResult AddQuote(string text, string character, string movie, string link)
        {
            //use LINQ to check there are no quotes already in the db with the same text
            bool exists = (from quotes in repo.Quotes
                           where quotes.Text == text
                           select quotes).Any();

            if (exists)
            {
                //notify user their quote is already in, verbatim!
                TempData["message"] = "Sorry, that quote has already been added";
            }
            else
            {
                Character name = new Character()
                {
                    Name = character
                };
                Movie title = new Movie()
                {
                    Title = movie
                };
                //truncate link, removes everything before the unique video Id
                //Or just let Results.chtml do the truncating so the database has full youtube links
                //int i = link.IndexOf("=");
                //string subLink = link.Remove(0, i + 1);
                Quote quote = new Quote()
                {
                    Text      = text,
                    Character = name,
                    Movie     = title,
                    Link      = link
                };
                repo.AddQuote(quote);
                //notify user of successful submission
                TempData["message"] = "Thank you for adding a quote!";
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #6
0
ファイル: QuoteService.cs プロジェクト: Druseski/BookStore
 public void Add(QuoteMap quote)
 {
     _quoteRepository.AddQuote(quote);
 }
コード例 #7
0
 public Quote AddQuote(Quote quote)
 {
     return(_quoteRepo.AddQuote(quote));
 }