public async Task <IActionResult> Post([FromBody] CRUDDto data) { APIResult apiResult; #region 驗證 DTO 物件的資料一致性 if (!ModelState.IsValid) { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, "傳送過來的資料有問題", payload: null); return(Ok(apiResult)); } #endregion #region 新增紀錄 await Task.Yield(); data.Id = new Random().Next(1, 99999); #endregion apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, ErrorMessageEnum.None, payload: data); return(Ok(apiResult)); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] CRUDDto data) { APIResult apiResult; #region 驗證 DTO 物件的資料一致性 if (!ModelState.IsValid) { apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK, "傳送過來的資料有問題", payload: null); return(Ok(apiResult)); } #endregion #region 更新物件 await Task.Yield(); CRUDDto CRUDDto = data; #endregion apiResult = APIResultFactory.Build(true, StatusCodes.Status202Accepted, ErrorMessageEnum.None, payload: null); return(Ok(apiResult)); }