コード例 #1
0
        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());
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        public async Task DeleteAsync(int id)
        {
            await _repository.DeleteAsync(id);

            await _unitOfWork.SaveChangesAsync();
        }