Skip to content

Commit

Permalink
Merge pull request #83 from HeinHtetAung-Dev/main
Browse files Browse the repository at this point in the history
Added GetClientByUser
  • Loading branch information
HeinHtetAung-Dev authored Sep 23, 2024
2 parents a4b01b8 + 6920f4a commit 71914ea
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions REMS.BackendApi/Features/Client/ClientController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public async Task<IActionResult> GetClientById(int id)
}
}

[HttpGet("Users/{id}")]
public async Task<IActionResult> GetClientByUserId(int id)
{
var agentList = await _blClient.GetClientByUserId(id);

return Ok(agentList);
}


[HttpPost]
public async Task<IActionResult> PostClient(ClientRequestModel requestModel)
{
Expand Down
5 changes: 5 additions & 0 deletions REMS.Modules/Features/Client/BL_Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public async Task<Result<ClientModel>> GetClientById(int id)
var responseModel = await _daClient.GetClientById(id);
return responseModel;
}
public async Task<Result<ClientModel>> GetClientByUserId(int id)
{
var responseModel = await _daClient.GetClientByUserId(id);
return responseModel;
}

public async Task<Result<ClientModel>> CreateClient(ClientRequestModel requestModel)
{
Expand Down
26 changes: 26 additions & 0 deletions REMS.Modules/Features/Client/DA_Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@ public async Task<Result<ClientModel>> GetClientById(int id)
return model;
}

public async Task<Result<ClientModel>> GetClientByUserId(int userId)
{
Result<ClientModel> model = null;
try
{
var client = await _db
.Clients
.Include(c => c.User) // Include the User entity
.AsNoTracking()
.FirstOrDefaultAsync(x => x.UserId == userId);

if (client is null) return model = Result<ClientModel>.Error("Client not found.");

var responseModel = client.Change(client.User);

model = Result<ClientModel>.Success(responseModel);
}
catch (Exception ex)
{
model = Result<ClientModel>.Error(ex);
}

return model;
}


public async Task<Result<ClientModel>> CreateClient(ClientRequestModel requestModel)
{
Result<ClientModel> model = null;
Expand Down

0 comments on commit 71914ea

Please sign in to comment.