public async Task <IActionResult> Delete(long typeId, long id) { var billType = await _billTypeRepo.GetAsync(typeId); if (billType == null) { return(NotFound(Resources.Bills.BillResource.BillTypeNotFound)); } var bill = await _billRepo.GetAsync(billType.Id, id); if (bill == null) { return(NotFound(Resources.Bills.BillResource.BillNotFound)); } var affectedRows = await _billRepo.DeleteAsync(bill); if (affectedRows == -1) { return(BadRequest(Resources.Bills.BillResource.CanNotDeleteBill)); } if (affectedRows > 0) { var viewModel = AutoMapper.Mapper.Map <BillViewModel>(bill); return(Ok(viewModel)); } return(BadRequest()); }
/// <summary> /// Delete water meter and bills associated /// </summary> /// <param name="waterMeter"></param> /// <returns></returns> public async Task DeleteWaterMeterWithBills(WaterMeter waterMeter) { foreach (var bill in waterMeter.Bills) { await _billRepository.DeleteAsync(bill); } await DeleteAsync(waterMeter); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <bool> Handle(DeleteBillCommand request, CancellationToken cancellationToken) { var bill = await _repository.GetAsync(request.BillId, cancellationToken); if (bill == null) { return(false); } await _repository.DeleteAsync(bill.Id, cancellationToken); await _repository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return(true); }
public async Task DeleteAsync(int id) { await _repository.DeleteAsync(id); await _unitOfWork.SaveChangesAsync(); }