// Gets all the departments that matches the existing departmentId public List <DepartmentViewModel> GetAll() { List <DepartmentViewModel> allVms = new List <DepartmentViewModel>(); try { // Get the Departments List <Departments> allDepts = _model.GetAll(); // For each elements in allDepts, add them to alllVms foreach (Departments dept in allDepts) { DepartmentViewModel vm = new DepartmentViewModel(); vm.Id = dept.Id; vm.DepartmentName = dept.DepartmentName; allVms.Add(vm); } } catch (Exception ex) { Console.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); throw ex; } // try/catch return(allVms); }
// GetAll() function of the DepartmentViewModel class public List <DepartmentViewModel> GetAll() { // List to hold all the DepartmentViewModel objects List <DepartmentViewModel> allVms = new List <DepartmentViewModel>(); try { // List to hold all the departments in the database List <Department> allDepartments = _model.GetAll(); // For each department in the database it will create a DepartmentViewModel // object to store the Department Name, Id and a Timer for concurrency issues // then adds the DepartmentViewModel object to the List foreach (Department dep in allDepartments) { DepartmentViewModel depVm = new DepartmentViewModel(); depVm.Name = dep.DepartmentName; depVm.Id = dep.Id; depVm.Timer = Convert.ToBase64String(dep.Timer); allVms.Add(depVm); } } catch (Exception ex) { Console.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); throw ex; } // Return the List of DepartmentViewModel objects return(allVms); }
public List <DepartmentViewModel> GetAll() { List <DepartmentViewModel> allVms = new List <DepartmentViewModel>(); try { List <Department> allDepartments = _model.GetAll(); foreach (Department dept in allDepartments) { DepartmentViewModel deptVm = new DepartmentViewModel(); deptVm.Id = dept.Id; deptVm.Name = dept.DepartmentName; deptVm.Timer = Convert.ToBase64String(dept.Timer); allVms.Add(deptVm); } } catch (Exception ex) { Console.WriteLine("Problem in " + GetType().Name + " " + MethodBase.GetCurrentMethod().Name + " " + ex.Message); throw ex; } return(allVms); }