Exemple #1
0
        public ActionResult DeletePosts(int id)
        {
            t_posts posts = obj.t_posts.Where(x => x.id.Equals(id)).SingleOrDefault();

            obj.t_posts.Remove(posts);
            obj.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            t_posts t_posts = db.t_posts.Find(id);

            db.t_posts.Remove(t_posts);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "id,userid,title,url,tags,categoryId,postContent,date_time")] t_posts t_posts)
 {
     if (ModelState.IsValid)
     {
         db.Entry(t_posts).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.categoryId = new SelectList(db.t_category, "id", "category", t_posts.categoryId);
     ViewBag.userid     = new SelectList(db.t_user, "id", "username", t_posts.userid);
     return(View(t_posts));
 }
Exemple #4
0
        public ActionResult EditPosts(Posts editData)
        {
            t_posts posts = obj.t_posts.Where(x => x.id.Equals(editData.id)).SingleOrDefault();

            posts.title       = editData.Title;
            posts.tags        = editData.Tags;
            posts.url         = editData.Url;
            posts.postContent = editData.PostContent;
            posts.categoryId  = Convert.ToInt32(Request["categories"]);
            posts.is_active   = editData.Is_active;
            obj.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            t_posts t_posts = db.t_posts.Find(id);

            if (t_posts == null)
            {
                return(HttpNotFound());
            }
            return(View(t_posts));
        }
        // GET: Test/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            t_posts t_posts = db.t_posts.Find(id);

            if (t_posts == null)
            {
                return(HttpNotFound());
            }
            ViewBag.categoryId = new SelectList(db.t_category, "id", "category", t_posts.categoryId);
            ViewBag.userid     = new SelectList(db.t_user, "id", "username", t_posts.userid);
            return(View(t_posts));
        }
Exemple #7
0
        public ActionResult CreatePosts(Posts posts)
        {
            if (ModelState.IsValid)
            {
                t_posts tposts = new t_posts();
                tposts.title       = posts.Title;
                tposts.url         = string.IsNullOrEmpty(posts.Url) ? GenerateURL(posts.Title) : GenerateURL(posts.Url);//posts.Url;
                tposts.postContent = posts.PostContent;
                tposts.tags        = posts.Tags;
                tposts.categoryId  = Convert.ToInt32(Request["Category"]);
                tposts.date_time   = System.DateTime.Now.ToString("yyyy-MM-dd");
                tposts.userid      = ((UserDetails)Session["userdetails"]).id;
                obj.t_posts.Add(tposts);
                obj.SaveChanges();
                if (((UserDetails)Session["userdetails"]).role == "Admin")
                {
                    return(RedirectToAction("Index", "Admin"));
                }

                return(RedirectToAction("CreatePosts"));
            }
            ViewBag.Category = new SelectList(obj.t_category, "id", "category");
            return(View());
        }