// 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)); }
public async Task <IActionResult> Delete([FromQuery] string id) { var user = await _applicationUserRepository.FindById(id); if (user == default) { return(NotFound()); } //var tmp = await _userManager.UpdateSecurityStampAsync(user); await _applicationUserRepository.Delete(user); return(Ok()); }
public async Task <IActionResult> Post([FromBody] EmployeeModel model) { var user = await _applicationUserRepository.FindById(model.ID.ToString()); List <Task> tasks = new List <Task>(); if (user == default) { return(NotFound()); } user.Email = model.Email; user.PhoneNumber = model.PhoneNumber; user.FirstName = model.FirstName; user.LastName = model.LastName; user.AddressLine = model.AddressLine; user.PostalCode = model.PostalCode; user.Town = model.Town; tasks.Add(_applicationUserRepository.Update(user)); var listOfCurrentRoles = await _applicationUserRepository.GetRoles(user); var listOfNewRoles = model.Roles; foreach (var item in FindDifferences(listOfNewRoles, listOfCurrentRoles)) { tasks.Add(_applicationUserRepository.AddToRole(user, item)); } foreach (var item in FindDifferences(listOfCurrentRoles, listOfNewRoles)) { tasks.Add(_applicationUserRepository.RemoveFromRole(user, item)); } await Task.WhenAll(tasks); return(Ok()); }
public async Task <ApplicationUser> FindByIdAsync(string userId, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); return(await userRepository.FindById(userId)); }
public List <Quiz> GetSended(string userId) { return(_userRepository.FindById(userId).SendedQuizes.ToList()); }