示例#1
0
        public IActionResult Edit(int id, [Bind("Id,Title,Perex,Content,AuthorId,CreatedAt")] Post post)
        {
            if (id != post.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(post);
                    _context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostExists(post.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(post));
        }
示例#2
0
 public ActionResult <Post> Patch(Guid ID, [FromBody] Post post)
 {
     try
     {
         _ctx.Update(post);
         return(Ok(post));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw new Exception();
     }
 }
示例#3
0
        public async Task <IActionResult> Put(int?id, [Bind("ID, Title, Author, Content")] Post post)
        {
            if (id != post.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Update(post);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(GetAll)));
            }

            return(View(post));
        }
示例#4
0
        public async Task <IActionResult> Put([FromBody] Post post)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _postsContext.Update(post);
            try
            {
                await _postsContext.SaveChangesAsync();

                return(Ok());
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }
        }
示例#5
0
 public ActionResult <Post> Patch(Guid ID, [FromBody] Post post)
 {
     _ctx.Update(post);
     return(Ok(post));
 }