public async Task <ActionResult <List <AuditDto> > > ViewRoleHistory(Guid sheriffId) { var sheriff = await SheriffService.GetSheriff(sheriffId, null); if (sheriff == null) { return(NotFound(CouldNotFindSheriffError)); } if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, sheriff.HomeLocationId)) { return(Forbid()); } var userRoleIds = Db.UserRole.AsNoTracking().Where(ur => ur.UserId == sheriffId).Select(ur => ur.Id); var roleHistory = Db.Audit.AsNoTracking().Include(a => a.CreatedBy).Where(e => e.TableName == "UserRole" && userRoleIds.Contains(e.KeyValues.RootElement.GetProperty("Id") .GetInt32())) .ToList(); //Have to select, because we have adapt ignore on these properties. return(Ok(roleHistory.Select(s => { var audit = s.Adapt <AuditDto>(); audit.CreatedBy = s.CreatedBy.Adapt <SheriffDto>(); audit.CreatedOn = s.CreatedOn; audit.CreatedById = s.CreatedById; return audit; }))); }
public async Task <ActionResult> FindSheriff(Guid id) { var sheriff = await _service.GetSheriff(id); if (sheriff == null) { return(NotFound($"Couldn't find sheriff with id: {id}")); } return(Ok(sheriff.Adapt <SheriffDto>())); }
private async Task CheckForAccessToSheriffByLocation(Guid?id, string badgeNumber = null) { var savedSheriff = await SheriffService.GetSheriff(id, badgeNumber); if (savedSheriff == null) { throw new NotFoundException(CouldNotFindSheriffError); } if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, savedSheriff.HomeLocationId)) { throw new NotAuthorizedException(); } }
private async Task CheckForAccessToSheriffByLocation <T>(int id) where T : SheriffEvent { var sheriffEvent = await SheriffService.GetSheriffEvent <T>(id); if (sheriffEvent == null) { throw new NotFoundException(CouldNotFindSheriffEventError); } var savedSheriff = await SheriffService.GetSheriff(sheriffEvent.SheriffId, null); if (savedSheriff == null) { throw new NotFoundException(CouldNotFindSheriffError); } if (!PermissionDataFiltersExtensions.HasAccessToLocation(User, Db, savedSheriff.HomeLocationId)) { throw new NotAuthorizedException(); } }