Esempio n. 1
0
        public ActionResult List()
        {
            //construct VM using Linq

            /*
             * IEnumerable<EmplListVM> model = from e in EmplRepoStub.ReadAllEmployees()
             *  join d in DeptRepoStub.ReadAllDepartments()
             *      on e.DepartmentId equals d.Id
             *  select new EmplListVM
             *  {
             *      Name = e.FirstName + " " + e.LastName,
             *      DeptName = d.Name,
             *      PhoneNum = e.PhoneNum,
             *      EmplId = e.Id
             *  };
             */

            //method syntax equivalent
            IEnumerable <EmplListVM> model = EmplRepoStub.ReadAllEmployees()
                                             .Join(
                DeptRepoStub.ReadAllDepartments(),
                empl => empl.DepartmentId,
                dept => dept.Id,
                (empl, dept) => new EmplListVM
            {
                Name     = empl.FirstName + " " + empl.LastName,
                DeptName = dept.Name,
                PhoneNum = empl.PhoneNum,
                EmplId   = empl.Id
            }
                );

            return(View(model));
        }
Esempio n. 2
0
 /*HELPERS*/
 /// <summary>
 /// Load Departments for drop down selects
 /// </summary>
 /// <returns>List of SelectListItem's for Views</returns>
 private static List <SelectListItem> GetDepartmentsSelectListItems()
 {
     return(DeptRepoStub.ReadAllDepartments()
            .Select(
                d => new SelectListItem
     {
         Text = d.Name,
         Value = d.Id.ToString()
     }
                )
            .ToList());
 }