public ActionResult Post(HttpPostedFileBase file, PoostViewModel model, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                string   SelectVal = form["SelectVal"];
                string[] FavIds    = SelectVal.Split(',');


                if (file != null)

                {
                    model.Imagepath = new byte[file.ContentLength];
                    file.InputStream.Read(model.Imagepath, 0, file.ContentLength);
                }

                var objectt = new PostTable
                {
                    Imagepath   = model.Imagepath,
                    Title       = model.Title,
                    Description = model.Description,
                    Userid      = User.Identity.GetUserId(),
                    DateTime    = DateTime.Now,
                };

                db.PostTable.Add(objectt);
                db.SaveChanges();

                int Postid = objectt.Id;


                TagUserTable fav = new TagUserTable();



                for (int i = 0; i < FavIds.Length; i++)
                {
                    var id = int.Parse(FavIds[i]);

                    fav.Tagsid = id;
                    fav.Userid = User.Identity.GetUserId();
                    fav.postid = Postid;

                    db.TagUserTable.Add(fav);
                    db.SaveChanges();
                }
            }
            else
            {
                return(View("Post", "Post"));
            }


            return(RedirectToAction("Index", "Post"));
        }
        public ActionResult Index()
        {
            PoostViewModel VModel = new PoostViewModel();
            var            userid = User.Identity.GetUserId();

            VModel.Posts    = db.PostTable.Include("User").Where(p => p.Userid == userid).ToList();
            VModel.postTags = db.TagUserTable.ToList();
            VModel.Tags     = db.Tags.ToList();


            return(View(VModel));
        }
        public ActionResult Edit(int id)
        {
            var userid   = User.Identity.GetUserId();
            var post     = db.PostTable.Single(g => g.Id == id && g.Userid == userid);
            var postView = new PoostViewModel
            {
                id          = post.Id,
                Title       = post.Title,
                Description = post.Description,
                Imagepath   = post.Imagepath,
                DateTime    = DateTime.Now,
            };

            return(View("Post", postView));
        }