Update SetCompany API for better ease of use
This commit is contained in:
@@ -29,25 +29,24 @@ namespace BoredCareers.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SetCompany([FromBody] Company company, [FromQuery] bool newCompany = false) {
|
||||
public async Task<IActionResult> SetCompany([FromBody] Company company) {
|
||||
if (isLoggedIn()) {
|
||||
if (newCompany) {
|
||||
Company? test = await _databaseService.GetCompany(Convert.ToInt32(company.ID));
|
||||
if (test == null) {
|
||||
company.ID = await _databaseService.SetCompany(company);
|
||||
Company? test = await _databaseService.GetCompany(Convert.ToInt32(company.ID));
|
||||
if (test == null) {
|
||||
company.ID = await _databaseService.SetCompany(company);
|
||||
|
||||
|
||||
await _databaseService.SetEmployee(new Employee() {
|
||||
AccountID = getLoggedInUserID(),
|
||||
AccountName = getLoggedInUser().UserName,
|
||||
AccountEmail = getLoggedInUser().Email,
|
||||
Company = company
|
||||
});
|
||||
return Ok();
|
||||
}
|
||||
return NotFound("The company already exists");
|
||||
await _databaseService.SetEmployee(new Employee() {
|
||||
AccountID = getLoggedInUserID(),
|
||||
AccountName = getLoggedInUser().UserName,
|
||||
AccountEmail = getLoggedInUser().Email,
|
||||
Company = company
|
||||
});
|
||||
return Ok();
|
||||
} else {
|
||||
if (await isLoggedInUserEmployeeOf(Convert.ToInt32(company.ID))) {
|
||||
if (company.Email != test.Email) {
|
||||
company.EmailVerified = false;
|
||||
}
|
||||
await _databaseService.SetCompany(company);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user