示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("QuoteId,QuoteText,AuthorSpeaker,Date,Subject,Citation")] Quote quote)
        {
            if (id != quote.QuoteId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(quote);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!QuoteExists(quote.QuoteId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(quote));
        }
示例#2
0
 /// <summary>
 /// This method update and existing character and saves the changes
 /// </summary>
 /// <param name="character"></param>
 /// <returns></returns>
 public async Task <Character> UpdateCharacterAsync(Character character)
 {
     try
     {
         var characterExist = dbContext.Characters.FirstOrDefault(p => p.Id == character.Id);
         if (characterExist != null)
         {
             dbContext.Update(character);
             await dbContext.SaveChangesAsync();
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(character);
 }
示例#3
0
        /// <summary>
        /// This method update and existing quote and saves the changes
        /// </summary>
        /// <param name="quote"></param>
        /// <returns></returns>
        public async Task <Quote> UpdateQuoteAsync(Quote quote)
        {
            var validationContext = new ValidationContext(quote);

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

                var quoteExist = GetAllAndRelated().FirstOrDefault(p => p.Id == quote.Id);
                if (quoteExist != null)
                {
                    dbContext.Update(quote);
                    await dbContext.SaveChangesAsync();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(quote);
        }