Finished 'Models in ASP.NET MVC'

master
jason.zhu 2021-06-10 16:15:36 +10:00
parent 483fe19002
commit 33c8722583
4 changed files with 51 additions and 2 deletions

View File

@ -4,13 +4,17 @@ using System.Linq;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using FirstMVCDemo.Models;
namespace FirstMVCDemo.Controllers namespace FirstMVCDemo.Controllers
{ {
public class HomeController : Controller public class HomeController : Controller
{ {
// GET: Home // GET: Home
public ActionResult Index() public ActionResult Index(int id)
{ {
EmployeeBusinessLayer employeeBL = new EmployeeBusinessLayer();
Employee employee = employeeBL.GetEmployeeDetails(id);
return View(); return View();
} }
} }

View File

@ -97,6 +97,8 @@
<Compile Include="Global.asax.cs"> <Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon> <DependentUpon>Global.asax</DependentUpon>
</Compile> </Compile>
<Compile Include="Models\Employee.cs" />
<Compile Include="Models\EmployeeBusinessLayer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -112,7 +114,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />
<Folder Include="Models\" />
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace FirstMVCDemo.Models
{
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Gender { get; set; }
public decimal Salary { get; set; }
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace FirstMVCDemo.Models
{
public class EmployeeBusinessLayer
{
public Employee GetEmployeeDetails(int EmployeeId)
{
//Here we hardcoded the data
//later we will discuss how to retrieve
//the data from a database
Employee employee = new Employee()
{
EmployeeId = EmployeeId,
Name = "Pranaya",
Gender = "Male",
City = "Mumbai",
Salary = 1000,
Address = "Andheri"
};
return employee;
}
}
}