Exemplo n.º 1
0
        public async Task <IActionResult> Delete([FromBody] DeleteInvoiceInput deleteInvoiceInput)
        {
            var apiResponse = new ApiResponse();

            if (!this.ModelState.IsValid)
            {
                apiResponse.IsSuccessful = false;

                return(this.BadRequest(apiResponse));
            }

            try
            {
                apiResponse = await this.invoiceService.DeleteInvoice(deleteInvoiceInput);

                if (apiResponse.IsSuccessful)
                {
                    return(this.Ok(apiResponse));
                }

                return(this.BadRequest(apiResponse));
            }
            catch (Exception exception)
            {
                return(this.StatusCode(
                           500,
                           new ApiResponse
                {
                    IsSuccessful = false,
                    Message = exception.InnerException.Message
                }));
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        /// The delete invoice.
        /// </summary>
        /// <param name="deleteInvoiceInput">
        /// The delete Invoice Input.
        /// </param>
        /// <returns>
        /// The <see cref="T:System.Threading.Tasks.Task" />.
        /// </returns>
        public async Task <ApiResponse> DeleteInvoice(DeleteInvoiceInput deleteInvoiceInput)
        {
            foreach (var invoiceId in deleteInvoiceInput.InvoiceIds)
            {
                var invoice = await this.invoiceRepository.FindById(invoiceId);

                if (invoice == null)
                {
                    continue;
                }

                invoice.IsDeleted = true;

                this.invoiceRepository.Update(invoice);
            }

            await this.invoiceRepository.SaveChanges();

            return(new ApiResponse
            {
                IsSuccessful = true,
                Message = "Invoice Deleted"
            });
        }