tag pages
news create form correction
This commit is contained in:
@ -13,21 +13,27 @@ namespace WebApplication1.Controllers
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
setTitle();
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult About()
|
||||
{
|
||||
ViewBag.Message = "Your application description page.";
|
||||
|
||||
setTitle();
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Contact()
|
||||
{
|
||||
ViewBag.Message = "Your contact page.";
|
||||
|
||||
setTitle();
|
||||
return View();
|
||||
}
|
||||
|
||||
void setTitle()
|
||||
{
|
||||
ViewBag.titlemenu = "hi user";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,8 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(db.news.Where(n => n.title.Contains(category.title)));
|
||||
//search for record that contains "cat title" in cat field.
|
||||
return View(db.news.Where(n => n.cat.Contains(category.title)));
|
||||
}
|
||||
|
||||
// GET: categories/Create
|
||||
|
||||
@ -38,7 +38,23 @@ namespace WebApplication1.Controllers
|
||||
// GET: news/Create
|
||||
public ActionResult Create()
|
||||
{
|
||||
return View();
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
var news = db.news.ToList();
|
||||
var cat = db.categories.ToList();
|
||||
ViewBag.categoryTitle = cat;
|
||||
var tags= db.tags.ToList();
|
||||
ViewBag.tagTitle = tags;
|
||||
//var models= new Tuple<List<category>, List<tag>>(cat, tags);
|
||||
return View();
|
||||
}
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
ViewBag.categoryTitle = db.categories.ToList();
|
||||
return View();
|
||||
}
|
||||
else
|
||||
return RedirectToAction("login", "users");
|
||||
}
|
||||
|
||||
// POST: news/Create
|
||||
@ -50,6 +66,7 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
||||
db.news.Add(news);
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
|
||||
141
Controllers/tagsController.cs
Normal file
141
Controllers/tagsController.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace WebApplication1.Models
|
||||
{
|
||||
public class tagsController : Controller
|
||||
{
|
||||
private newswebappEntities db = new newswebappEntities();
|
||||
|
||||
// GET: tags
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View(db.tags.ToList());
|
||||
}
|
||||
|
||||
// GET: tags/Details/5
|
||||
public ActionResult Details(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
tag tags = db.tags.Find(id);
|
||||
ViewBag.title = tags.title;
|
||||
if (tags == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
//search for record that contains "tag title" in tag field.
|
||||
return View(db.news.Where(n => n.tag.Contains(tags.title)));
|
||||
}
|
||||
|
||||
// GET: tags/Create
|
||||
public ActionResult Create()
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) == 1)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
||||
else
|
||||
return RedirectToAction("index", "home");
|
||||
}
|
||||
|
||||
// POST: tags/Create
|
||||
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Create([Bind(Include = "code,link,title")] tag tag)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
tag.link = "tags/"+tag.title;
|
||||
db.tags.Add(tag);
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return View(tag);
|
||||
}
|
||||
|
||||
// GET: tags/Edit/5
|
||||
public ActionResult Edit(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
tag tag = db.tags.Find(id);
|
||||
if (tag == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(tag);
|
||||
}
|
||||
|
||||
// POST: tags/Edit/5
|
||||
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Edit([Bind(Include = "code,link,title")] tag tag)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
db.Entry(tag).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return View(tag);
|
||||
}
|
||||
|
||||
// GET: tags/Delete/5
|
||||
public ActionResult Delete(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
tag tag = db.tags.Find(id);
|
||||
if (tag == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(tag);
|
||||
}
|
||||
|
||||
// POST: tags/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult DeleteConfirmed(int id)
|
||||
{
|
||||
tag tag = db.tags.Find(id);
|
||||
db.tags.Remove(tag);
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
db.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user