public async Task <IActionResult> PutTodoList(TestTodoList testTodoList) { var result = new Result <object>(); Type modelType = typeof(TestTodoList); // TestTodoList findTestTodoList = new TestTodoList(); // _mapper.Map(testTodoList, findTestTodoList); var updateTestTodoList = await _ablemusicContext.TestTodoList .Where(x => x.Id == testTodoList.Id) .FirstOrDefaultAsync(); if (updateTestTodoList == null) { return(NotFound(DataNotFound(result))); } UpdateTable(testTodoList, modelType, updateTestTodoList); try { await _ablemusicContext.SaveChangesAsync(); } catch (Exception e) { result.ErrorMessage = e.Message; result.IsSuccess = false; return(BadRequest(result)); } result.Data = updateTestTodoList; return(Ok(result)); }
public async Task <ActionResult <TestTodoList> > PostTodoList(TestTodoList testTodoList) { //Result<List<Product>> result = new Result<List<Product>>(); var result = new Result <object>(); try { await _ablemusicContext.TestTodoList.AddAsync(testTodoList); await _ablemusicContext.SaveChangesAsync(); //retrieve the new data with the ProductType and ProductCategory detail result.Data = testTodoList; } catch (Exception e) { result.ErrorMessage = e.Message; result.IsSuccess = false; result.IsFound = false; // _ablemusicContext.Remove(product); return(BadRequest(result)); } return(Ok(result)); }