Skip to content

Commit

Permalink
Merge pull request #34 from one-project-one-month/dev
Browse files Browse the repository at this point in the history
Merge Request
  • Loading branch information
HeinHtetAung-Dev authored Aug 1, 2024
2 parents 0614275 + 9aaf35c commit 136850f
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 39 deletions.
16 changes: 16 additions & 0 deletions REMS.BackendApi/Features/Appointment/AppointmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,21 @@ public async Task<IActionResult> GetAppointmentByAgentId(int id,int pageNo,int p
return StatusCode(StatusCodes.Status500InternalServerError, ex.ToString());
}
}

[HttpPatch("{id}")]
public async Task<IActionResult> UpdateAppointment(int id,AppointmentRequestModel requestModel)
{
try
{
var response = await _blAppointment.UpdateAppointmentAsync(id, requestModel);
if (response.IsError)
return BadRequest(response);
return Ok(response);
}
catch(Exception ex)
{
return StatusCode(StatusCodes.Status500InternalServerError, ex);
}
}
}
}
22 changes: 17 additions & 5 deletions REMS.Mapper/ChangeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ public static Agent ChangeAgent(this AgentRequestModel requestModel)
return agent;
}

public static AgentDto ChangeAgent(this Agent agent)
public static AgentDto ChangeAgent(this Agent agent,User user)
{
return new AgentDto
{
AgentId = agent.AgentId,
UserId = agent.UserId,
AgencyName = agent.AgencyName,
LicenseNumber = agent.LicenseNumber,
Email=user.Email,
PhoneNumber=user.Phone,
Address = agent.Address
};
}
Expand Down Expand Up @@ -98,6 +100,7 @@ public static PropertyModel Change(this Property dataModel)
var propertyModel = new PropertyModel()
{
PropertyId = dataModel.PropertyId,
AgentId = dataModel.AgentId,
Address = dataModel.Address,
City = dataModel.City,
State = dataModel.State,
Expand All @@ -109,17 +112,22 @@ public static PropertyModel Change(this Property dataModel)
NumberOfBathrooms = dataModel.NumberOfBathrooms,
YearBuilt = dataModel.YearBuilt,
Description = dataModel.Description,
Status = dataModel.Status
Status = dataModel.Status,
AvailiablityType =dataModel.AvailiablityType,
MinrentalPeriod = dataModel.MinrentalPeriod,
Approvedby = dataModel.Approvedby,
Adddate = dataModel.Adddate,
Editdate = dataModel.Editdate,
};

return propertyModel;
}

public static Property Change(this PropertyRequestModel requestModel)
{
Property property = new Property
Property property = new()
{
PropertyId = requestModel.PropertyId ?? 0,
AgentId = requestModel.AgentId,
Address = requestModel.Address,
City = requestModel.City,
State = requestModel.State,
Expand All @@ -131,8 +139,12 @@ public static Property Change(this PropertyRequestModel requestModel)
NumberOfBathrooms = requestModel.NumberOfBathrooms,
YearBuilt = requestModel.YearBuilt,
Description = requestModel.Description,
Status = requestModel.Status
Status = requestModel.Status,
AvailiablityType = requestModel.AvailiablityType,
MinrentalPeriod = requestModel.MinRentalPeriod,
Approvedby = requestModel.ApprovedBy,
};

return property;
}

Expand Down
4 changes: 2 additions & 2 deletions REMS.Models/Agent/AgentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class AgentDto

public string? LicenseNumber { get; set; } = null!;

public string? Phone { get; set; }

public string? Email { get; set; }

public string? PhoneNumber { get; set; }

public string? Address { get; set; }
}
24 changes: 17 additions & 7 deletions REMS.Models/Property/PropertyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ public class PropertyModel
{
public int PropertyId { get; set; }

public string Address { get; set; }
public int? AgentId { get; set; }

public string City { get; set; }
public string Address { get; set; } = null!;

public string State { get; set; }
public string City { get; set; } = null!;

public string ZipCode { get; set; }
public string State { get; set; } = null!;

public string PropertyType { get; set; }
public string ZipCode { get; set; } = null!;

public string PropertyType { get; set; } = null!;

public decimal Price { get; set; }

Expand All @@ -26,7 +28,15 @@ public class PropertyModel

public string? Description { get; set; }

public string Status { get; set; }
public string Status { get; set; } = null!;

public string AvailiablityType { get; set; } = null!;

public int? MinrentalPeriod { get; set; }

public string? Approvedby { get; set; }

public DateTime? Adddate { get; set; }

public DateTime? DateListed { get; set; }
public DateTime? Editdate { get; set; }
}
14 changes: 8 additions & 6 deletions REMS.Models/Property/PropertyRequestModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
namespace REMS.Models.Property;
namespace REMS.Models.Property;

public class PropertyRequestModel
{
public int? PropertyId { get; set; }
public int? AgentId { get; set; }

public string Address { get; set; }

Expand All @@ -29,14 +28,17 @@ public class PropertyRequestModel

public string Status { get; set; }

public DateTime? DateListed { get; set; }
public string AvailiablityType { get; set; }

public List<PropertyImageRequestModel> Images { get; set; }
public int? MinRentalPeriod { get; set; }

public string? ApprovedBy { get; set; }

public List<PropertyImageRequestModel> Images { get; set; } = new List<PropertyImageRequestModel>();
}

public class PropertyImageRequestModel
{
public string? ImgBase64 { get; set; }
public string? Description { get; set; }
}

2 changes: 1 addition & 1 deletion REMS.Modules/Features/Agent/BL_Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<Result<object>> DeleteAgentAsync(int id)

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

public async Task<Result<string>> LoginAgentAsync(AgentLoginRequestModel agentLoginInfo)
Expand Down
26 changes: 19 additions & 7 deletions REMS.Modules/Features/Agent/DA_Agent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace REMS.Modules.Features.Agent;
using REMS.Models.User;

namespace REMS.Modules.Features.Agent;

public class DA_Agent
{
Expand Down Expand Up @@ -35,7 +37,7 @@ public async Task<Result<AgentResponseModel>> CreateAgentAsync(AgentRequestModel
}
var agentResponse = new AgentResponseModel
{
Agent = agent.ChangeAgent()
Agent = agent.ChangeAgent(user)
};
response = Result<AgentResponseModel>.Success(agentResponse, "Agent Register Successfully");
}
Expand Down Expand Up @@ -96,9 +98,9 @@ public async Task<Result<AgentResponseModel>> UpdateAgentAsync(int id, AgentRequ
{
return Result<AgentResponseModel>.Error("Updating Fail");
}
var agentResponse = new AgentResponseModel
AgentResponseModel agentResponse = new AgentResponseModel
{
Agent = agent.ChangeAgent()
Agent = agent.ChangeAgent(user)
};
response = Result<AgentResponseModel>.Success(agentResponse, "Successfully Update");
}
Expand Down Expand Up @@ -167,13 +169,13 @@ public async Task<Result<string>> LoginAgentAsync(AgentLoginRequestModel agentLo
return model;
}

public async Task<Result<AgentDto>> SearchAgentAsync(int id)
public async Task<Result<AgentDto>> SearchAgentByUserIdAsync(int id)
{
Result<AgentDto> model = null;
try
{
AgentDto? agent = await _db.Agents
.Where(ag => ag.AgentId == id)
.Where(ag => ag.UserId == id)
.Select(ag => new AgentDto
{
AgentId = ag.AgentId,
Expand All @@ -183,11 +185,21 @@ public async Task<Result<AgentDto>> SearchAgentAsync(int id)
Address = ag.Address
})
.FirstOrDefaultAsync();
if (agent is null)
var user = await _db.Users
.Where(x => x.UserId == id)
.Select(n => new UserModel
{
Phone = n.Phone,
Email = n.Email
})
.FirstOrDefaultAsync();
if (agent is null || user is null)
{
model = Result<AgentDto>.Error("User Not Found");
goto result;
}
agent.PhoneNumber=user.Phone;
agent.Email=user.Email;
model = Result<AgentDto>.Success(agent);
}
catch (Exception ex)
Expand Down
5 changes: 5 additions & 0 deletions REMS.Modules/Features/Appointment/BL_Appointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public async Task<Result<AppointmentListResponseModel>> GetAppointmentByAgentIdA
return await _daAppointment.GetAppointmentByClientIdAsync(id, pageNo, pageSize);
}

public async Task<Result<AppointmentResponseModel>> UpdateAppointmentAsync(int id, AppointmentRequestModel requestModel)
{
return await _daAppointment.UpdateAppointmentAsync(id, requestModel);
}

private Result<AppointmentResponseModel> CheckAppointmentValue(AppointmentRequestModel requestModel)
{
TimeSpan time;
Expand Down
69 changes: 59 additions & 10 deletions REMS.Modules/Features/Appointment/DA_Appointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<Result<AppointmentResponseModel>> CreateAppointmentAsync(Appoi
}
catch (Exception ex)
{
response= Result<AppointmentResponseModel>.Error(ex);
response = Result<AppointmentResponseModel>.Error(ex);
}
return response;
}
Expand All @@ -63,7 +63,7 @@ public async Task<Result<object>> DeleteAppointmentAsync(int id)
.AsNoTracking()
.FirstOrDefaultAsync(x => x.AppointmentId == id);
if (appointment is null)
return Result<object>.Error( "Appointment Not Found.");
return Result<object>.Error("Appointment Not Found.");
_db.Appointments.Remove(appointment);
_db.Entry(appointment).State = EntityState.Deleted;
int result = await _db.SaveChangesAsync();
Expand All @@ -73,7 +73,7 @@ public async Task<Result<object>> DeleteAppointmentAsync(int id)
}
catch (Exception ex)
{
response= Result<object>.Error( ex);
response = Result<object>.Error(ex);
}
return response;
}
Expand All @@ -86,18 +86,18 @@ public async Task<Result<AppointmentListResponseModel>> GetAppointmentByClientId
var query = _db.Appointments
.AsNoTracking()
.Where(x => x.ClientId == id)
.Select(n=>new AppointmentModel
.Select(n => new AppointmentModel
{
AppointmentId = n.AppointmentId,
ClientId=n.ClientId,
PropertyId=n.PropertyId,
ClientId = n.ClientId,
PropertyId = n.PropertyId,
AppointmentDate = n.AppointmentDate,
AppointmentTime=n.AppointmentTime.ToString(),
Status=n.Status,
Notes=n.Notes
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)
if (appointmentList is null || appointmentList.Count == 0)
{
return Result<AppointmentListResponseModel>.Error("No Data Found.");
}
Expand All @@ -120,5 +120,54 @@ public async Task<Result<AppointmentListResponseModel>> GetAppointmentByClientId
}
return response;
}

public async Task<Result<AppointmentResponseModel>> UpdateAppointmentAsync(int id, AppointmentRequestModel requestModel)
{
Result<AppointmentResponseModel> response = null;
try
{
if (requestModel is null)
return Result<AppointmentResponseModel>.Error("Request Model is null");

var appointment = await _db.Appointments
.AsNoTracking()
.FirstOrDefaultAsync(x => x.PropertyId == id); ;
if (appointment is null)
return Result<AppointmentResponseModel>.Error("appointment not found");

if (!string.IsNullOrWhiteSpace(requestModel.AppointmentDate.ToString()))
{
appointment.AppointmentDate = requestModel.AppointmentDate;
}
if (!string.IsNullOrWhiteSpace(requestModel.AppointmentTime))
{
appointment.AppointmentTime = TimeSpan.Parse(requestModel.AppointmentTime);
}
if (!string.IsNullOrWhiteSpace(requestModel.Status))
{
appointment.Status = requestModel.Status;
}
if (!string.IsNullOrWhiteSpace(requestModel.Notes))
{
appointment.Notes = requestModel.Notes;
}
_db.Entry(appointment).State= EntityState.Modified;
int result=await _db.SaveChangesAsync();
if (result < 0)
{
return Result<AppointmentResponseModel>.Error("Fail to update appointment");
}
var appointmentResponse = new AppointmentResponseModel
{
Appointment = appointment.Change()
};
response=Result<AppointmentResponseModel>.Success(appointmentResponse,"Appointment Update Successfully");
}
catch (Exception ex)
{
response = Result<AppointmentResponseModel>.Error(ex);
}
return response;
}
}
}
Loading

0 comments on commit 136850f

Please sign in to comment.