Beispiel #1
0
        public async Task <IActionResult> PutBlog([FromRoute] int id, [FromBody] Blog blog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != blog.id)
            {
                return(BadRequest());
            }

            _context.Entry(blog).State = EntityState.Modified;

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

            return(NoContent());
        }
Beispiel #2
0
        public Post InsertPost(int blog_id, string title, string text, string[] tags)
        {
            try
            {
                post = new Post {
                    blog_id = blog_id, title = title, text = text
                };
                dbcontext.Add(post); // track posts
                dbcontext.SaveChanges();

                foreach (var item in tags)
                {
                    tag = new Tag {
                        name = item
                    };
                    dbcontext.Entry(tag).State = dbcontext.Tags.Any(t => t.name == item)
                        ? EntityState.Unchanged
                        : EntityState.Added;

                    dbcontext.SaveChanges();

                    var ptJoin = new PostTag {
                        post_id = post.id, tag_id = tag.id
                    };
                    dbcontext.Add(ptJoin);
                    dbcontext.SaveChanges();
                }
                return(post);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 public ActionResult Edit([Bind(Include = "Id,Adi,Aciklama,Aktif")] Kategori kategori)
 {
     if (ModelState.IsValid)
     {
         db.Entry(kategori).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(kategori));
 }
Beispiel #4
0
        public async Task <IActionResult> PutBlog(int id, BlogModel blog)
        {
            if (id != blog.Id)
            {
                return(BadRequest());
            }

            var originalBlog = await GetUserBlog(blog.Id);

            if (originalBlog != null)
            {
                originalBlog.Body    = blog.Body;
                originalBlog.Subject = blog.Subject;
                _context.Entry(originalBlog).State = EntityState.Modified;
            }
            else
            {
                return(NotFound());
            }

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

            return(NoContent());
        }
 public void Update(TEntity entity)
 {
     context.Entry(entity).State = EntityState.Modified;
     context.SaveChanges();
 }