public async Task <JsonResult> OnPostCreateOrEditAsync(int id, Customer customer) { if (ModelState.IsValid) { if (id == 0) { await _customer.AddAsync(customer); await _unitOfWork.Commit(); } else { await _customer.UpdateAsync(customer); await _unitOfWork.Commit(); } Customers = await _customer.GetAllAsync(); var html = await _renderService.ToStringAsync("_ViewAll", Customers); return(new JsonResult(new { isValid = true, html = html })); } else { var html = await _renderService.ToStringAsync("_CreateOrEdit", customer); return(new JsonResult(new { isValid = false, html = html })); } }
public async Task <IActionResult> Put(int id, [FromBody] Customer customer) { if (id != customer.Id) { return(BadRequest()); } await customerRepository.UpdateAsync(customer); return(NoContent()); }