public async Task ExecuteAsync(DeleteEntityCommand command) { if (!command.Validate()) { AddNotification(command.GetNotifications()); return; } AddNotification(partnerRepository.Get().Any(x => x.Id == command.Id), "Partner Id Not Found"); if (!IsValid) { return; } try { await partnerRepository.DeleteAsync(partnerRepository.Get(x => x.Id == command.Id).FirstOrDefault()); } catch (Exception ex) { logger.LogError(ex.Message, ex); AddNotification(ex.Message, System.Net.HttpStatusCode.InternalServerError); } }
public async Task <IActionResult> DeletePartner(int?id) { try { if (id == null) { throw new Exception(); } var item = await _partnerRepository.GetByIdAsync(id.Value); if (item == null) { throw new Exception(); } var result = await _partnerRepository.DeleteAsync(item); if (!result) { throw new Exception("Failed to delete."); } var notify = _notificationHelper.DeleteOldByIdAsync(item.PartnerGuidId); return(RedirectToAction(nameof(PremiumIndex))); } catch (Exception) { return(new NotFoundViewResult("_Error404")); } }
public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } try { var partner = await _partnerRepository.GetByIdAsync(id.Value); if (partner == null) { return(NotFound()); } var flight = _flightRepository.GetAll() .Where(f => f.FlightCompanyId == partner.Id) .FirstOrDefault(); if (flight != null) { return(StatusCode(400, "Please delete all flights that use this company first!")); } await _partnerRepository.DeleteAsync(partner); return(StatusCode(200, "Success")); } catch (Exception) { return(StatusCode(520, "Unknown Error.")); } }
public async Task <IActionResult> DeleteConfirmed(int id) { var partner = await _partnerRepository.GetByIdAsync(id); await _partnerRepository.DeleteAsync(partner); return(RedirectToAction(nameof(Index))); }
public bool DeleteAsync(int id) { if (id <= 0) { throw new ArgumentException("id错误"); } return(_partnerRepository.DeleteAsync(id)); }
public async Task DeleteAsync(Guid partnerId) { var partner = await _partnerRepository.GetByIdAsync(partnerId); if (partner == null) { return; } var asyncActions = new List <Task>(); partner.Locations?.ForEach(l => { asyncActions.Add(DeleteContactPerson(l)); }); await Task.WhenAll(asyncActions); await _partnerRepository.DeleteAsync(partnerId); }
public async Task <IActionResult> DeletePartner(int id) { try { var partner = await _partnerRepository.GetByIdAsync(id); if (partner == null) { throw new Exception(); } var result = await _partnerRepository.DeleteAsync(partner); return(RedirectToAction("PartnersIndex")); } catch (Exception) { return(new NotFoundViewResult("_Error500")); } }