This tutorial uses the MVC development framework and the Repository mode. Unity is not used in the previous article.
As always, let's take a look at the DEMO's physical structure.
I will not describe these files one by one, and it is not hard to understand.
Let's take a look at the general operation process.
Step 1
The Logon account is HuntSoul. The password is 123456 (* ^__ ^ ......
Step 2
Here is the logon success screen. Open the "task list" and Check what tasks are available today ~ (X )~
Step 3
Return to XD and click "Open warehouse "! Look at the weapons in our warehouse XD
Step 4
Well, the general process is like this, as I said, very simple ~ Let's take a look at these simple and ugly code XD.
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Namespace UnityAndMVC2_Demo2.Models
{
Public class Entity
{
Public int ID {get; set ;}
}
}
The Entity class is used to mark objects.
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Namespace UnityAndMVC2_Demo2.Models
{
Public class Account: Entity
{
Public string AccountID {get; set ;}
Public string AccountPwd {get; set ;}
Public string LickName {get; set ;}
Public string Age {get; set ;}
Public string Email {get; set ;}
Public string Cellphone {get; set ;}
Public List <Task> Tasks {get; set ;}
Public List <StoreHouse> Stores {get; set ;}
}
}
This is our account model. It is much simpler than a traditional game account. However, based on the tutorial, we don't need to be too complicated. Just understand it, I don't think you need to explain the attributes one by one? XD should mention that the database is not used in this tutorial, so it may be difficult for DB First programmers to understand it, but this is just to give you a new perspective to try object-oriented (OO). This method seems to be the Code First in the industry, right? Or the Model First ~ That I understand ~ XD. I still need to explain the key points. The Account class has two aggregate List objects: Task and StoreHouse, which are one-to-multiple relationships. The warehouse here is a bit tangled. When I was writing a tutorial, I thought about it for a moment. If I knew what I was talking about, I would like to make a close look. Haha. If there are so many ink marks, the following Model code will not be explained one by one.
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web; namespace UnityAndMVC2_Demo2.Models
{
Public class Task: Entity
{
Public string TaskName {get; set ;}
Public string TaskContent {get; set ;}
Public string TaskStatus {get; set ;}
Public Account {get; set ;}
}
}
Using System; using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Namespace UnityAndMVC2_Demo2.Models
{
Public class StoreHouse: Entity
{
Public string GoodsName {get; set ;}
Public int GoodsNum {get; set ;}
Public float GoodsKg {get; set ;}
Public Account {get; set ;}
}
}
Okay. I just mentioned that I didn't use the database. How can I explain the data on the image? Well, you have come up with a clever idea. The DBContext is a data generation class. To put it bluntly, it is a fake database. This is necessary for testing, you don't need to care too much about me. You can simulate a DB as you like, or you can use NBuilder ~ The usage is not explained in detail. Let's take a look at DBContext.
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Namespace UnityAndMVC2_Demo2.Models
{
Public class DBContext
{
Public List <Account> Accounts {get; set ;}
Public DBContext ()
{
Accounts = new List <Account> ();
Account n_account = new Account ()
{
ID = 1,
AccountID = "HuntSoul ",
Accountpwds = "123456 ",
LickName = "soul of zookeeper ",
Age = "44 ",
Cellphone = "139 XXXXXXXXX ",
Email = "31580941X@qq.com ",
Tasks = new List <Task> ()
{
New Task ()
{
ID = 1,
TaskName = "Unity And MVC practice Demo2 ",
TaskContent = "...",
TaskStatus = "completed"
}, New Task () {ID = 2, TaskName = "Soy Sauce", TaskContent = "...", & n