码迷,mamicode.com
首页 > Web开发 > 详细

简易留言薄系统-ASP.NET MVC(Model层)

时间:2017-08-19 11:11:51      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:isp   display   play   UI   data   models   address   splay   model   

我的开发顺序是从Model层开始。在Model层目前一共有4个类。Model层除MvcBbsContext引用了System.componentModel 与 System.ComponentModel.DataAnnotations,在MvcBbsContext类中引用了System.Data.Entity

1.User

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace MvcBBSApplication.Models
{
public class User
{
[Key]
public int Id { get; set; }

[DisplayName("UserName")]
[Required(ErrorMessage = "Please enter the Email")]
[DataType(DataType.EmailAddress, ErrorMessage = "Please enter the correct format")]
public string Email { get; set; }

[DisplayName("NickName")]
[Required(ErrorMessage = "Please enter the NickName")]
[MaxLength(10, ErrorMessage = "MaxLength 20 words")]
public string NickName { get; set; }

[DisplayName("Password")]
[Required(ErrorMessage = "Please enter the Password")]
[MaxLength(10, ErrorMessage = "MaxLength 10 words")]
[DataType(DataType.Password)]
public string Password { get; set; }

[DisplayName("CreatOn")]
[Required]
public DateTime CreatOn { get; set; }
}
}

-------------------------------------------------------------

2.Message

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MvcBBSApplication.Models
{
public class Message
{
[Key]
public int Id { get; set; }

[DisplayName("Title")]
[Required(ErrorMessage = "Please enter the Title")]
[MaxLength(50, ErrorMessage = "MaxLength 50 words")]
public string Title { get; set; }

[DisplayName("UserName")]
public User User { get; set; }

[DisplayName("Content")]
[DataType(DataType.MultilineText)]
public string content { get; set; }

[DisplayName("CreatOn")]
[Required]
public DateTime CreatOn { get; set; }

[DisplayName("IpAddress")]
[Required]
public string Ip { get; set; }
}
}

----------------------------------------------

3.Reply

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MvcBBSApplication.Models
{
public class Reply
{
[Key]
public int Id { get; set; }

[DisplayName("Title")]
public Message Message { get; set; }

[DisplayName("UserName")]
public User User { get; set; }

[DisplayName("Content")]
[Required(ErrorMessage="Please enter content")]
[DataType(DataType.MultilineText)]
public string Content { get; set; }

[DisplayName("CreatOn")]
[Required]
public DateTime CreatOn { get; set; }

[DisplayName("IpAddress")]
[Required]
public string Ip { get; set; }
}
}

------------------------------------------------

4.MvcBbsContext

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MvcBBSApplication.Models
{
public class MvcBbsContext:DbContext
{
public MvcBbsContext()
: base("name=DefaultConnection")
{
}

public DbSet<User> Users { get; set; }
public DbSet<Message> Messages { get; set; }
public DbSet<Reply> Replys { get; set; }
}
}

简易留言薄系统-ASP.NET MVC(Model层)

标签:isp   display   play   UI   data   models   address   splay   model   

原文地址:http://www.cnblogs.com/Weimin496/p/7395310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!