public Post Update(Post post)
 {
     Post p = _db.posts.Find(post.id);
     p.title = post.title;
     p.content = post.content;
     _db.SaveChanges();
     return p;
 }
        public ActionResult Create(HttpPostedFileBase[] files, string[] descriptions)
        {
            //Create Post
            Post post = new Post();
            post.title = Request["post.title"];
            post.slug = Request["post.slug"];
            post.type = PostType.Image;
            post.isFeature = bool.Parse(Request["post.isFeature"]);
            post.imageUrl = Request["post.imageUrl"];
            post.user = db.Users.Find(User.Identity.GetUserId());
            post.content = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
            post.createdDate = DateTime.Now;
            post.category = db.categories.Find(int.Parse(Request["post.category"]));

            db.posts.Add(post);
            db.SaveChanges();

            string id = post.id.ToString();

            if (files.Count() > 0)
            {

                //Create ImageGallery
                ImageGallery imageGallery = new ImageGallery();
                imageGallery.Id = Guid.NewGuid();
                imageGallery.Name = Request["imageGallery.Name"];
                imageGallery.ImagePath = "~/ImageGallery/";
                imageGallery.post = post;
                imageGallery = db.imageGallery.Add(imageGallery);
                db.SaveChanges();

                //Create List of Image for ImageGallery has been created
                for (int i = 0; i < files.Count(); i++)
                {
                    HttpPostedFileBase file = files[i];
                    string guid = Guid.NewGuid().ToString();
                    string fileName = imageGallery.Id + "_" + i + "_" + file.FileName;
                    file.SaveAs(Server.MapPath("~/ImageGallery/" + fileName));
                    Images image = new Images();
                    image.Description = descriptions[i] ?? "";
                    image.order = i;
                    image.gallery = imageGallery;
                    image.Name = i.ToString();
                    image.Path = imageGallery.ImagePath + fileName;
                    db.images.Add(image);

                    imageGallery.ImageList.Add(image);

                    //string path = "https://"+Request.Url.Host+":"+Request.Url.Port+ VirtualPathUtility.ToAbsolute(image.Path);
                }

                db.SaveChanges();
            }

            return View("index");
        }
 public Post Update(Post post)
 {
     var sqlQuery =
         "UPDATE Posts " +
         "SET FirstName = @FirstName, " +
         "    LastName  = @LastName, " +
         "    Email     = @Email " +
         "WHERE id = @id";
     this._db.Execute(sqlQuery, post);
     return post;
 }
 public void Add(Post post)
 {
     var sqlQuery = "INSERT INTO Posts (title, content, user_Id,createdDate) VALUES(@title, @content, @user_Id,@createdDate); " ;
        this._db.Query<ApplicationUser>(sqlQuery,post).Single();
 }
 public void Add(Post post)
 {
     this._db.posts.Add(post);
     this._db.SaveChanges();
 }