public class Employee { public int EmployeeId { get; set; } [Display(Name = "Employee Code")] public string EmployeeCode { get; set; } public virtual List<EmployeeDesignation> EmployeeDesignationList { get; set; } public virtual List<EmployeeSalary> EmployeeSalaryList { get; set; } public virtual List<EmployeePay> PayList { get; set; } } public class EmployeeDesignation { public int EmployeeDesignationId { get; set; } public int EmployeeId { get; set; } public Employee AnEmploye { get; set; } public int DesignationId { get; set; } public virtual List< Designation > DesignationObj { get; set; } public DateTime StartDate { get; set; } public DateTime EndtDate { get; set; } } public class Designation { public int DesignationId { get; set; } public string DesignationName { get; set; } } public class EmployeeSalary { public int EmployeeSalaryId { get; set; } public double BasicSalary { get; set; } public double MedicalAnnouncement { get; set; } public double HouseRent { get; set; } public int EmployeeId { get; set; } public virtual Employee AnEmployee { get; set; } public DateTime StartDate { get; set; } public DateTime EndtDate { get; set; } }
public class EmployeeViewModel { public List<Employee> Employees { get; set; } public List<EmployeeDesignation> Designations { get; set; } public List<Designation> DesignationObj { get; set; } public List<EmployeeSalary> Salaries { get; set; } }
public ActionResult EmpReport() { var employees = (from employee in db.Employees select employee).ToList(); var salaries = (from salary in db.Salaries select salary).ToList(); var employeeViewModel = new EmployeeViewModel(); employeeViewModel.Employees = employees; employeeViewModel.Designations = db.EmployeeDesignations.Include(x => x.DesignationObj).ToList(); employeeViewModel.Salaries = db.Salaries.ToList(); return View(employeeViewModel); }
@model EmployeeManagementSystem.ViewModel.EmployeeViewModel @{ ViewBag.Title = "EmpReport"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>EmpReport</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table> <tr> <th> @Html.DisplayNameFor(model => model.EmployeeCode) </th> <th> @Html.DisplayNameFor(model => model.EmployeeName) </th> <th> @Html.DisplayNameFor(model => model.Email) </th> <th> @Html.DisplayNameFor(model => model.ContactNo) </th> <th> @Html.DisplayNameFor(model => model.DesignationName) </th> @* <th> @Html.DisplayNameFor(model => model.BasicSalary) </th> <th> @Html.DisplayNameFor(model => model.MedicalAnnouncement) </th> <th> @Html.DisplayNameFor(model => model.HouseRent) </th>*@ <th></th> </tr> @foreach (var item in Model.Employees) { <tr> <td> @Html.DisplayFor(modelItem => item.EmployeeCode) </td> <td> @Html.DisplayFor(modelItem => item.EmployeeName) </td> <td> @Html.DisplayFor(modelItem => item.Email) </td> <td> @Html.DisplayFor(modelItem => item.ContactNo) </td> <td> @Html.DisplayFor(modelItem => item.EmployeeDesignationList) </td> <td> @Html.DisplayFor(modelItem => item.BasicSalary) </td> <td> @Html.DisplayFor(modelItem => item.MedicalAnnouncement) </td> <td> @Html.DisplayFor(modelItem => item.HouseRent) </td> </tr> } @foreach (var item in Model.Designations) { <tr> <td> @Html.DisplayFor(modelItem => item.DesignationObj.DesignationName) </td> </tr> } </table>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)