This commit is contained in:
@@ -67,10 +67,10 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// PUT Global biz settings
|
/// PUT Global biz settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="global"></param>
|
/// <param name="updatedObject"></param>
|
||||||
/// <returns>nothing</returns>
|
/// <returns>New concurrency token</returns>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
public async Task<IActionResult> ReplaceGlobalBizSettings([FromBody] GlobalBizSettings global)
|
public async Task<IActionResult> ReplaceGlobalBizSettings([FromBody] GlobalBizSettings updatedObject)
|
||||||
{
|
{
|
||||||
if (serverState.IsClosed)
|
if (serverState.IsClosed)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
@@ -84,16 +84,10 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
try
|
var o = await biz.PutAsync(updatedObject);//In future may need to return entire object, for now just concurrency token
|
||||||
{
|
if (o == null)
|
||||||
if (!await biz.ReplaceAsync(global))
|
return StatusCode(409, new ApiErrorResponse(biz.Errors));
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
|
||||||
}
|
|
||||||
catch (DbUpdateConcurrencyException)
|
|
||||||
{
|
|
||||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
|
||||||
}
|
|
||||||
return NoContent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -67,28 +67,22 @@ namespace AyaNova.Api.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// PUT Global ops backup settings
|
/// PUT Global ops backup settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="global"></param>
|
/// <param name="updatedObject"></param>
|
||||||
/// <returns>nothing</returns>
|
/// <returns>New concurrency token</returns>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
public async Task<IActionResult> ReplaceGlobalOpsBackupSettings([FromBody] GlobalOpsBackupSettings global)
|
public async Task<IActionResult> ReplaceGlobalOpsBackupSettings([FromBody] GlobalOpsBackupSettings updatedObject)
|
||||||
{
|
{
|
||||||
if (serverState.IsClosed)
|
if (serverState.IsClosed)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
GlobalOpsBackupSettingsBiz biz = GlobalOpsBackupSettingsBiz.GetBiz(ct, HttpContext);
|
GlobalOpsBackupSettingsBiz biz = GlobalOpsBackupSettingsBiz.GetBiz(ct, HttpContext);
|
||||||
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
try
|
var o = await biz.PutAsync(updatedObject);//In future may need to return entire object, for now just concurrency token
|
||||||
{
|
if (o == null)
|
||||||
if (!await biz.ReplaceAsync(global))
|
return StatusCode(409, new ApiErrorResponse(biz.Errors));
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
|
||||||
}
|
|
||||||
catch (DbUpdateConcurrencyException)
|
|
||||||
{
|
|
||||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
|
||||||
}
|
|
||||||
return NoContent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// <summary>
|
// /// <summary>
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
else
|
else
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency })); ;
|
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -59,24 +59,24 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
|
|
||||||
//put
|
//put
|
||||||
internal async Task<bool> ReplaceAsync(GlobalBizSettings inObj)
|
internal async Task<GlobalBizSettings> PutAsync(GlobalBizSettings updatedObject)
|
||||||
{
|
{
|
||||||
var dbObj = await ct.GlobalBizSettings.FirstOrDefaultAsync(m => m.Id == 1);
|
var dbObject = await ct.GlobalBizSettings.FirstOrDefaultAsync(m => m.Id == 1);
|
||||||
if (dbObj == null)
|
if (dbObject == null)
|
||||||
throw new System.Exception("GlobalBizSettingsBiz::ReplaceAsync -> Global settings object not found in database!!");
|
throw new System.Exception("GlobalBizSettingsBiz::ReplaceAsync -> Global settings object not found in database!!");
|
||||||
CopyObject.Copy(inObj, dbObj, "Id");
|
CopyObject.Copy(updatedObject, dbObject, "Id");
|
||||||
|
|
||||||
ct.Entry(dbObj).OriginalValues["Concurrency"] = inObj.Concurrency;
|
ct.Entry(dbObject).OriginalValues["Concurrency"] = updatedObject.Concurrency;
|
||||||
|
|
||||||
Validate(dbObj);
|
Validate(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return null;
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
//Log modification and save context
|
//Log modification and save context
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Modified), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Modified), ct);
|
||||||
//Update the static copy for the server
|
//Update the static copy for the server
|
||||||
ServerGlobalBizSettings.Initialize(dbObj);
|
ServerGlobalBizSettings.Initialize(dbObject);
|
||||||
return true;
|
return dbObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,11 +58,11 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
|
|
||||||
//put
|
//put
|
||||||
internal async Task<bool> ReplaceAsync(GlobalOpsBackupSettings putObject)
|
internal async Task<GlobalOpsBackupSettings> PutAsync(GlobalOpsBackupSettings putObject)
|
||||||
{
|
{
|
||||||
var dbObject = await ct.GlobalOpsBackupSettings.FirstOrDefaultAsync(m => m.Id == 1);
|
var dbObject = await ct.GlobalOpsBackupSettings.FirstOrDefaultAsync(m => m.Id == 1);
|
||||||
if (dbObject == null)
|
if (dbObject == null)
|
||||||
throw new System.Exception("GlobalOpsSettingsBiz::ReplaceAsync -> Global settings object not found in database!!");
|
throw new System.Exception("GlobalOpsSettingsBiz::PutAsync -> Global settings object not found in database!!");
|
||||||
|
|
||||||
//If backup time has changed then reset last backup as well as it might block from taking effect
|
//If backup time has changed then reset last backup as well as it might block from taking effect
|
||||||
if (putObject.BackupTime.Hour != dbObject.BackupTime.Hour && putObject.BackupTime.Minute != dbObject.BackupTime.Minute)
|
if (putObject.BackupTime.Hour != dbObject.BackupTime.Hour && putObject.BackupTime.Minute != dbObject.BackupTime.Minute)
|
||||||
@@ -73,12 +73,12 @@ namespace AyaNova.Biz
|
|||||||
ct.Entry(dbObject).OriginalValues["Concurrency"] = putObject.Concurrency;
|
ct.Entry(dbObject).OriginalValues["Concurrency"] = putObject.Concurrency;
|
||||||
Validate(dbObject);
|
Validate(dbObject);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return null;
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Modified), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Modified), ct);
|
||||||
//Update the static copy for the server
|
//Update the static copy for the server
|
||||||
ServerGlobalOpsSettingsCache.Backup=dbObject;
|
ServerGlobalOpsSettingsCache.Backup=dbObject;
|
||||||
return true;
|
return dbObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user