예제 #1
0
        public async Task <IActionResult> DeleteAsync(int id)
        {
            var parameters = new Dictionary <string, object>();

            parameters.Add("Method", "DeleteAsync");

            try
            {
                // Does the dashboard exist?
                var dashboard = await _dashboardService.GetAsync(id);

                if (dashboard == null)
                {
                    throw new ApiException(string.Format("Unable to find a dashboard record with ID of '{0}'.", id));
                }

                // Delete the corresponding rule from the Twitter API, by using the TwitterRuleId property in the dashboard.
                await _twitterApiRuleService.DeleteRuleAsync(new List <string> {
                    dashboard.TwitterRuleId
                });

                // Delete the dashboard from the database.
                await _dashboardService.DeleteAsync(dashboard.Id);



                // Send the fact that a dashboard has been deleted to the clients connected through SignalR.
                await _blashHub.DeleteDashboardAsync(id, _hostApplicationLifetime.ApplicationStopping);

                return(Json(new { Success = true }));
            }
            catch (Exception exception)
            {
                // Returns a 500 error and logs the exception.
                _logger.LogWithParameters(LogLevel.Error, exception, exception.Message, parameters);
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;

                return(Json(new { error = new { code = Response.StatusCode, message = exception.Message } }));
            }
        }