public IActionResult DeleteEquipment(string id) { _logger.LogDebug(LoggingEvents.HttpPost, "Begin method " + this.GetType().Name + "." + MethodBase.GetCurrentMethod().ReflectedType.Name); if (!string.IsNullOrEmpty(id) && Guid.TryParse(id, out Guid equipmentId)) { MicrosoftDynamicsCRMbcgovEquipment equipment = _dynamicsClient.GetEquipmentById(equipmentId); if (equipment == null) { _logger.LogWarning(LoggingEvents.NotFound, "Equipment NOT found."); return(new NotFoundResult()); } // TODO - add this routine. /* * if (!UserDynamicsExtensions.CurrentUserHasAccessToEquipment(equipmentId, _httpContextAccessor, _dynamicsClient)) * { * _logger.LogWarning(LoggingEvents.NotFound, "Current user has NO access to the equipment."); * return new NotFoundResult(); * } */ // delete the equipment try { _dynamicsClient.Equipments.Delete(equipmentId.ToString()); _logger.LogDebug(LoggingEvents.HttpDelete, "Equipment deleted: " + equipmentId.ToString()); } catch (OdataerrorException odee) { _logger.LogError(LoggingEvents.Error, "Error deleting the equipment: " + equipmentId.ToString()); _logger.LogError("Request:"); _logger.LogError(odee.Request.Content); _logger.LogError("Response:"); _logger.LogError(odee.Response.Content); throw new OdataerrorException("Error deleting the account: " + equipmentId.ToString()); } _logger.LogDebug(LoggingEvents.HttpDelete, "No content returned."); return(NoContent()); // 204 } else { return(BadRequest()); } }