public async Task <IActionResult> Get([FromHeader] string sender, int id, int?agencyId, int?warehouseId) { try { if (sender == null) { return(Unauthorized()); } object other = null; Employee user = JsonConvert.DeserializeObject <Employee>(sender); if (agencyId != null) { if (user.IsAdmin() || user.AgencyId == agencyId.Value) { other = await otherServ.GetInAgency(id, agencyId.Value); } else { return(Unauthorized()); } } else if (warehouseId != null) { if (user.IsAdmin() || user.WarehouseId == warehouseId.Value) { other = await otherServ.GetInWarehouse(id, warehouseId.Value); } else { return(Unauthorized()); } } else { if (user.IsAdmin()) { other = await otherServ.Get(id); } else { return(Unauthorized()); } } if (other == null) { return(NotFound()); } else { return(Ok(other)); } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); return(StatusCode(500)); } }