Hi @Jaliya Udagedara ,
For return type, see the code
public class EmployeeController : Controller
{
public static List<EmployeeVM> emp = new List<EmployeeVM>();
private IDepartmentDM _departmentDM;
private IEmployeeDM _employeeDM;
public EmployeeController(IDepartmentDM departmentDM, IEmployeeDM employeeDM)
{
_departmentDM = departmentDM;
_employeeDM = employeeDM;
}
public IActionResult Index()
{
ViewBag.DataSource = _employeeDM.GetAll();
return View();
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TAFACoreMvc.Models
{
public interface IEmployeeDM
{
EmployeeVM GetAll();
}
}
This is the method
public EmployeeVM GetAll()
{
var vm = new EmployeeVM();
var dtos = svc.GetAll().ToList();
vm.Employees.AddRange(dtos.Select(dto => new EmployeeVM.Employee()
{
EmployeeId = dto.EmployeeId,
DepartmentId = dto.DepartmentId,
DepartmentName = dto.DepartmentName,
EmployeeName = dto.EmployeeName,
Designation = dto.Designation
}).ToList());
return vm;
}
The return type is List<T>