This commit is contained in:
2021-08-19 20:25:45 +00:00
parent 02b1846fdc
commit a8335cfd7d
3 changed files with 138 additions and 68 deletions

View File

@@ -61,31 +61,7 @@ namespace AyaNova.Api.Controllers
else
return CreatedAtAction(nameof(UnitController.GetUnit), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
}
// /// <summary>
// /// Duplicate Unit
// /// (Wiki and Attachments are not duplicated)
// /// </summary>
// /// <param name="id">Source object id</param>
// /// <param name="apiVersion">From route path</param>
// /// <returns>Unit</returns>
// [HttpPost("duplicate/{id}")]
// public async Task<IActionResult> DuplicateUnit([FromRoute] long id, ApiVersion apiVersion)
// {
// if (!serverState.IsOpen)
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
// UnitBiz biz = UnitBiz.GetBiz(ct, HttpContext);
// if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
// return StatusCode(403, new ApiNotAuthorizedResponse());
// if (!ModelState.IsValid)
// return BadRequest(new ApiErrorResponse(ModelState));
// Unit o = await biz.DuplicateAsync(id);
// if (o == null)
// return BadRequest(new ApiErrorResponse(biz.Errors));
// else
// return CreatedAtAction(nameof(UnitController.GetUnit), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
// }
/// <summary>
/// Get Unit
/// </summary>
@@ -375,5 +351,29 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Create Unit Meter Reading entry
/// </summary>
/// <param name="newObject"></param>
/// <param name="apiVersion">From route path</param>
/// <returns></returns>
[HttpPost("meter-reading")]
public async Task<IActionResult> PostUnitMeterReading([FromBody] UnitMeterReading newObject, ApiVersion apiVersion)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
UnitBiz biz = UnitBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
UnitMeterReading o = await biz.CreateMeterReadingAsync(newObject);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return CreatedAtAction(nameof(UnitController.GetUnit), new { id = o.UnitId, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
}
}//eoc
}//eons