public async Task <IActionResult> PutNonBills(int id, ApiNonBills nonBills) { if (id != nonBills.NonBillId) { return(BadRequest("Non-bill does not exist.")); } var resource = new CoreNonBills { NonBillId = nonBills.NonBillId, Price = nonBills.Price, StoreName = nonBills.StoreName, User = await _userRepo.GetUserById(nonBills.UserId) }; try { await _repo.UpdateNonBillAsync(resource); } catch (DbUpdateConcurrencyException) { if (!await _repo.NonBillExistAsync(id)) { return(NotFound("Non-bill does not exist.")); } else { throw; } } return(Ok("Non-bill updated!")); }
public async Task <ActionResult> PostNonBills(ApiNonBills nonBills) { try { var resource = new CoreNonBills { NonBillId = nonBills.NonBillId, Price = nonBills.Price, StoreName = nonBills.StoreName, User = await _userRepo.GetUserById(nonBills.UserId) }; await _repo.AddNonBillAsync(resource); return(Ok("Non-bill has been added!")); } catch (Exception e) { return(BadRequest(e.Message)); } }