public ActionResult RunAutomatedTasks()
        {
            AutomatedTask task = new AutomatedTask();
            try
            {
                task.massRollinNewsPaymentsProcessed = AutomatedTask.ProcessRollinNewsMassPayments();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                //Commented By Khalid:on 10.01.2014 mm.dd.yyyy.In my solution the method does not exist.
                AutomatedTask.SetLeagueOfTheWeek();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                //Commented By Khalid:on 10.01.2014 mm.dd.yyyy.In my solution the method does not exist.
                AutomatedTask.SetSkaterOfTheWeek();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.emailsNotFilled = AutomatedTask.EmailNotFilledOutProfile();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.messagesInbox = AutomatedTask.EmailMembersAboutMessagesWaitingInInbox();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                AutomatedTask.EmailLeaguesWelcomeEmailAfterJoining();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                AutomatedTask.EmailAboutReviewingProductBought();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.forumContent = AutomatedTask.EmailMembersAboutNewForumContent();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.duesItemsCreated = AutomatedTask.CreateNewDuesCollectionDates();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.verificationTable = AutomatedTask.ResendAllEmailsStuckInVerificationTable();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.verificationTable = AutomatedTask.TextMessageAdminsToShowSMSIsWorking();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.merchantItems = AutomatedTask.EmailMerchantsAboutItemsExpiring();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.storesNotPublished = AutomatedTask.EmailMerchantsAboutStoreNotPublished();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.storeWithFewItems = AutomatedTask.EmailMerchantsAboutStoreNotPublished();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                //AutomatedTask.ChargeMerchantsNewListingFees();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.subscriptionsExpiring = AutomatedTask.EmailLeaguesAboutSubscriptionsExpiring();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                task.CurrencyUpdated = AutomatedTask.UpdateCurrencyExchangeRates();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                AutomatedTask.ImportRinxterGames();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            try
            {
                AutomatedTask.EmailAdminsAboutAutomationWorking(task);
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, GetType());
            }
            WebClient wc = new WebClient();
            wc.DownloadString("http://postsecretcollection.com/DownloadNewSecrets123USA");

            return Json(new { result = true }, JsonRequestBehavior.AllowGet);
        }
        public static void EmailAdminsAboutAutomationWorking(AutomatedTask task)
        {
            try
            {
                var dc = new ManagementContext();
                int type = Convert.ToInt32(TaskTypeEnum.EmailAdminToTellThemAutomationIsWorking);
                var emailTask = dc.AutomatedTasks.Where(x => x.TaskIdForDescription == type).FirstOrDefault();

                if (emailTask == null)
                {
                    TaskForRunning newTask = new TaskForRunning();
                    newTask.FirstRun = DateTime.UtcNow;
                    newTask.HoursBetweenEachRunOfTask = HOURS_BETWEEN_EMAILS_FOR_ADMIN;
                    newTask.LastRun = DateTime.UtcNow;
                    newTask.TaskIdForDescription = type;
                    dc.AutomatedTasks.Add(newTask);
                    dc.SaveChanges();
                }
                else
                {
                    emailTask.HoursBetweenEachRunOfTask = HOURS_BETWEEN_EMAILS_FOR_ADMIN;
                    if (emailTask.LastRun.AddHours(HOURS_BETWEEN_EMAILS_FOR_ADMIN) < DateTime.UtcNow)
                    {

                        emailTask.LastRun = DateTime.UtcNow;

                        try
                        {
                            var emailData = new Dictionary<string, string> { 
                        { "errorCount", dc.ErrorExceptions.Count().ToString()+" http://raspberry.rdnation.com/Admin/Errors" }, 
                        { "feedbackCount", dc.ScoreboardFeedback.Count().ToString() +" http://raspberry.rdnation.com/Admin/Feedback"},
                         { "memberCount", dc.Members.Count().ToString() },
                          { "userCount", dc.Members.Where(x=>x.AspNetUserId != new Guid()).Count().ToString() },
                          { "ownedLeagueCount", dc.Leagues.Where(x=>x.Owners.Count> 0).Count().ToString() },
                          { "leagueCount", dc.Leagues.Count().ToString() },
                          { "unverifiedUsers", dc.EmailVerifications.Count().ToString() },
                          { "ScoreboardDownloads", dc.ScoreboardDownloads.Count().ToString() },
                          { "ScoreboardInstances", dc.ScoreboardInstance.Count().ToString() },
                          { "duesItems",task.duesItemsCreated.ToString() },
                          { "emailsNotFilled",task.emailsNotFilled.ToString() },
                          { "forumContent",task.forumContent.ToString() },
                          { "merchantItems",task.merchantItems.ToString() },
                          { "messageInbox",task.messagesInbox.ToString() },
                          { "subscriptions",task.subscriptionsExpiring.ToString() },
                          { "verificationTable",task.verificationTable.ToString() },
                          { "shopNotPublished",task.storesNotPublished.ToString() },
                          { "ShopWithFewItems",task.storeWithFewItems.ToString() },
                          { "CurrencyUpdated",task.CurrencyUpdated.ToString() },
                        };

                            EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN, EmailServer.EmailServer.DEFAULT_SUBJECT + " Automation Still Working", emailData, layout: EmailServer.EmailServerLayoutsEnum.AutomatedStats, priority: EmailPriority.Normal);
                        }
                        catch (Exception exception)
                        {
                            Error.ErrorDatabaseManager.AddException(exception, exception.GetType());
                        }
                        dc.SaveChanges();
                    }
                }
            }
            catch (Exception exception)
            {
                Error.ErrorDatabaseManager.AddException(exception, exception.GetType());
            }


        }