public async Task <OwnerExtended> GetOwnerWithDetailsAsync(Guid ownerId) { try { var owner = await FindByCondition(o => o.Id.Equals(ownerId)).SingleAsync(); var ownerExtended = new OwnerExtended(owner) { Accounts = RepositoryContext.Accounts.Where(o => o.OwnerId == ownerId) }; return(ownerExtended); } catch { return(new OwnerExtended()); } }
public async Task <OwnerExtended> GetOwnerWithDetails(Guid ownerId) { var owner = await GetOwnerById(ownerId); const string sql = "SELECT * FROM [dbo].[Account] WHERE [Account].[OwnerId] = @ownerId;"; var accounts = await Query <Account>(sql, new { ownerId }); var ownerExtended = new OwnerExtended() { Id = owner.Id, Address = owner.Address, DateOfBirth = owner.DateOfBirth, Name = owner.Name, Accounts = accounts }; return(ownerExtended); }
public IActionResult GetOwnerWithDetails(Guid id) { try { OwnerExtended owner = _repository.Owner.GetOwnerWithDetails(id); if (owner.Id.Equals(Guid.Empty)) { _logger.LogError($"Owner with id: {id}, hasn't been found in db."); return(NotFound()); } else { _logger.LogInfo($"Returned owner with details for id: {id}"); return(Ok(owner)); } } catch (Exception e) { _logger.LogError($"Something went wrong inside GetOwnerWithDetails action: {e.Message}"); return(StatusCode(500, "Internal server error")); } }