Пример #1
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());
        }
        public async Task <IActionResult> PutStudent([FromRoute] int id, [FromBody] Student student)
        {
            if (id != student.Id)
            {
                return(BadRequest());
            }

            context.Entry(student).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public void DeleteBlogPost(int id)
 {
     using (BlogPostContext context = new BlogPostContext(_connectionName, _schemaName))
     {
         Data.Model.BlogPost post = context.BlogPosts.Find(id);
         context.Entry(post).State = System.Data.EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public void UpdateBlogPost(Domain.Model.BlogPost post)
 {
     using (BlogPostContext context = new BlogPostContext(_connectionName, _schemaName))
     {
         context.Entry(new Data.Model.BlogPost {
             Id = post.Id, Post = post.Post, Title = post.Title
         }).State = System.Data.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #5
0
 public ActionResult Edit([Bind(Include = "Id,Name,BlogPostId")] Tag tag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BlogPostId = new SelectList(db.BlogPosts, "Id", "Title", tag.BlogPostId);
     return(View(tag));
 }
        public async Task <IActionResult> PutBlogPostItem(long id, BlogPostItem item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public ActionResult Edit([Bind(Include = "Id,Title,CreatedOn")] BlogPost blogPost)
        {
            if (ModelState.IsValid)
            {
                db.Entry(blogPost).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(blogPost));
        }