diff --git a/README.md b/README.md
index 4bcac1c..70402c4 100644
--- a/README.md
+++ b/README.md
@@ -184,4 +184,28 @@ Scaffold-DbContext "Server=.;Database=AdminPortal;User ID=sa; Password=sa@123;In
### CI
-GitHub Actions
\ No newline at end of file
+GitHub Actions
+
+https://stackoverflow.com/questions/30346907/how-to-remove-webdav-module-from-iis
+https://learn.microsoft.com/en-us/answers/questions/856808/iis-net-6-aspnetcorev2-405-method-not-allowed
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
\ No newline at end of file
diff --git a/REMS.BackendApi/Features/Agent/AgentController.cs b/REMS.BackendApi/Features/Agent/AgentController.cs
index 2a0a96f..7329ced 100644
--- a/REMS.BackendApi/Features/Agent/AgentController.cs
+++ b/REMS.BackendApi/Features/Agent/AgentController.cs
@@ -65,14 +65,6 @@ public async Task UpdateAgent(int userId, AgentRequestModel reque
}
}
- [HttpPost("LoginAgent", Name = "LoginAgent")]
- public async Task LoginAgent(AgentLoginRequestModel agentLoginInfo)
- {
- Result res = await _blAgent.LoginAgentAsync(agentLoginInfo);
-
- return Ok(res);
- }
-
[HttpGet("SearchUser/{id}", Name = "SearchUser")]
public async Task SearchUser(int id)
{
@@ -96,4 +88,12 @@ public async Task SearchAgentByNameAndLocation(SearchAgentRequest
return Ok(agentList);
}
+
+ [HttpGet("AgentAll", Name = "AgentAll")]
+ public async Task AgentAll()
+ {
+ Result> agentList = await _blAgent.AgentAll();
+
+ return Ok(agentList);
+ }
}
\ No newline at end of file
diff --git a/REMS.BackendApi/Features/Appointment/AppointmentController.cs b/REMS.BackendApi/Features/Appointment/AppointmentController.cs
index a916a9b..a67253d 100644
--- a/REMS.BackendApi/Features/Appointment/AppointmentController.cs
+++ b/REMS.BackendApi/Features/Appointment/AppointmentController.cs
@@ -46,7 +46,7 @@ public async Task DeleteAppointment(int id)
}
[HttpGet("{propertyId}/{pageNo}/{pageSize}")]
- public async Task GetAppointmentByAgentId(int propertyId, int pageNo, int pageSize)
+ public async Task GetAppointmentByPropertyIdAsync(int propertyId, int pageNo, int pageSize)
{
try
{
@@ -76,5 +76,21 @@ public async Task UpdateAppointment(int id, AppointmentRequestMod
return StatusCode(StatusCodes.Status500InternalServerError, ex);
}
}
+
+ [HttpGet("GetAppointmentByClientId/{clientId}/{pageNo}/{pageSize}", Name = "GetAppointmentByClientId")]
+ public async Task GetAppointmentByClientId(int clientId, int pageNo, int pageSize)
+ {
+ try
+ {
+ var response = await _blAppointment.GetAppointmentByClientId(clientId, pageNo, pageSize);
+ if (response.IsError)
+ return BadRequest(response);
+ return Ok(response);
+ }
+ catch (Exception ex)
+ {
+ return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
+ }
+ }
}
}
diff --git a/REMS.BackendApi/Features/Client/ClientController.cs b/REMS.BackendApi/Features/Client/ClientController.cs
index 9ddefae..391dc36 100644
--- a/REMS.BackendApi/Features/Client/ClientController.cs
+++ b/REMS.BackendApi/Features/Client/ClientController.cs
@@ -4,7 +4,7 @@ namespace REMS.BackendApi.Features.Client;
[Route("api/v1/clients")]
[ApiController]
-[Authorize(Roles = "Agent")]
+//[Authorize(Roles = "Agent")]
public class ClientController : ControllerBase
{
private readonly BL_Client _blClient;
diff --git a/REMS.BackendApi/Features/Property/PropertyController.cs b/REMS.BackendApi/Features/Property/PropertyController.cs
index 0b8fef8..d3301fb 100644
--- a/REMS.BackendApi/Features/Property/PropertyController.cs
+++ b/REMS.BackendApi/Features/Property/PropertyController.cs
@@ -1,4 +1,5 @@
-using REMS.Models.Property;
+using REMS.Models;
+using REMS.Models.Property;
namespace REMS.BackendApi.Features.Property;
@@ -14,11 +15,16 @@ public PropertyController(BL_Property blProperties)
}
[HttpGet]
- public async Task GetProperties()
+ public async Task GetProperties(string? propertyStatus = "")
{
try
{
- var response = await _blProperties.GetProperties();
+ if (!string.IsNullOrWhiteSpace(propertyStatus) && !IsValidPropertyStatus(propertyStatus))
+ {
+ return BadRequest($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
+ }
+
+ var response = await _blProperties.GetProperties(propertyStatus);
return Ok(response);
}
catch (Exception ex)
@@ -28,11 +34,16 @@ public async Task GetProperties()
}
[HttpGet("{pageNo}/{pageSize}")]
- public async Task GetProperties(int pageNo, int pageSize)
+ public async Task GetProperties(int pageNo, int pageSize, string? propertyStatus = "")
{
try
{
- var response = await _blProperties.GetProperties(pageNo, pageSize);
+ if (!string.IsNullOrWhiteSpace(propertyStatus) && !IsValidPropertyStatus(propertyStatus))
+ {
+ return BadRequest($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
+ }
+
+ var response = await _blProperties.GetProperties(pageNo, pageSize, propertyStatus);
return Ok(response);
}
catch (Exception ex)
@@ -42,13 +53,13 @@ public async Task GetProperties(int pageNo, int pageSize)
}
[HttpGet("agent/{agentId}")]
- public async Task GetPropertiesByAgentId(int agentId, [FromQuery] string propertyStatus = nameof(PropertyStatus.Approved))
+ public async Task GetPropertiesByAgentId(int agentId, [FromQuery] string propertyStatus = "")
{
try
{
- if (!Enum.TryParse(propertyStatus, out var parsedStatus) || !Enum.IsDefined(typeof(PropertyStatus), parsedStatus))
+ if (!string.IsNullOrWhiteSpace(propertyStatus) && !IsValidPropertyStatus(propertyStatus))
{
- throw new Exception($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
+ return BadRequest($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
}
var response = await _blProperties.GetPropertiesByAgentId(agentId, propertyStatus);
@@ -61,13 +72,13 @@ public async Task GetPropertiesByAgentId(int agentId, [FromQuery]
}
[HttpGet("agent/{agentId}/{pageNo}/{pageSize}")]
- public async Task GetPropertiesByAgentId(int agentId, int pageNo, int pageSize, [FromQuery] string propertyStatus = nameof(PropertyStatus.Approved))
+ public async Task GetPropertiesByAgentId(int agentId, int pageNo, int pageSize, [FromQuery] string propertyStatus = "")
{
try
{
- if (!Enum.TryParse(propertyStatus, out var parsedStatus) || !Enum.IsDefined(typeof(PropertyStatus), parsedStatus))
+ if (!string.IsNullOrWhiteSpace(propertyStatus) && !IsValidPropertyStatus(propertyStatus))
{
- throw new Exception($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
+ return BadRequest($"Invalid Status; Status should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyStatus)))}");
}
var response = await _blProperties.GetPropertiesByAgentId(agentId, pageNo, pageSize, propertyStatus);
@@ -96,15 +107,15 @@ public async Task GetPropertyById(int propertyId)
[HttpPost]
public async Task CreateProperty([FromBody] PropertyRequestModel requestModel)
{
- if (requestModel == null)
+ var validationResult = ValidatePropertyRequestModel(requestModel);
+ if (validationResult != null)
{
- return BadRequest("Request model cannot be null");
+ return validationResult;
}
try
{
var response = await _blProperties.CreateProperty(requestModel);
- // return CreatedAtAction(nameof(GetPropertyById), new { propertyId = response.Property.PropertyId }, response);
return Ok(response);
}
catch (Exception ex)
@@ -113,7 +124,7 @@ public async Task CreateProperty([FromBody] PropertyRequestModel
}
}
- [HttpPut("{propertyId}")]
+ [HttpPut("Update/{propertyId}")]
public async Task UpdateProperty(int propertyId, [FromBody] PropertyRequestModel requestModel)
{
if (propertyId < 1)
@@ -121,9 +132,10 @@ public async Task UpdateProperty(int propertyId, [FromBody] Prope
return BadRequest("Invalid Property Id");
}
- if (requestModel == null)
+ var validationResult = ValidatePropertyRequestModel(requestModel);
+ if (validationResult != null)
{
- return BadRequest("Request model cannot be null");
+ return validationResult;
}
try
@@ -174,18 +186,46 @@ public async Task DeleteProperty(int propertyId)
{
var result = await _blProperties.DeleteProperty(propertyId);
return Ok(result);
- //if (result)
- //{
- // return NoContent();
- //}
- //else
- //{
- // return NotFound("Property not found");
- //}
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
+
+ private IActionResult ValidatePropertyRequestModel(PropertyRequestModel requestModel)
+ {
+ if (requestModel == null)
+ {
+ return BadRequest("Request model cannot be null");
+ }
+
+ if (!IsValidPropertyType(requestModel.PropertyType))
+ {
+ return BadRequest($"Invalid Type; Property Type should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyType)))}");
+ }
+
+ if (!IsValidPropertyAvailiableType(requestModel.AvailiablityType))
+ {
+ return BadRequest($"Invalid Availability Type; Property Availability Type should be one of the following: {string.Join(", ", Enum.GetNames(typeof(PropertyAvailiableType)))}");
+ }
+
+ return null;
+ }
+
+
+ private static bool IsValidPropertyStatus(string status)
+ {
+ return Enum.TryParse(status, out var parsedStatus) && Enum.IsDefined(typeof(PropertyStatus), parsedStatus);
+ }
+
+ private static bool IsValidPropertyType(string propertyType)
+ {
+ return Enum.TryParse(propertyType, out var parsedPropertyType) && Enum.IsDefined(typeof(PropertyType), parsedPropertyType);
+ }
+
+ private static bool IsValidPropertyAvailiableType(string propertyAvailiableType)
+ {
+ return Enum.TryParse(propertyAvailiableType, out var paresedPropertyAvailiableType) && Enum.IsDefined(typeof(PropertyAvailiableType), paresedPropertyAvailiableType);
+ }
}
\ No newline at end of file
diff --git a/REMS.BackendApi/appsettings.json b/REMS.BackendApi/appsettings.json
index ffcca27..c1740c7 100644
--- a/REMS.BackendApi/appsettings.json
+++ b/REMS.BackendApi/appsettings.json
@@ -8,8 +8,8 @@
"AllowedHosts": "*",
"ConnectionStrings": {
//"DbConnection": "Server=.;Database=REMS;User Id=sa;Password=sasa@123;TrustServerCertificate=True;",
- "DbConnection": "Server=.;Database=rems;User Id=sa;Password=sasa@123;TrustServerCertificate=True;"
- //"DbConnection": "Server=LAPTOP-TTIU8JF8;Database=REMS;User Id=sa;Password=Minkhantthu3367;TrustServerCertificate=True;"
+ //"DbConnection": "Server=.;Database=rems;User Id=sa;Password=sasa@123;TrustServerCertificate=True;"
+ "DbConnection": "Server=LAPTOP-TTIU8JF8;Database=REMS;User Id=sa;Password=Minkhantthu3367;TrustServerCertificate=True;"
//"DbConnection": "Server=.;Database=REMS;User Id=sa;Password=P@ssw0rd;TrustServerCertificate=True;"
//"DbConnection": "Server=.\\SQL2019E;Database=REMS;User Id=sa;Password=p@ssw0rd;TrustServerCertificate=True;"
},
diff --git a/REMS.Mapper/ChangeModel.cs b/REMS.Mapper/ChangeModel.cs
index a70e58d..93f02a2 100644
--- a/REMS.Mapper/ChangeModel.cs
+++ b/REMS.Mapper/ChangeModel.cs
@@ -79,9 +79,9 @@ public static Client Change(this ClientRequestModel requestModel)
return client;
}
- public static ClientResponseModel Change(this Client dataModel, User user)
+ public static ClientModel Change(this Client dataModel, User user)
{
- var clientResponseModel = new ClientResponseModel
+ var clientResponseModel = new ClientModel
{
ClientId = dataModel.ClientId,
UserId = dataModel.UserId,
@@ -214,6 +214,7 @@ public static ReviewModel Change(this Review dataModel)
PropertyId = dataModel.PropertyId,
Rating = dataModel.Rating,
Comments = dataModel.Comments,
+ DateCreated = dataModel.DateCreated,
};
return reviewModel;
diff --git a/REMS.Models/Appointment/AppointmentDetail.cs b/REMS.Models/Appointment/AppointmentDetail.cs
new file mode 100644
index 0000000..708a123
--- /dev/null
+++ b/REMS.Models/Appointment/AppointmentDetail.cs
@@ -0,0 +1,30 @@
+
+using REMS.Models.Custom;
+
+namespace REMS.Models.Appointment;
+
+
+public partial class AppointmentDetail
+{
+ public int? AppointmentId { get; set; }
+ public string? AgentName { get; set; }
+ public string? ClientName { get; set; }
+ public string? AppointmentDate { get; set; }
+ public string? AppointmentTime { get; set; }
+ public string? AgentPhoneNumber { get; set; }
+ public string? Status { get; set; }
+ public string? Note { get; set; }
+ public string? Address { get; set; }
+ public string? City { get; set; }
+ public string? State { get; set; }
+ public decimal? Price { get; set; }
+ public decimal? Size { get; set; }
+ public int? NumberOfBedrooms { get; set; }
+ public int? NumberOfBathrooms { get; set; }
+}
+
+public partial class AppointmentDetailList
+{
+ public PageSettingModel? pageSetting { get; set; }
+ public List appointmentDetails { get; set; }
+}
diff --git a/REMS.Models/Appointment/AppointmentResponseModel.cs b/REMS.Models/Appointment/AppointmentResponseModel.cs
index ef43af3..48cc84f 100644
--- a/REMS.Models/Appointment/AppointmentResponseModel.cs
+++ b/REMS.Models/Appointment/AppointmentResponseModel.cs
@@ -1,4 +1,7 @@
-using System;
+using REMS.Database.AppDbContextModels;
+using REMS.Models.Agent;
+using REMS.Models.Client;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -9,5 +12,6 @@ namespace REMS.Models.Appointment
public class AppointmentResponseModel
{
public AppointmentModel? Appointment { get; set; }
+
}
}
diff --git a/REMS.Models/Client/ClientListResponseModel.cs b/REMS.Models/Client/ClientListResponseModel.cs
index c1024e0..d4eec61 100644
--- a/REMS.Models/Client/ClientListResponseModel.cs
+++ b/REMS.Models/Client/ClientListResponseModel.cs
@@ -10,6 +10,6 @@ namespace REMS.Models.Client;
public class ClientListResponseModel
{
- public List DataLst { get; set; }
+ public List DataLst { get; set; }
public PageSettingModel PageSetting { get; set; }
}
diff --git a/REMS.Models/Client/ClientModel.cs b/REMS.Models/Client/ClientModel.cs
index d9c1f1d..9f4b3a2 100644
--- a/REMS.Models/Client/ClientModel.cs
+++ b/REMS.Models/Client/ClientModel.cs
@@ -15,4 +15,6 @@ public class ClientModel
public string? Email { get; set; }
public string? Address { get; set; }
+
+ public string? Role { get; set; }
}
diff --git a/REMS.Models/Property/PropertyResponseModel.cs b/REMS.Models/Property/PropertyResponseModel.cs
index ce450aa..6e074ab 100644
--- a/REMS.Models/Property/PropertyResponseModel.cs
+++ b/REMS.Models/Property/PropertyResponseModel.cs
@@ -1,7 +1,11 @@
-namespace REMS.Models.Property;
+using REMS.Models.Review;
+
+namespace REMS.Models.Property;
public class PropertyResponseModel
{
public PropertyModel Property { get; set; }
public List Images { get; set; }
+
+ public List Reviews { get; set; }
}
\ No newline at end of file
diff --git a/REMS.Models/Result.cs b/REMS.Models/Result.cs
index 44f852a..04024a8 100644
--- a/REMS.Models/Result.cs
+++ b/REMS.Models/Result.cs
@@ -40,4 +40,9 @@ public static Result Error(Exception ex)
IsSuccess = false,
};
}
+
+ public static implicit operator Result(Result? v)
+ {
+ throw new NotImplementedException();
+ }
}
diff --git a/REMS.Modules/Features/Agent/BL_Agent.cs b/REMS.Modules/Features/Agent/BL_Agent.cs
index f06e444..06e538b 100644
--- a/REMS.Modules/Features/Agent/BL_Agent.cs
+++ b/REMS.Modules/Features/Agent/BL_Agent.cs
@@ -32,10 +32,6 @@ public async Task> SearchAgentAsync(int id)
return await _daAgent.SearchAgentByUserIdAsync(id);
}
- public async Task> LoginAgentAsync(AgentLoginRequestModel agentLoginInfo)
- {
- return await _daAgent.LoginAgentAsync(agentLoginInfo);
- }
public async Task> SearchAgentByNameAsync(string name, int pageNumber, int pageSize)
{
@@ -64,4 +60,9 @@ public async Task> SearchAgentByNameAndLocationAs
}
return model;
}
+
+ public async Task>> AgentAll()
+ {
+ return await _daAgent.AgentAllAsync();
+ }
}
\ No newline at end of file
diff --git a/REMS.Modules/Features/Agent/DA_Agent.cs b/REMS.Modules/Features/Agent/DA_Agent.cs
index 1ae120b..67401b2 100644
--- a/REMS.Modules/Features/Agent/DA_Agent.cs
+++ b/REMS.Modules/Features/Agent/DA_Agent.cs
@@ -142,33 +142,6 @@ public async Task> DeleteAgentAsync(int userId)
}
return response;
}
-
- public async Task> LoginAgentAsync(AgentLoginRequestModel agentLoginInfo)
- {
- Result model = null;
- try
- {
- User? user = await _db.Users
- .Where(us => us.Name == agentLoginInfo.UserName && us.Password == agentLoginInfo.Password)
- .FirstOrDefaultAsync();
-
- if (user is null)
- {
- model = Result.Error("Login Fail");
- goto result;
- }
-
- model = model = Result.Error("Login Success");
- }
- catch (Exception ex)
- {
- model = Result.Error(ex);
- }
-
- result:
- return model;
- }
-
public async Task> SearchAgentByUserIdAsync(int id)
{
Result model = null;
@@ -331,4 +304,29 @@ public async Task> SearchAgentByNameAndLocationAs
return model;
}
+
+
+ public async Task>> AgentAllAsync()
+ {
+ Result> model = null;
+ try
+ {
+ List agents = await _db.Agents
+ .Select(ag => new AgentDto
+ {
+ AgentId = ag.AgentId,
+ UserId = ag.UserId,
+ AgencyName = ag.AgencyName,
+ LicenseNumber = ag.LicenseNumber,
+ Address = ag.Address
+ })
+ .ToListAsync();
+ model = Result>.Success(agents);
+ }
+ catch (Exception ex)
+ {
+ model = Result>.Error(ex);
+ }
+ return model;
+ }
}
\ No newline at end of file
diff --git a/REMS.Modules/Features/Appointment/BL_Appointment.cs b/REMS.Modules/Features/Appointment/BL_Appointment.cs
index c3e28c8..e7e4210 100644
--- a/REMS.Modules/Features/Appointment/BL_Appointment.cs
+++ b/REMS.Modules/Features/Appointment/BL_Appointment.cs
@@ -33,7 +33,7 @@ public async Task> DeleteAppointmentAsync(int id)
return response;
}
- public async Task> GetAppointmentByPropertyIdAsycn(int id, int pageNo, int pageSize)
+ public async Task> GetAppointmentByPropertyIdAsycn(int id, int pageNo, int pageSize)
{
var response = CheckPageNoandPageSize(pageNo, pageSize);
if (response is not null)
@@ -70,18 +70,25 @@ private Result CheckAppointmentValue(AppointmentReques
return default;
}
- private Result CheckPageNoandPageSize(int pageNo, int pageSize)
+ private Result CheckPageNoandPageSize(int pageNo, int pageSize)
{
AppointmentListResponseModel response = new AppointmentListResponseModel();
if (pageNo <= 0)
{
- return Result.Error("PageNo must be positive number");
+ return Result.Error("PageNo must be positive number");
}
if (pageSize <= 0)
{
- return Result.Error("pageSize must be positive number");
+ return Result.Error("pageSize must be positive number");
}
return default;
}
+
+
+ public async Task> GetAppointmentByClientId(int clientId, int pageNo, int pageSize)
+ {
+ return await _daAppointment.GetAppointmentByClientId(clientId, pageNo, pageSize);
+ }
+
}
}
diff --git a/REMS.Modules/Features/Appointment/DA_Appointment.cs b/REMS.Modules/Features/Appointment/DA_Appointment.cs
index 8eb1b06..006c4df 100644
--- a/REMS.Modules/Features/Appointment/DA_Appointment.cs
+++ b/REMS.Modules/Features/Appointment/DA_Appointment.cs
@@ -1,4 +1,5 @@
using Azure;
+using REMS.Database.AppDbContextModels;
using REMS.Models.Appointment;
using System;
using System.Collections.Generic;
@@ -77,45 +78,55 @@ public async Task> DeleteAppointmentAsync(int id)
return response;
}
- public async Task> GetAppointmentByPropertyIdAsycn(int id, int pageNo, int pageSize)
+ public async Task> GetAppointmentByPropertyIdAsycn(int propertyId, int pageNo, int pageSize)
{
- Result response = null;
+ Result response = null;
try
{
- var query = _db.Appointments
- .AsNoTracking()
- .Where(x => x.PropertyId == id)
- .Select(n => new AppointmentModel
- {
- AppointmentId = n.AppointmentId,
- ClientId = n.ClientId,
- PropertyId = n.PropertyId,
- AppointmentDate = n.AppointmentDate,
- AppointmentTime = n.AppointmentTime.ToString(),
- Status = n.Status,
- Notes = n.Notes
- });
- var appointmentList = await query.Pagination(pageNo, pageSize).ToListAsync();
- if (appointmentList is null || appointmentList.Count == 0)
+ var query = await (from _app in _db.Appointments
+ join _cli in _db.Clients on _app.ClientId equals _cli.ClientId
+ join _pro in _db.Properties on _app.PropertyId equals _pro.PropertyId
+ join _age in _db.Agents on _pro.AgentId equals _age.AgentId
+ where _app.PropertyId == propertyId
+ select new AppointmentDetail
+ {
+ AgentName = _age.AgencyName,
+ ClientName = _cli.FirstName + " " + _cli.LastName,
+ AppointmentDate = _app.AppointmentDate.ToString("yyyy-MM-dd"),
+ AppointmentTime = _app.AppointmentTime.ToString(),
+ Status = _app.Status,
+ Note = _app.Notes,
+ Address = _pro.Address,
+ City = _pro.City,
+ State = _pro.State,
+ Price = _pro.Price,
+ Size = _pro.Size,
+ NumberOfBedrooms = _pro.NumberOfBedrooms,
+ NumberOfBathrooms = _pro.NumberOfBathrooms,
+ }).ToListAsync();
+ var appointmentList = query
+ .Skip((pageNo - 1) * pageSize)
+ .Take(pageSize).ToList();
+ if (appointmentList is null || appointmentList.Count < 0)
{
- return Result.Error("No Data Found.");
+ return Result.Error("No Data Found.");
}
- int totalCount = await query.CountAsync();
+ int totalCount = query.Count();
int pageCount = totalCount / pageSize;
if (totalCount % pageSize != 0)
{
pageCount++;
}
- var appointmentResponse = new AppointmentListResponseModel
+ var appointmentResponse = new AppointmentDetailList
{
pageSetting = new PageSettingModel(pageNo, pageSize, pageCount, totalCount),
- lstAppointment = appointmentList
+ appointmentDetails = appointmentList
};
- response = Result.Success(appointmentResponse);
+ response = Result.Success(appointmentResponse);
}
catch (Exception ex)
{
- response = Result.Error(ex);
+ response = Result.Error(ex);
}
return response;
}
@@ -168,5 +179,61 @@ public async Task> UpdateAppointmentAsync(int i
}
return response;
}
+
+ public async Task> GetAppointmentByClientId(int clientId, int pageNo, int pageSize)
+ {
+ Result model = null;
+ try
+ {
+ var query = await (from _app in _db.Appointments
+ join _cli in _db.Clients on _app.ClientId equals _cli.ClientId
+ join _pro in _db.Properties on _app.PropertyId equals _pro.PropertyId
+ join _age in _db.Agents on _pro.AgentId equals _age.AgentId
+ join _user in _db.Users on _age.UserId equals _user.UserId
+ where _app.ClientId == clientId
+ select new AppointmentDetail
+ {
+ AppointmentId = _app.AppointmentId,
+ AgentName = _age.AgencyName,
+ ClientName = _cli.FirstName + " " + _cli.LastName,
+ AppointmentDate = _app.AppointmentDate.ToString("yyyy-MM-dd"),
+ AppointmentTime = _app.AppointmentTime.ToString(),
+ AgentPhoneNumber = _user.Phone,
+ Status = _app.Status,
+ Note = _app.Notes,
+ Address = _pro.Address,
+ City = _pro.City,
+ State = _pro.State,
+ Price = _pro.Price,
+ Size = _pro.Size,
+ NumberOfBedrooms = _pro.NumberOfBedrooms,
+ NumberOfBathrooms = _pro.NumberOfBathrooms,
+ }).ToListAsync();
+ var appointmentList = query
+ .Skip((pageNo - 1) * pageSize)
+ .Take(pageSize).ToList();
+ if (appointmentList is null || appointmentList.Count == 0)
+ {
+ return Result.Error("No Data Found.");
+ }
+ int totalCount = query.Count();
+ int pageCount = totalCount / pageSize;
+ if (totalCount % pageSize != 0)
+ {
+ pageCount++;
+ }
+ AppointmentDetailList newappdetailIst = new AppointmentDetailList
+ {
+ pageSetting = new PageSettingModel(pageNo, pageSize, pageCount, totalCount),
+ appointmentDetails = appointmentList
+ };
+ model = Result.Success(newappdetailIst);
+ }
+ catch (Exception ex)
+ {
+ model = Result.Error(ex);
+ }
+ return model;
+ }
}
}
diff --git a/REMS.Modules/Features/Client/BL_Client.cs b/REMS.Modules/Features/Client/BL_Client.cs
index 87e6cb4..6a42620 100644
--- a/REMS.Modules/Features/Client/BL_Client.cs
+++ b/REMS.Modules/Features/Client/BL_Client.cs
@@ -29,19 +29,19 @@ public async Task> GetClients(int pageNo, int pa
return response;
}
- public async Task> GetClientById(int id)
+ public async Task> GetClientById(int id)
{
var responseModel = await _daClient.GetClientById(id);
return responseModel;
}
- public async Task> CreateClient(ClientRequestModel requestModel)
+ public async Task> CreateClient(ClientRequestModel requestModel)
{
var response = await _daClient.CreateClient(requestModel);
return response;
}
- public async Task> UpdateClient(int id, ClientRequestModel requestModel)
+ public async Task> UpdateClient(int id, ClientRequestModel requestModel)
{
if (id <= 0) throw new Exception("id is null");
var response = await _daClient.UpdateClient(id, requestModel);
diff --git a/REMS.Modules/Features/Client/DA_Client.cs b/REMS.Modules/Features/Client/DA_Client.cs
index 83319ba..1daf514 100644
--- a/REMS.Modules/Features/Client/DA_Client.cs
+++ b/REMS.Modules/Features/Client/DA_Client.cs
@@ -30,7 +30,7 @@ public async Task> GetClients()
var clientListResponse = new ClientListResponseModel
{
- DataLst = clientResponseModel,
+ DataLst = clientResponseModel
};
model = Result.Success(clientListResponse);
@@ -79,9 +79,9 @@ public async Task> GetClients(int pageNo = 1, in
return model;
}
- public async Task> GetClientById(int id)
+ public async Task> GetClientById(int id)
{
- Result model = null;
+ Result model = null;
try
{
var client = await _db
@@ -92,23 +92,23 @@ public async Task> GetClientById(int id)
if (client is null)
{
- return model = Result.Error("Client not found.");
+ return model = Result.Error("Client not found.");
}
var responseModel = client.Change(client.User);
- model = Result.Success(responseModel);
+ model = Result.Success(responseModel);
}
catch (Exception ex)
{
- model = Result.Error(ex);
+ model = Result.Error(ex);
}
return model;
}
- public async Task> CreateClient(ClientRequestModel requestModel)
+ public async Task> CreateClient(ClientRequestModel requestModel)
{
- Result model = null;
+ Result model = null;
try
{
if (requestModel == null)
@@ -118,7 +118,7 @@ public async Task> CreateClient(ClientRequestModel r
if (CheckEmailDuplicate(requestModel.Email))
{
- model = Result.Error("Client create failed. Email already exist");
+ model = Result.Error("Client create failed. Email already exist");
goto result;
}
@@ -126,7 +126,7 @@ public async Task> CreateClient(ClientRequestModel r
int result = await _db.SaveChangesAsync();
if (result < 0)
{
- model = Result.Error("Client create failed.");
+ model = Result.Error("Client create failed.");
goto result;
}
@@ -145,20 +145,20 @@ public async Task> CreateClient(ClientRequestModel r
var responseModel = client.Change(user);
model = addClient > 0
- ? Result.Success(responseModel)
- : Result.Error("Client create failed.");
+ ? Result.Success(responseModel)
+ : Result.Error("Client create failed.");
}
catch (Exception ex)
{
- model = Result.Error(ex);
+ model = Result.Error(ex);
}
result:
return model;
}
- public async Task> UpdateClient(int id, ClientRequestModel requestModel)
+ public async Task> UpdateClient(int id, ClientRequestModel requestModel)
{
- Result model = null;
+ Result model = null;
try
{
var client = await _db.Clients
@@ -167,7 +167,7 @@ public async Task> UpdateClient(int id, ClientReques
if (client is null)
{
- return model = Result.Error("Client Not Found");
+ return model = Result.Error("Client Not Found");
goto result;
}
@@ -177,7 +177,7 @@ public async Task> UpdateClient(int id, ClientReques
if (user is null)
{
- return model = Result.Error("User Not Found");
+ return model = Result.Error("User Not Found");
goto result;
}
@@ -217,11 +217,11 @@ public async Task> UpdateClient(int id, ClientReques
var clientResponseModel = client.Change(user);
- model = Result.Success(clientResponseModel);
+ model = Result.Success(clientResponseModel);
}
catch (Exception ex)
{
- model = Result.Error(ex);
+ model = Result.Error(ex);
}
result:
return model;
diff --git a/REMS.Modules/Features/Property/BL_Property.cs b/REMS.Modules/Features/Property/BL_Property.cs
index 54ab462..6e9f0d5 100644
--- a/REMS.Modules/Features/Property/BL_Property.cs
+++ b/REMS.Modules/Features/Property/BL_Property.cs
@@ -9,24 +9,24 @@ public BL_Property(DA_Property daProperty)
_daProperty = daProperty;
}
- public async Task>> GetProperties()
+ public async Task>> GetProperties(string? propertyStatus)
{
- var response = await _daProperty.GetProperties();
+ var response = await _daProperty.GetProperties(propertyStatus);
return response;
}
- public async Task> GetProperties(int pageNo, int pageSize)
+ public async Task> GetProperties(int pageNo, int pageSize, string? propertyStatus)
{
if (pageNo < 1 || pageSize < 1)
{
throw new Exception("PageNo or PageSize Cannot be less than 1");
}
- var response = await _daProperty.GetProperties(pageNo, pageSize);
+ var response = await _daProperty.GetProperties(pageNo, pageSize, propertyStatus);
return response;
}
- public async Task>> GetPropertiesByAgentId(int agentId, string propertyStatus)
+ public async Task>> GetPropertiesByAgentId(int agentId, string? propertyStatus)
{
if (agentId < 1)
{
diff --git a/REMS.Modules/Features/Property/DA_Property.cs b/REMS.Modules/Features/Property/DA_Property.cs
index d102f3a..a129f3a 100644
--- a/REMS.Modules/Features/Property/DA_Property.cs
+++ b/REMS.Modules/Features/Property/DA_Property.cs
@@ -1,5 +1,6 @@
using Azure;
using Microsoft.Extensions.Configuration;
+using REMS.Models;
namespace REMS.Modules.Features.Property;
@@ -14,21 +15,29 @@ public DA_Property(AppDbContext db, IConfiguration configuration)
_configuration = configuration;
}
- public async Task>> GetProperties()
+ public async Task>> GetProperties(string? propertyStatus)
{
Result> model = null;
try
{
- var properties = await _db.Properties
- .AsNoTracking()
- .Where(x => x.Status == nameof(PropertyStatus.Approved))
- .Include(x => x.PropertyImages)
- .ToListAsync();
+ var query = _db.Properties
+ .AsNoTracking()
+ .Include(x => x.PropertyImages)
+ .Include(x => x.Reviews)
+ .AsQueryable();
+
+ if (!string.IsNullOrWhiteSpace(propertyStatus))
+ {
+ query = query.Where(x => x.Status == propertyStatus);
+ }
+
+ var properties = await query.ToListAsync();
var propertyResponseModels = properties.Select(property => new PropertyResponseModel
{
Property = property.Change(),
- Images = property.PropertyImages.Select(x => x.Change()).ToList()
+ Images = property.PropertyImages.Select(x => x.Change()).ToList(),
+ Reviews = property.Reviews.Select(x => x.Change()).ToList()
}).ToList();
model = Result>.Success(propertyResponseModels);
@@ -42,23 +51,30 @@ public async Task>> GetProperties()
}
}
- public async Task> GetProperties(int pageNo = 1, int pageSize = 10)
+ public async Task> GetProperties(int pageNo = 1, int pageSize = 10, string? propertyStatus = "")
{
Result model = null;
try
{
- var properties = await _db.Properties
+ var query = _db.Properties
.AsNoTracking()
- .Where(x => x.Status == nameof(PropertyStatus.Approved))
.Include(x => x.PropertyImages)
+ .Include(x => x.Reviews)
.Skip((pageNo - 1) * pageSize)
- .Take(pageSize)
- .ToListAsync();
+ .Take(pageSize);
+
+ if (!string.IsNullOrWhiteSpace(propertyStatus))
+ {
+ query = query.Where(x => x.Status == propertyStatus);
+ }
+
+ var properties = await query.ToListAsync();
var propertyResponseModel = properties.Select(property => new PropertyResponseModel
{
Property = property.Change(),
- Images = property.PropertyImages.Select(x => x.Change()).ToList()
+ Images = property.PropertyImages.Select(x => x.Change()).ToList(),
+ Reviews = property.Reviews.Select(x => x.Change()).ToList()
}).ToList();
var totalCount = await _db.Properties.CountAsync();
@@ -86,17 +102,25 @@ public async Task>> GetPropertiesByAgentId(in
Result> model = null;
try
{
- var properties = await _db.Properties
- .AsNoTracking()
- .Where(x => x.AgentId == agentId)
- .Where(x => x.Status == propertyStatus)
- .Include(x => x.PropertyImages)
- .ToListAsync();
+ var query = _db.Properties
+ .AsNoTracking()
+ .Where(x => x.AgentId == agentId);
+
+ if (!string.IsNullOrWhiteSpace(propertyStatus))
+ {
+ query = query.Where(x => x.Status == propertyStatus);
+ }
+
+ query = query.Include(x => x.PropertyImages)
+ .Include(x => x.Reviews);
+
+ var properties = await query.ToListAsync();
var propertyResponseModels = properties.Select(property => new PropertyResponseModel
{
Property = property.Change(),
- Images = property.PropertyImages.Select(x => x.Change()).ToList()
+ Images = property.PropertyImages.Select(x => x.Change()).ToList(),
+ Reviews = property.Reviews.Select(x => x.Change()).ToList()
}).ToList();
model = Result>.Success(propertyResponseModels);
@@ -110,24 +134,33 @@ public async Task>> GetPropertiesByAgentId(in
}
}
- public async Task> GetPropertiesByAgentId(int agentId, int pageNo = 1, int pageSize = 10, string propertyStatus = nameof(PropertyStatus.Approved))
+ public async Task> GetPropertiesByAgentId(int agentId, int pageNo = 1, int pageSize = 10, string? propertyStatus = "")
{
Result model = null;
try
{
- var properties = await _db.Properties
- .AsNoTracking()
- .Where(x => x.AgentId == agentId)
- .Where(x => x.Status == propertyStatus)
- .Include(x => x.PropertyImages)
- .Skip((pageNo - 1) * pageSize)
- .Take(pageSize)
- .ToListAsync();
+ var query = _db.Properties
+ .AsNoTracking()
+ .Where(x => x.AgentId == agentId);
+
+ if (!string.IsNullOrWhiteSpace(propertyStatus))
+ {
+ query = query.Where(x => x.Status == propertyStatus);
+ }
+
+ query = query.Include(x => x.PropertyImages)
+ .Include(x => x.Reviews);
+
+ var properties = await query
+ .Skip((pageNo - 1) * pageSize)
+ .Take(pageSize)
+ .ToListAsync();
var propertyResponseModel = properties.Select(property => new PropertyResponseModel
{
Property = property.Change(),
- Images = property.PropertyImages.Select(x => x.Change()).ToList()
+ Images = property.PropertyImages.Select(x => x.Change()).ToList(),
+ Reviews = property.Reviews.Select(x => x.Change()).ToList()
}).ToList();
var totalCount = await _db.Properties.Where(x => x.AgentId == agentId).CountAsync();
@@ -158,13 +191,15 @@ public async Task> GetPropertyById(int propertyId)
var property = await _db.Properties
.AsNoTracking()
.Include(x => x.PropertyImages)
+ .Include(x => x.Reviews)
.FirstOrDefaultAsync(x => x.PropertyId == propertyId)
?? throw new Exception("Property Not Found");
var propertyResponse = new PropertyResponseModel
{
Property = property.Change(),
- Images = property.PropertyImages.Select(x => x.Change()).ToList()
+ Images = property.PropertyImages.Select(x => x.Change()).ToList(),
+ Reviews = property.Reviews.Select(x => x.Change()).ToList()
};
model = Result.Success(propertyResponse);
@@ -206,13 +241,15 @@ public async Task> CreateProperty(PropertyRequestM
var createdProperty = await _db.Properties
.AsNoTracking()
.Include(x => x.PropertyImages)
+ .Include(x => x.Reviews)
.FirstOrDefaultAsync(x => x.PropertyId == property.PropertyId)
?? throw new Exception("Property Not Found");
var propertyResponse = new PropertyResponseModel
{
Property = createdProperty.Change(),
- Images = createdProperty.PropertyImages.Select(x => x.Change()).ToList()
+ Images = createdProperty.PropertyImages.Select(x => x.Change()).ToList(),
+ Reviews = property.Reviews.Select(x => x.Change()).ToList()
};
model = Result.Success(propertyResponse);
@@ -273,13 +310,15 @@ public async Task> UpdateProperty(int propertyId,
var updatedProperty = await _db.Properties
.AsNoTracking()
.Include(x => x.PropertyImages)
+ .Include(x => x.Reviews)
.FirstOrDefaultAsync(x => x.PropertyId == property.PropertyId)
?? throw new Exception("Property Not Found");
var responseModel = new PropertyResponseModel
{
Property = updatedProperty.Change(),
- Images = updatedProperty.PropertyImages.Select(x => x.Change()).ToList()
+ Images = updatedProperty.PropertyImages.Select(x => x.Change()).ToList(),
+ Reviews = property.Reviews.Select(x => x.Change()).ToList()
};
model = Result.Success(responseModel);
return model;
@@ -316,13 +355,15 @@ public async Task> ChangePropertyStatus(PropertySt
var updatedProperty = await _db.Properties
.AsNoTracking()
.Include(x => x.PropertyImages)
+ .Include(x => x.Reviews)
.FirstOrDefaultAsync(x => x.PropertyId == property.PropertyId)
?? throw new Exception("Property Not Found");
var responseModel = new PropertyResponseModel
{
Property = updatedProperty.Change(),
- Images = updatedProperty.PropertyImages.Select(x => x.Change()).ToList()
+ Images = updatedProperty.PropertyImages.Select(x => x.Change()).ToList(),
+ Reviews = property.Reviews.Select(x => x.Change()).ToList()
};
model = Result.Success(responseModel);
return model;