Skip to content

Commit

Permalink
Merge pull request #81 from HeinHtetAung-Dev/main
Browse files Browse the repository at this point in the history
Changes standard format and username is agentname , agencyname is Agent.AgencyName
  • Loading branch information
HeinHtetAung-Dev authored Sep 16, 2024
2 parents ddaa529 + 1fe0ac7 commit 868d8e2
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 89 deletions.
32 changes: 20 additions & 12 deletions REMS.BackendApi/Features/Agent/AgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public async Task<IActionResult> PostAgent(AgentRequestModel requestModel)
}

[HttpDelete("{id}")]
public async Task<IActionResult> DeleteAgent(int userId)
public async Task<IActionResult> DeleteAgent(int id)
{
try
{
var response = await _blAgent.DeleteAgentAsync(userId);
var response = await _blAgent.DeleteAgentAsync(id);
if (response.IsError) return BadRequest(response);
return Ok(response);
}
Expand All @@ -42,11 +42,11 @@ public async Task<IActionResult> DeleteAgent(int userId)
}

[HttpPatch("{id}")]
public async Task<IActionResult> UpdateAgent(int userId, AgentRequestModel requestModel)
public async Task<IActionResult> UpdateAgent(int id, AgentRequestModel requestModel)
{
try
{
var response = await _blAgent.UpdateAgentAsync(userId, requestModel);
var response = await _blAgent.UpdateAgentAsync(id, requestModel);
if (response.IsError) return BadRequest(response);
return Ok(response);
}
Expand All @@ -56,26 +56,34 @@ public async Task<IActionResult> UpdateAgent(int userId, AgentRequestModel reque
}
}

[HttpGet("{id}", Name = "SearchUser")]
public async Task<IActionResult> SearchUser(int id)
[HttpGet("Users/{id}")]
public async Task<IActionResult> SearchAgentByUserId(int id)
{
var agentList = await _blAgent.SearchAgentAsync(id);

return Ok(agentList);
}

[HttpGet("{name}/{pageNo}/{pageSize}", Name = "SearchUserByName")]
public async Task<IActionResult> SearchUserByName(string name, int pageNumber, int pageSize)
[HttpGet("{id}")]
public async Task<IActionResult> SearchAgentById(int id)
{
var agentList = await _blAgent.SearchAgentByNameAsync(name, pageNumber, pageSize);
var agentList = await _blAgent.SearchAgentById(id);

return Ok(agentList);
}

[HttpPost("location", Name = "SearchAgentByNameAndLocation")]
public async Task<IActionResult> SearchAgentByNameAndLocation(SearchAgentRequestModel _searchAgentReqeustModel)
[HttpGet("GetAgent")]
public async Task<IActionResult> SearchUserByName(string agencyName, int pageNo = 1, int pageSize = 10)
{
var agentList = await _blAgent.SearchAgentByNameAndLocationAsync(_searchAgentReqeustModel);
var agentList = await _blAgent.SearchAgentByNameAsync(agencyName, pageNo, pageSize);

return Ok(agentList);
}

[HttpGet("agencyName/Location")]
public async Task<IActionResult> SearchAgentByNameAndLocation(string? agencyName, string? location, int pageNo = 1, int pageSize = 10)
{
var agentList = await _blAgent.SearchAgentByNameAndLocation(agencyName, location, pageNo, pageSize);

return Ok(agentList);
}
Expand Down
7 changes: 4 additions & 3 deletions REMS.Mapper/ChangeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static User ChangeUser(this AgentRequestModel requestModel)
{
var user = new User
{
Name = requestModel.UserName!,
Name = requestModel.AgentName,
Email = requestModel.Email!,
Password = requestModel.Password!,
Phone = requestModel.Phone,
Expand All @@ -71,7 +71,7 @@ public static Agent ChangeAgent(this AgentRequestModel requestModel)
var agent = new Agent
{
UserId = requestModel.UserId,
AgencyName = requestModel.AgentName!,
AgencyName = requestModel.AgencyName,
LicenseNumber = requestModel.LicenseNumber!,
Address = requestModel.Address!
};
Expand All @@ -85,9 +85,10 @@ public static AgentDto ChangeAgent(this Agent agent, User user)
AgentId = agent.AgentId,
UserId = agent.UserId,
AgencyName = agent.AgencyName,
AgentName = user.Name,
LicenseNumber = agent.LicenseNumber,
Email = user.Email,
PhoneNumber = user.Phone,
Phone = user.Phone,
Address = agent.Address
};
}
Expand Down
2 changes: 1 addition & 1 deletion REMS.Models/Agent/AgentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AgentDto

public string? Email { get; set; }

public string? PhoneNumber { get; set; }
public string? Phone { get; set; }

public string? Address { get; set; }

Expand Down
9 changes: 4 additions & 5 deletions REMS.Models/Agent/AgentListResponseModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace REMS.Models.Agent;
using REMS.Models.Custom;

namespace REMS.Models.Agent;

public class AgentListResponseModel
{
public int PageSize { get; set; }
public int PageNumber { get; set; }
public int PageCount { get; set; }
public bool IsEndOfPages => PageNumber >= PageCount;
public List<AgentDto> AgentList { get; set; } = new();
public PageSettingModel? pageSetting { get; set; }
}
4 changes: 2 additions & 2 deletions REMS.Models/Agent/AgentRequestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public class AgentRequestModel
{
public int UserId { get; set; }

public string? AgentName { get; set; }
public string? AgencyName { get; set; }

public string? UserName { get; set; }
public string? AgentName { get; set; }

public string? LicenseNumber { get; set; }

Expand Down
30 changes: 14 additions & 16 deletions REMS.Modules/Features/Agent/BL_Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,30 @@ public async Task<Result<object>> DeleteAgentAsync(int id)
return response;
}

public async Task<Result<AgentDto>> SearchAgentAsync(int id)
public async Task<Result<AgentDto>> SearchAgentAsync(int AgentId)
{
return await _daAgent.SearchAgentByUserIdAsync(id);
return await _daAgent.SearchAgentByUserIdAsync(AgentId);
}

public async Task<Result<AgentDto>> SearchAgentById(int AgentId)
{
return await _daAgent.SearchAgentById(AgentId);
}

public async Task<Result<AgentListResponseModel>> SearchAgentByNameAsync(string name, int pageNumber, int pageSize)
public async Task<Result<AgentListResponseModel>> SearchAgentByNameAsync(string name, int pageNo,
int pageSize)
{
if (pageNumber < 1 || pageSize < 1)
if (pageNo < 1 || pageSize < 1)
return Result<AgentListResponseModel>.Error("Page Number or Page Size Can't be less than 1");
return await _daAgent.SearchAgentByNameAsync(name, pageNumber, pageSize);
return await _daAgent.SearchAgentByNameAsync(name, pageNo, pageSize);
}

public async Task<Result<AgentListResponseModel>> SearchAgentByNameAndLocationAsync(
SearchAgentRequestModel _searchAgent)
public async Task<Result<AgentListResponseModel>> SearchAgentByNameAndLocation(string agencyName, string location,
int pageNo, int pageSize)
{
Result<AgentListResponseModel> model = null;
if (_searchAgent.PageNumber < 1 || _searchAgent.PageSize < 1)
model = Result<AgentListResponseModel>.Error("Page Number or Page Size Can't be less than 1");
if (!string.IsNullOrEmpty(_searchAgent.Address))
model =
await _daAgent.SearchAgentByNameAndLocationAsync(_searchAgent.AgentName ?? "", _searchAgent.Address,
_searchAgent.PageNumber, _searchAgent.PageSize);
else
model = await _daAgent.SearchAgentByNameAsync(_searchAgent.AgentName ?? "", _searchAgent.PageNumber,
_searchAgent.PageSize);
model = await _daAgent.SearchAgentByNameAndLocation(agencyName, location, pageNo,
pageSize);
return model;
}

Expand Down
Loading

0 comments on commit 868d8e2

Please sign in to comment.