今天抽出时间,终于根据页面文档,简单写出了Controller层的代码。但是还没有做任何功能的实现。大致代码如下:
在Controller层,有两个Controller分别是:MessageController 和 UserController:
MessageController包含留言创建页,留言列表页和留言回复页。功能:写入新Message,写入回复Message,删除一个Message。
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MvcBBSApplication.Models; namespace MvcBBSApplication.Controllers { public class MessageController : Controller { // // GET: /Message/ //Page List Message public ActionResult ListMessage(string criteria) { return View(); } //Page Creat public ActionResult CreatMessage() { return View(); } //Insert Message [HttpPost] public ActionResult CreatMessage(Message message) { return View(); } //Page Reply Message public ActionResult ReplyMessage(int messageId) { return View(); } //Insert ReplyMessage public ActionResult ReplyMessage(int messageId,Reply reply) { return View(); } //Delete Message [HttpPost] public ActionResult DeleteMessage(int id) { return View(); } } }
UserController 包含 登录页和注册页。 功能:写入注册信息,登录,注销,以及一个private 的判断登录账户和密码的方法。
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MvcBBSApplication.Models; using System.Data.Entity.Validation; using System.Data; using System.Web.Security; namespace MvcBBSApplication.Controllers { public class UserController : Controller { //Page Register Member public ActionResult Register() { return View(); } //Insert Member [HttpPost] public ActionResult Register(User user) { return View(); } //Page Login public ActionResult Login(string returnUrl) { ViewBag.ReturnUrl = returnUrl; return View(); } //Login [HttpPost] public ActionResult Login(string email, string password, string returnUrl) { if (VaildateUser(email, password)) { FormsAuthentication.SetAuthCookie(email, false); if (string.IsNullOrEmpty(returnUrl)) { return RedirectToAction("ListMessage", "Message"); } else { return Redirect(returnUrl); } } ModelState.AddModelError("", "您输入的账号或密码错误"); return View(); } private bool VaildateUser(string email, string password) { return true; } //Logout public ActionResult Logout() { //TODO:清除cookie中的数据 FormsAuthentication.SignOut(); //TODO:清除Session 的值 Session.Clear(); return RedirectToAction("ListMessage","Message"); } } }
未完待续。。。。。。。。