public async Task <IActionResult> Delete(int id) { try { var databarang = await _detailBeli.sortbyidbeli(id); foreach (var barang in databarang) { var getdetailpembelian = await _detailBeli.getbyid(barang.DetailBeliId); var datadetailbarang = await _Barang.GetById(barang.IdBarang); datadetailbarang.Stok = Convert.ToInt16(datadetailbarang.Stok - barang.Qty); await _detailBeli.Deletes(getdetailpembelian.DetailBeliId); await _Barang.UpdateAsync(datadetailbarang); } await _Beli.Delete(id); return(Ok("Data berhasil didelete")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
//[Authorize(Roles = "Admin")] public async Task <IActionResult> sortbeliid(int Id) { var model = await _DetailBeli.sortbyidbeli(Id); return(Ok(model)); }