Esempio n. 1
0
 public Post Add(Post post)
 {
     post.Created = DateTime.UtcNow;
     _context.Posts.Add(post);
     _context.SaveChanges();
     return(post);
 }
Esempio n. 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 Create([Bind(Include = "Id,Adi,Aciklama,Aktif")] Kategori kategori)
        {
            if (ModelState.IsValid)
            {
                kategori.Aktif = true;
                db.Kategori.Add(kategori);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(kategori));
        }
Esempio n. 4
0
 public string Post(Blog blog)
 {
     try
     {
         _context.Blogs.Add(blog);
         _context.SaveChanges();
         return("Blog published successfully");
     }
     catch (Exception e)
     {
         return("Blog could not be added");
     }
 }
 public string Post(BlogPost post)
 {
     try
     {
         _context.BlogPosts.Add(post);
         _context.SaveChanges();
         return("Blog Post Added");
     }
     catch (Exception e)
     {
         return("Blog Post could not be added");
     }
 }
Esempio n. 6
0
 public string Post(Comment comment)
 {
     try
     {
         _context.Comments.Add(comment);
         _context.SaveChanges();
         return("Comment added successfully");
     }
     catch (Exception e)
     {
         return("Comment could not be added");
     }
 }
Esempio n. 7
0
 public string Post(Users user)
 {
     _context.Users.Add(user);
     try
     {
         _context.SaveChanges();
         return("User Added Successfully");
     }
     catch (Exception e)
     {
         return("User could not be added");
     }
 }
Esempio n. 8
0
        public ActionResult AddComment(long blog_id, string new_comment)
        {
            Blog blog = null;

            if (ModelState.IsValid)
            {
                blog = db.Blogs.Find(blog_id);
                blog.comments.Add(new Comment
                {
                    author     = User.Identity.Name,
                    date       = System.DateTime.Now,
                    content    = new_comment,
                    creationTS = System.DateTime.Now,
                    updatedTS  = System.DateTime.Now
                });

                db.SaveChanges();
            }

            return(PartialView("_Comments", blog.comments));
        }
Esempio n. 9
0
        public ActionResult Save(BlogViewData model, string blog_title, string blog_content)
        {
            Blog newBlog = new Blog();

            newBlog.title      = blog_title;
            newBlog.date       = System.DateTime.Now;
            newBlog.content    = blog_content;
            newBlog.creationTS = System.DateTime.Now;
            newBlog.updatedTS  = System.DateTime.Now;
            int[] tagIds = model.SelectedTags;

            List <Tag> selectedTags = new List <Tag>();

            // Get the Tag objects from the DB
            for (int i = 0; i < tagIds.Count(); i++)
            {
                int currentTag = tagIds[i];
                Tag t          = (from tag in db.Tags
                                  where tag.id == currentTag
                                  select tag).FirstOrDefault();
                selectedTags.Add(t);
            }

            // Add the Tag Objects to the Blog Object
            newBlog.tags.AddRange(selectedTags);

            db.Blogs.Add(newBlog);
            db.SaveChanges();

            //Reset the Tags
            model.allTags = (from tag in db.Tags
                             orderby tag.name ascending
                             select tag).ToList();

            return(RedirectToAction("Index"));
        }
Esempio n. 10
0
 public bool SAVE()
 {
     return(ctx.SaveChanges() > 0);
 }
 public void Insert(TEntity entity)
 {
     context.Set <TEntity>().Add(entity);
     context.SaveChanges();
 }
 public Post Add(Post post)
 {
     _context.Posts.Add(post);
     _context.SaveChanges();
     return(post);
 }