public ActionResult Edit([Bind(Include = "ID,AuthorID,Content,Source,Category")] Quote quote)
 {
     if (ModelState.IsValid)
     {
         db.Entry(quote).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorID = new SelectList(db.Authors, "ID", "FirstName", quote.AuthorID);
     return(View(quote));
 }
        public ActionResult Edit([Bind(Include = "QuoteId,body,authorName,entryDate")] Quote quote)
        {
            if (ModelState.IsValid)
            {
                quoteDb.Entry(quote).State = EntityState.Modified;
                quoteDb.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutQuoteItem(long id, QuoteItem quoteItem)
        {
            if (id != quoteItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(quoteItem).State = EntityState.Modified;
            if (quoteItem.author == "")
            {
                ModelState.AddModelError("Author", "Не добавлен автор");
            }
            if (quoteItem.quote == "")
            {
                ModelState.AddModelError("Quote", "Не добавлена цитата");
            }
            // если есть ошибки - возвращаем ошибку 400
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuoteItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }