MvcAppEmployeesFromDb.DataAccessLayer
来源:互联网 发布:恺英网络招聘 编辑:程序博客网 时间:2024/05/17 18:00
insert into TblEmployee values('johnson','fernandes',14000);
insert into TblEmployee values('michael','jackson',16000);
insert into TblEmployee values('robert','pattinson',20000);
<connectionStrings>
<add connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SalesERPDB;Integrated Security=True"
name="SalesERPDAL"
providerName="System.Data.SqlClient"/>
</connectionStrings>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using MvcAppEmployeesFromDb.Models;
namespace MvcAppEmployeesFromDb.DataAccessLayer
{
public class SalesERPDAL : DbContext
{
public DbSet<Employee> Employees { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Employee>().ToTable("TblEmployee");
base.OnModelCreating(modelBuilder);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcAppEmployeesFromDb.DataAccessLayer;
namespace MvcAppEmployeesFromDb.Models
{
public class EmployeeListViewModel
{
public List<Employee> Employees
{
get
{
SalesERPDAL salesDal = new SalesERPDAL();
return salesDal.Employees.ToList();
}
}
public string UserName { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace MvcAppEmployeesFromDb.Models
{
public class Employee
{
[Key]
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Salary { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcAppEmployeesFromDb.Models;
namespace MvcAppEmployeesFromDb.Controllers
{
public class TestController : Controller
{
//
// GET: /Test/
public ActionResult Index()
{
return View();
}
public ActionResult GetEmployeeListView()
{
EmployeeListViewModel employeeListViewModel = new EmployeeListViewModel();
employeeListViewModel.UserName = "Sky";
return View("EmployeeListView", employeeListViewModel);
}
}
}
@using MvcAppEmployeesFromDb.Models
@model EmployeeListViewModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>EmployeeListView</title>
</head>
<body>
Hello @Model.UserName
<hr />
<div>
<table>
<tr>
<th>Employee Name</th>
<th>Salary</th>
</tr>
@foreach (Employee item in Model.Employees)
{
<tr>
<td>@item.FirstName @item.LastName</td>
@if(item.Salary>15000)
{
<td style="background-color:yellow">
Employee Salary: @item.Salary.ToString("C")
</td>
}
else
{
<td style="background-color:green">
Employee Salary: @item.Salary.ToString("C")
</td>
}
</tr>
}
</table>
</div>
</body>
</html>
- MvcAppEmployeesFromDb.DataAccessLayer
- DataAccessLayer
- 论坛App_Code DataAccessLayer(1)
- wifidog 源码初分析-1-转
- call和apply及bind应用
- [Widget]ReplaceLayout-交替布局
- AD10 BOM制作
- android逆向3
- MvcAppEmployeesFromDb.DataAccessLayer
- stringbuffer与stringbuilder的区别
- 机试题:过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串。
- android逆向4
- 寻找左兄弟节点
- 支付宝:批量付款到支付宝账户有密接口
- IOS 解决iOS打印nsdictionary和nsarray是编码的问题
- 用axure给按钮图片等添加点击事件跳转页面
- 【C#学习之路】练手小项目之——文件加密机