Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ public async Task<IActionResult> Login([FromBody] LoginDto loginDto)
}

var employee = await _context.Employees!.FirstOrDefaultAsync(e => e.Email == loginDto.Email);
if (employee == null)
{
return BadRequest(new {message = "Invalid credentials"});
}
var role = "";

if (!BCrypt.Net.BCrypt.Verify(loginDto.Password, employee.Password))
{
Expand All @@ -124,6 +121,14 @@ public async Task<IActionResult> Login([FromBody] LoginDto loginDto)
employee.Token = jwtTokens.Token;
await _context.SaveChangesAsync();

var parkingPlaceId = "";

if (employee.Role == "Operator")
{
var parkingPlace = await _context.ParkingPlaces!.FirstOrDefaultAsync(p => p.ParkingPlaceOperatorId == employee.EmployeeId);
parkingPlaceId = parkingPlace!.ParkingPlaceId;
}

var user = new
{
Id = employee.EmployeeId,
Expand All @@ -132,6 +137,7 @@ public async Task<IActionResult> Login([FromBody] LoginDto loginDto)
Email = employee.Email,
Role = employee.Role,
ProfilePicture = employee.ProfilePicture,
ParkingPlaceId = parkingPlaceId
};


Expand Down Expand Up @@ -217,7 +223,7 @@ private async Task<AuthResults> GenerateJwtToken(Employee employee)
};
}

private string RandomString(int length)
private static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz_";
return new string(Enumerable.Repeat(chars, length)
Expand Down
44 changes: 42 additions & 2 deletions Controllers/EmployeeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IActionResult GetEmployeeById(string employeeId)
}

[HttpPost("update-employee")]
[Authorize]

public IActionResult UpdateEmployee(EmployeeIdDto employeeIdDto)
{
var employee = _context.Employees!.FirstOrDefault(e => e.EmployeeId == employeeIdDto.EmployeeId);
Expand All @@ -61,7 +61,17 @@ public IActionResult UpdateEmployee(EmployeeIdDto employeeIdDto)
});
}

employee.Role = employee.Role == "Employee" ? "Manager" : "Employee";
employee.FirstName = employeeIdDto.FirstName!;
employee.LastName = employeeIdDto.LastName!;
employee.EmployeeId = employeeIdDto.EmployeeId!;
employee.Email = employeeIdDto.Email!;
employee.Nic = employeeIdDto.Nic!;
employee.ContactNumber = employeeIdDto.ContactNumber!;
employee.AddressLine1 = employeeIdDto.AddressLine1!;
employee.AddressLine2 = employeeIdDto.AddressLine2!;
employee.Street = employeeIdDto.Street!;
employee.City = employeeIdDto.City!;

_context.SaveChanges();

return Ok(new
Expand Down Expand Up @@ -92,4 +102,34 @@ public IActionResult DeleteEmployee(EmployeeIdDto employeeIdDto)
message = "Employee deleted successfully"
});
}

// [HttpPost("update-employee")]
// public IActionResult UpdateEmployee([FromBody] UpdateEmployeeDto updateEmployeeDto)
// {
// var employee = _context.Employees!.FirstOrDefault(e => e.EmployeeId == updateEmployeeDto.EmployeeId);
//
// if (employee == null)
// {
// return BadRequest(new
// {
// message = "Employee not found"
// });
// }
//
// employee.FirstName = updateEmployeeDto.FirstName;
// employee.LastName = updateEmployeeDto.LastName;
// employee.AddressLine1 = updateEmployeeDto.AddressLine1;
// employee.Street = updateEmployeeDto.Street;
// employee.City = updateEmployeeDto.City;
// employee.ContactNumber = updateEmployeeDto.ContactNumber;
// employee.Nic = updateEmployeeDto.Nic;
//
// _context.Update(employee);
// _context.SaveChanges();
//
// return Ok(new
// {
// message = "Employee Updated Successfully"
// });
// }
}
94 changes: 93 additions & 1 deletion Controllers/ParkingPlacesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,79 @@ public async Task<IActionResult> GetParkingPlace(string parkingPlaceId)
});

}

[HttpGet("get-parking-place-info/{parkingPlaceId}")]
public async Task<IActionResult> GetParkingPlaceInfo(string parkingPlaceId)
{
var parkingPlace = await _context.ParkingPlaces!.FirstOrDefaultAsync(p => p.ParkingPlaceId == parkingPlaceId);

if (parkingPlace == null)
{
return NotFound(new
{
message = "Parking place not found."
});
}

var parkingService = await _context.ParkingPlaceServices!.Where(p => p.ParkingPlaceId == parkingPlaceId).ToListAsync();
var parkingPlaceVerifiedDate =
await _context.AwaitedParkingPlaces!.FirstOrDefaultAsync(p => p.AwaitedParkingPlacesId == parkingPlaceId);


return Ok(new
{
services = parkingService,
date = parkingPlaceVerifiedDate!.ConfirmationDate,
parking = parkingPlace

});
}

[HttpGet("get-all-parking-places")]
public async Task<IActionResult> GetAllParkingPlaces()
{
var parkingPlaces = await _context.ParkingPlaces!.ToListAsync();

if (parkingPlaces == null)
{
return NotFound(new
{
message = "Parking place not found"
});
}

var parkingPlacesList = new List<ParkingPlacesResponseDto>();

foreach (var parkingPlace in parkingPlaces)
{
var parkingOwner =
await _context.ParkingPlaceOwners!.FirstOrDefaultAsync(
p => p.OwnerId == parkingPlace.ParkingPlaceOwnerId);
var parkingOperator =
await _context.Employees!.FirstOrDefaultAsync(p => p.EmployeeId == parkingPlace.ParkingPlaceOperatorId);
var parkingVerifier =
await _context.Employees!.FirstOrDefaultAsync(p => p.EmployeeId == parkingPlace.ParkingPlaceVerifierId);
var complienceMonitoringDate =
await _context.ComplianceMonitoring!.FirstOrDefaultAsync(p =>
p.ParkingPlaceId == parkingPlace.ParkingPlaceId);
var parkingPlaceResponseDto = new ParkingPlacesResponseDto
{
ParkingPlaceId = parkingPlace.ParkingPlaceId,
Name = parkingPlace.Name,
Location = parkingPlace.Location,
ParkingOperator = parkingOperator!.FirstName+" "+ parkingOperator.LastName,
ParkingOwner = parkingOwner!.FullName,
ParkingVerifier = parkingVerifier!.FirstName+" "+ parkingVerifier.LastName,
Date = complienceMonitoringDate!.Date
};
parkingPlacesList.Add(parkingPlaceResponseDto);
}

return Ok(new
{
data = parkingPlacesList
});
}

[HttpGet("get-parking-place-by-operator/{operatorId}")]
public async Task<IActionResult> GetParkingPlaceByOperator(string operatorId)
Expand All @@ -92,11 +165,30 @@ public async Task<IActionResult> GetParkingPlaceByOperator(string operatorId)
message = "Parking place not found"
});
}

return Ok(new
{
data = parkingPlace
});
}

[HttpGet("get-new-parking-places/{role}")]
public async Task<IActionResult> GetNewParkingPlaces(string role)
{
var parkingPlaces = new List<ParkingPlace>();
if (role == "Operator")
{
parkingPlaces = await _context.ParkingPlaces!.Where(p => p.ParkingPlaceOperatorId == null).ToListAsync();
}
else if (role == "Verifier")
{
parkingPlaces = await _context.ParkingPlaces!.Where(p => p.ParkingPlaceVerifierId == null).ToListAsync();
}

return Ok(new
{
data = parkingPlaces
}
);
}

}
Loading