Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("QuoteId,QuoteText,AuthorSpeaker,Date,Subject,Citation")] Quote quote)
        {
            if (ModelState.IsValid)
            {
                _context.Add(quote);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(quote));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This method add a new character to the DbContext and saves it
 /// </summary>
 /// <param name="character"></param>
 /// <returns></returns>
 public async Task <Character> AddCharacterAsync(Character character)
 {
     try
     {
         dbContext.Characters.Add(character);
         await dbContext.SaveChangesAsync();
     }
     catch (Exception)
     {
         throw;
     }
     return(character);
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([FromBody] Quote quote)
        {
            if (quote == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _context.Quotes.Add(quote);
            await _context.SaveChangesAsync();

            return(Ok(quote));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method add a new quote to the DbContext and saves it
        /// </summary>
        /// <param name="quote"></param>
        /// <returns></returns>
        public async Task <Quote> AddQuoteAsync(Quote quote)
        {
            var validationContext = new ValidationContext(quote);

            Validator.ValidateObject(quote, validationContext, true);
            try
            {
                quote = await SetRelatedProperties(quote);

                dbContext.Quotes.Add(quote);
                await dbContext.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw;
            }
            return(quote);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([FromBody] Quote model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            model.InsertDate = DateTime.Now;

            _quoteDbContext.Quotes.Add(model);
            await _quoteDbContext.SaveChangesAsync();

            return(Created("Quote created", model));
        }