This commit is contained in:
@@ -67,10 +67,10 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// PUT Global biz settings
|
||||
/// </summary>
|
||||
/// <param name="global"></param>
|
||||
/// <returns>nothing</returns>
|
||||
/// <param name="updatedObject"></param>
|
||||
/// <returns>New concurrency token</returns>
|
||||
[HttpPut]
|
||||
public async Task<IActionResult> ReplaceGlobalBizSettings([FromBody] GlobalBizSettings global)
|
||||
public async Task<IActionResult> ReplaceGlobalBizSettings([FromBody] GlobalBizSettings updatedObject)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
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))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
try
|
||||
{
|
||||
if (!await biz.ReplaceAsync(global))
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
return NoContent();
|
||||
var o = await biz.PutAsync(updatedObject);//In future may need to return entire object, for now just concurrency token
|
||||
if (o == null)
|
||||
return StatusCode(409, new ApiErrorResponse(biz.Errors));
|
||||
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -67,28 +67,22 @@ namespace AyaNova.Api.Controllers
|
||||
/// <summary>
|
||||
/// PUT Global ops backup settings
|
||||
/// </summary>
|
||||
/// <param name="global"></param>
|
||||
/// <returns>nothing</returns>
|
||||
/// <param name="updatedObject"></param>
|
||||
/// <returns>New concurrency token</returns>
|
||||
[HttpPut]
|
||||
public async Task<IActionResult> ReplaceGlobalOpsBackupSettings([FromBody] GlobalOpsBackupSettings global)
|
||||
public async Task<IActionResult> ReplaceGlobalOpsBackupSettings([FromBody] GlobalOpsBackupSettings updatedObject)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
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());
|
||||
try
|
||||
{
|
||||
if (!await biz.ReplaceAsync(global))
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
return NoContent();
|
||||
var o = await biz.PutAsync(updatedObject);//In future may need to return entire object, for now just concurrency token
|
||||
if (o == null)
|
||||
return StatusCode(409, new ApiErrorResponse(biz.Errors));
|
||||
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace AyaNova.Api.Controllers
|
||||
else
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency })); ;
|
||||
return Ok(ApiOkResponse.Response(new { Concurrency = o.Concurrency }));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -59,24 +59,24 @@ namespace AyaNova.Biz
|
||||
//
|
||||
|
||||
//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);
|
||||
if (dbObj == null)
|
||||
var dbObject = await ct.GlobalBizSettings.FirstOrDefaultAsync(m => m.Id == 1);
|
||||
if (dbObject == null)
|
||||
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)
|
||||
return false;
|
||||
return null;
|
||||
await ct.SaveChangesAsync();
|
||||
//Log modification and save context
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Modified), ct);
|
||||
//Update the static copy for the server
|
||||
ServerGlobalBizSettings.Initialize(dbObj);
|
||||
return true;
|
||||
ServerGlobalBizSettings.Initialize(dbObject);
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,11 +58,11 @@ namespace AyaNova.Biz
|
||||
//
|
||||
|
||||
//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);
|
||||
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 (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;
|
||||
Validate(dbObject);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
return null;
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, 1, BizType, AyaEvent.Modified), ct);
|
||||
//Update the static copy for the server
|
||||
ServerGlobalOpsSettingsCache.Backup=dbObject;
|
||||
return true;
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user