public async Task <IActionResult> Delete([FromBody] DeleteRecipientInput deleteRecipientInput) { var apiResponse = new ApiResponse(); if (!this.ModelState.IsValid) { apiResponse.IsSuccessful = false; return(this.BadRequest(apiResponse)); } try { apiResponse = await this.recipientService.DeleteRecipient(deleteRecipientInput); 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 })); } }
/// <inheritdoc /> /// <summary> /// The delete recipient. /// </summary> /// <param name="deleteRecipientInput"> /// The delete recipient input. /// </param> /// <returns> /// The <see cref="T:System.Threading.Tasks.Task" />. /// </returns> public async Task <ApiResponse> DeleteRecipient(DeleteRecipientInput deleteRecipientInput) { foreach (var recipientNo in deleteRecipientInput.RecipientNo) { var recipient = await this.recipientRepository.FindById(recipientNo); if (recipient == null) { continue; } recipient.IsDeleted = true; this.recipientRepository.Update(recipient); } await this.recipientRepository.SaveChanges(); return(new ApiResponse { IsSuccessful = true, Message = "Recipient Deleted" }); }
public void DeleteRecipient(DeleteRecipientInput input) { _recipientRepository.Delete(p => p.Id == input.RecipientId); }