public async Task <IActionResult> DeleteVendor([FromRoute] int id) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await _vendorRepository.VendorExistsAsync(id)) { return(NotFound()); } var wasVendorDeleted = await _vendorRepository.DeleteVendorAsync(id); if (wasVendorDeleted) { return(Ok()); } return(NoContent()); } catch (Exception e) { _logger.LogCritical($"DELETE {Route}/{id} - {e.GetType().Name} - {e.Message} - {e.StackTrace}"); return(StatusCode(500, "An error ocurred in server")); } }
public async Task <ActionResult> DeleteVendorAsync(string id) { var vendorFromService = _service.GetVendorAsync(id); if (vendorFromService == null) { return(NotFound()); } await _service.DeleteVendorAsync(id).ConfigureAwait(false); return(NoContent()); }
internal async Task <bool> DeleteVendorAsync(string vendorName) { Vendor vendor = await vendorRepository.Vendors.FirstOrDefaultAsync(x => x.Name == vendorName); if (vendor != null) { try { await vendorRepository.DeleteVendorAsync(vendor); return(true); } catch (Exception) { return(false); } } else { return(false); } }