private void updateEmpTbl() { int v = (int)Cache["table"]; Feb1AssignmentEntities fae = new Feb1AssignmentEntities(); if (v == -1) { employeetbl.DataSource = fae.spGetAllEmps(-1).ToList(); } else { try { //sort by dept if (v == 0) { employeetbl.DataSource = (from Emp in fae.Employees join Dep in fae.Departments on Emp.DeptId equals Dep.DeptID orderby Dep.DeptName ascending select new { EmployeeName = Emp.EmpName, Salary = Emp.EmpSalary, Department = Dep.DeptName }).ToList(); } //toupper else if (v == 1) { employeetbl.DataSource = (from Emp in fae.Employees join Dep in fae.Departments on Emp.DeptId equals Dep.DeptID select new { EmployeeName = Emp.EmpName.ToUpper(), Salary = Emp.EmpSalary, Department = Dep.DeptName }).ToList(); } else { var maxSalary = (from Emp in fae.Employees select Emp).Max(x => x.EmpSalary); employeetbl.DataSource = (from Emp in fae.Employees select Emp).Where(x => x.EmpSalary == maxSalary).ToList(); } } catch (Exception ex) { throw new Exception("Error occured while retrieving Route Info - " + ex.Message.ToString()); } } employeetbl.DataBind(); }
protected void addNewItems(object sender, EventArgs e) { Feb1AssignmentEntities fae = new Feb1AssignmentEntities(); Department dep = new Department(); dep.DeptName = RandomString(50); fae.Departments.Add(dep); Employee emp1 = new Employee(), emp2 = new Employee(); emp1.DeptId = fae.Departments.ToList()[fae.Departments.Count() - 1].DeptID; emp2.DeptId = fae.Departments.ToList()[fae.Departments.Count() - 1].DeptID; emp1.EmpName = RandomString(50); emp2.EmpName = RandomString(50); emp1.EmpSalary = random.Next(200000); emp2.EmpSalary = random.Next(200000); fae.Employees.Add(emp1); fae.Employees.Add(emp2); fae.SaveChanges(); updateEmpTbl(); }