Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("BlogId,Name,Url,Detail")] Blog blog)
        {
            if (id != blog.BlogId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(blog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlogExists(blog.BlogId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }
Пример #2
0
        public async Task <IActionResult> PutBlog(int id, Blog blog)
        {
            if (id != blog.BlogId)
            {
                return(BadRequest());
            }

            //_context.Entry(blog).State = EntityState.Modified;
            _context.Entry(blog).State        = EntityState.Detached;
            _context.Entry(blog.Detail).State = EntityState.Detached;


            try
            {
                //await _context.SaveChangesAsync();
                _context.Update(blog);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BlogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }