public ActionResult Edit(int id) { var allowance = _countryAllowanceRepository.FindById(id).MapToView(); if (allowance == null) { return(HttpNotFound()); } return(PartialView("_CountryAllowanceForm", allowance)); }
// GET: TravelReport public ActionResult Index(int?page, string query = null) { var travelReports = new List <TravelReportVM>(); var employeeId = User.Identity.GetUserId(); if (User.IsInRole("Admin")) // admin can see personal travelReports + all closed travelReports of other employees { var allTravelReports = _travelReportRepository.GetAllFromDatabaseEnumerable().ToList().MapToViews(); foreach (var report in allTravelReports) { if (report.Status == Bll.Model.Status.Closed || report.EmployeeId == employeeId) { travelReports.Add(report); } } } else // other emplyoees can only see personal travelReports { travelReports = _travelReportRepository.GetAllFromDatabaseEnumerable().Where(u => u.EmployeeId == employeeId).ToList().MapToViews(); } foreach (var report in travelReports) // get fixed values for TravelReport Index Table { report.Employee = _applicationUserRepository.FindById(report.EmployeeId).MapToView(); report.Country = _countryAllowanceRepository.FindById(report.CountryAllowanceId).MapToView(); } CheckTempDataMessages(); // paging int pageSize = 10; var pageNumber = page ?? 1; // if no page was specified in the querystring, default to the first page (1) var onePageOfTravelReports = travelReports.ToPagedList(pageNumber, pageSize); // will only contain 10 items max because of the pageSize // searching if (!string.IsNullOrEmpty(query)) { var travelReportSearched = travelReports .Where(m => m.Employee.FirstName.ToLower().Contains(query.ToLower()) || m.Employee.LastName.ToLower().Contains(query.ToLower()) || m.Country.Country.ToLower().Contains(query.ToLower())); //|| m.Departure.Equals(query)); onePageOfTravelReports = travelReportSearched.ToPagedList(pageNumber, pageSize); } ViewBag.onePageOfTravelReports = onePageOfTravelReports; return(View(onePageOfTravelReports)); }