基本信息
源码名称:MVC EF开发的留言板实例源码下载
源码大小:4.62M
文件格式:.rar
开发语言:C#
更新时间:2015-01-27
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 4 元 
   源码介绍

MVC基于EF开发的留言板

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LiuYanBan.Models;
using LiuYanBan.Services;
using System.Linq.Expressions;
using LiuYaBan.Entity;
using _5rchina.BLL;

namespace LiuYanBan.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            IndexModel model = new IndexModel();
            Expression<Func<Message, bool>> p = PredicateBuilder.True<Message>();
            p = p.And(a => a.ParentID == 0);          
            IQueryable<Message> Query=MessageService.GetByExpression(p);
            model.Messages = Query.OrderByDescending(a => a.CreateTime).ToList();
            MessageService.Dispose();
            model.Types = TypeSevice.All();
            return View(model);
        }

        [HttpGet]
        public ActionResult PostCommentary(string contents)
        {
            JsonResultInfo returnJson = null;
            if (contents.Length > 0)
            {
                Message m = new Message();
                m.Contents = contents;
                m.TypeID = 0;
                m.UserID = 0;
                m.ParentID = 0;
                m.CreateTime = DateTime.Now;
                m=MessageService.Add(m);
                if (m!=null&&m.MessageID>0)
                {
                    returnJson = new JsonResultInfo("post", "发表评论成功!", 0);
                    return Json(returnJson, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    returnJson = new JsonResultInfo("post", "系统繁忙请稍后再试!", 5);
                    return Json(returnJson, JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                returnJson = new JsonResultInfo("post", "请填写评论内容!", 3);
                return Json(returnJson, JsonRequestBehavior.AllowGet);
            }
        }
    }
    [Serializable]
    public class JsonResultInfo
    {
        public JsonResultInfo(string op, string msg, int error)
        {
            this.op = op;
            this.msg = msg;
            this.error = error;
        }
        public string op { set; get; }
        public string msg { set; get; }
        public int error { set; get; }
    }
}