public MainWindow() { UiCtx = SynchronizationContext.Current; InitializeComponent(); this.KeyDown += OnKeyPress; Vm = new PFViewModel(ItemsPanel, ZoomViewbox); DataContext = Vm; }
private void Reset() { Vm = new PFViewModel(ItemsPanel, ZoomViewbox); DataContext = Vm; }
public ActionResult Index(string search, string previousSortOrder, string previousSortTerm, string CurrentSortTerm, int?page, bool PFView = false, bool gratuityView = false, bool insuranceView = false, bool deletedEmployeesView = false, bool salaryView = false, bool fullTimeactive = false, bool fullTimeTotal = false, bool vhwactive = false, bool vhwTotal = false, bool fullTimemaleactive = false, bool fullTimemaletotal = false, bool fullTimefemaleactive = false, bool fullTimefemaletotal = false) { ViewBag.Search = search; ViewBag.PFView = PFView; previousSortTerm = String.IsNullOrEmpty(previousSortTerm) ? "Name" : previousSortTerm; IQueryable <Employee> searchedEmployees = Enumerable.Empty <Employee>().AsQueryable(); if (fullTimeactive) { searchedEmployees = db.Employees.Where(employee => employee.IsActive == true && employee.VHW == "No"); } else if (fullTimeTotal) { searchedEmployees = db.Employees.Where(employee => employee.VHW == "No"); } else if (vhwactive) { searchedEmployees = db.Employees.Where(employee => employee.IsActive == true && employee.VHW == "Yes"); } else if (vhwTotal) { searchedEmployees = db.Employees.Where(employee => employee.VHW == "Yes"); } else if (fullTimemaleactive) { searchedEmployees = db.Employees.Where(employee => employee.IsActive == true && employee.VHW == "No" && employee.Gender == "Male"); } else if (fullTimemaletotal) { searchedEmployees = db.Employees.Where(employee => employee.VHW == "No" && employee.Gender == "Male"); } else if (fullTimefemaleactive) { searchedEmployees = db.Employees.Where(employee => employee.VHW == "No" && employee.Gender == "Female" && employee.IsActive == true); } else if (fullTimefemaletotal) { searchedEmployees = db.Employees.Where(employee => employee.VHW == "No" && employee.Gender == "Female"); } if (PFView) { DateTime testLessThanDate = DateTime.Now.Add(new TimeSpan(30, 0, 0, 0)); searchedEmployees = searchedEmployees.Where(e => e.PFStartDate <= testLessThanDate && e.PFStatus == false); } if (gratuityView) { DateTime testLessThanDate = DateTime.Now.Add(new TimeSpan(120, 0, 0, 0)); searchedEmployees = searchedEmployees.Where(e => e.GratuityStartDate <= testLessThanDate && e.GratuityStatus == false); var emps = searchedEmployees.ToList(); } if (insuranceView) { DateTime testLessThanDate = DateTime.Now.Add(new TimeSpan(30, 0, 0, 0)); searchedEmployees = searchedEmployees.Where(e => e.InsuranceRenewalDate == null || e.InsuranceExpiryDate <= testLessThanDate); } if (deletedEmployeesView) { searchedEmployees = db.Employees.Where(e => e.IsActive == false); } if (!String.IsNullOrEmpty(search)) { searchedEmployees = searchedEmployees.Where(e => e.FirstName.StartsWith(search) || e.LastName.StartsWith(search)); } IEnumerable <Employee> sortedmployees = null; string currentSortOrder = string.Empty; switch (CurrentSortTerm) { case "FirstName": if (previousSortTerm.Equals(CurrentSortTerm)) { if (previousSortOrder == "ascending") { sortedmployees = searchedEmployees.OrderByDescending (m => m.FirstName); currentSortOrder = "descending"; } else { sortedmployees = searchedEmployees.OrderBy (m => m.FirstName); currentSortOrder = "ascending"; } } else { sortedmployees = searchedEmployees.OrderBy (m => m.FirstName); currentSortOrder = "ascending"; } break; case "Id": CurrentSortTerm = "Id"; if (previousSortTerm.Equals(CurrentSortTerm)) { if (previousSortOrder == "ascending") { sortedmployees = searchedEmployees.OrderByDescending (m => m.Id); currentSortOrder = "descending"; } else { sortedmployees = searchedEmployees.OrderBy (m => m.Id); currentSortOrder = "ascending"; } } else { sortedmployees = searchedEmployees.OrderBy (m => m.Id); currentSortOrder = "ascending"; } break; case "LastName": CurrentSortTerm = "LastName"; if (previousSortTerm.Equals(CurrentSortTerm)) { if (previousSortOrder == "ascending") { sortedmployees = searchedEmployees.OrderByDescending (m => m.LastName); currentSortOrder = "descending"; } else { sortedmployees = searchedEmployees.OrderBy (m => m.LastName); currentSortOrder = "ascending"; } } else { sortedmployees = searchedEmployees.OrderBy (m => m.LastName); currentSortOrder = "ascending"; } break; case "Gender": CurrentSortTerm = "Gender"; if (previousSortTerm.Equals(CurrentSortTerm)) { if (previousSortOrder == "ascending") { sortedmployees = searchedEmployees.OrderByDescending (m => m.Gender); currentSortOrder = "descending"; } else { sortedmployees = searchedEmployees.OrderBy (m => m.Gender); currentSortOrder = "ascending"; } } else { sortedmployees = searchedEmployees.OrderBy (m => m.Gender); currentSortOrder = "ascending"; } break; case "DepartmentId": CurrentSortTerm = "DepartmentId"; if (previousSortTerm.Equals(CurrentSortTerm)) { if (previousSortOrder == "ascending") { sortedmployees = searchedEmployees.OrderByDescending (m => m.DepartmentId); currentSortOrder = "descending"; } else { sortedmployees = searchedEmployees.OrderBy (m => m.DepartmentId); currentSortOrder = "ascending"; } } else { sortedmployees = searchedEmployees.OrderBy (m => m.DepartmentId); currentSortOrder = "ascending"; } break; default: currentSortOrder = "ascending"; sortedmployees = searchedEmployees.OrderBy (m => m.FirstName); CurrentSortTerm = "FirstName"; break; } ViewBag.PreviousSortOrder = currentSortOrder; ViewBag.PreviousSortTerm = CurrentSortTerm; if (PFView) { var user = System.Web.HttpContext.Current.User; var pfViewModel = new PFViewModel(); if (user.Identity.IsAuthenticated) { if (user.IsInRole("Accounts")) { pfViewModel.IsAccountsLogin = true; } if (user.IsInRole("Admin")) { pfViewModel.IsAdminLogin = true; } } List <PFViewModel> newList = sortedmployees.Select(x => new PFViewModel { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, DepartmentName = x.Department.Name, DateOfJoining = x.DateOfJoining, Gender = x.Gender, PFStatus = x.PFStatus, PFStartDate = x.PFStartDate, ProbationPeriod = x.ProbationPeriod }).ToList(); newList[0].IsAdminLogin = pfViewModel.IsAdminLogin; newList[0].IsAccountsLogin = pfViewModel.IsAccountsLogin; return(View("PFView", newList.ToList())); } if (gratuityView) { var user = System.Web.HttpContext.Current.User; var pfViewModel = new PFViewModel(); if (user.Identity.IsAuthenticated) { if (user.IsInRole("Accounts")) { pfViewModel.IsAccountsLogin = true; } if (user.IsInRole("Admin")) { pfViewModel.IsAdminLogin = true; } } List <GratuityViewModel> newList = sortedmployees.Select(x => new GratuityViewModel { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, DepartmentName = x.Department.Name, DateOfJoining = x.DateOfJoining, Gender = x.Gender, GratuityStatus = x.GratuityStatus }).ToList(); newList[0].IsAdminLogin = pfViewModel.IsAdminLogin; newList[0].IsAccountsLogin = pfViewModel.IsAccountsLogin; return(View("GratuityView", newList.ToList())); } if (insuranceView) { return(View("InsuranceView", sortedmployees.ToList())); } if (deletedEmployeesView) { return(View("DeletedEmployeesView", sortedmployees.ToList())); } if (salaryView) { return(View("SalaryView", sortedmployees.ToList())); } return(View(sortedmployees)); }