Example #1
0
        /// <summary>
        /// Forces an update for the activity widgets
        /// </summary>
        public IEnumerable <Widget> ChangeWidgetActities(IEnumerable <Widget> widgets, int platformId)
        {
            //** Create new widgetDatas **//
            DataManager dataManager = new DataManager();

            //1st widget
            WidgetData loginData   = dataManager.GetUserActivitiesData(ActivityType.LoginActivity, DateTime.Now.AddDays(-30));
            Widget     loginWidget = widgets.Where(widget => widget.PropertyTags.All(tag => tag.Name.ToLower().Contains("login"))).SingleOrDefault();

            loginWidget.WidgetDatas = new List <WidgetData>
            {
                loginData
            };
            loginData.Widget = loginWidget;
            widgetRepo.CreateWidgetData(loginData);

            //2nd widget
            WidgetData registerData   = dataManager.GetUserActivitiesData(ActivityType.RegisterActivity, DateTime.Now.AddDays(-30));
            Widget     registerWidget = widgets.Where(widget => widget.PropertyTags.All(tag => tag.Name.ToLower().Contains("register"))).SingleOrDefault();

            loginWidget.WidgetDatas = new List <WidgetData>
            {
                loginData
            };
            registerData.Widget = registerWidget;
            widgetRepo.CreateWidgetData(registerData);

            //3rd widget
            WidgetData visitData   = dataManager.GetUserActivitiesData(ActivityType.VisitActitiy, DateTime.Now.AddDays(-30));
            Widget     visitWidget = widgets.Where(widget => widget.PropertyTags.All(tag => tag.Name.ToLower().Contains("visit"))).SingleOrDefault();

            loginWidget.WidgetDatas = new List <WidgetData>
            {
                loginData
            };
            visitData.Widget = visitWidget;
            widgetRepo.CreateWidgetData(visitData);

            //Get last updated
            SubplatformManager platformManager = new SubplatformManager();
            SubPlatform        platform        = platformManager.GetSubPlatform(platformId);

            platform.LastUpdatedActivities = DateTime.Now;
            platformManager.ChangeSubplatform(platform);

            return(widgets);
        }
        /// <summary>
        /// Generate alerts for the weekly review
        /// </summary>
        public bool GenerateAlertsForWeeklyReview(int platformId)
        {
            InitRepo();

            //Get timepstamp for weekly review
            SubplatformManager platformManager = new SubplatformManager();
            SubPlatform        platform        = platformManager.GetSubPlatform(platformId);

            if (platform.LastUpdatedWeeklyReview != null && platform.LastUpdatedWeeklyReview > DateTime.Now.AddDays(-7))
            {
                return(false);
            }

            platform.LastUpdatedWeeklyReview = DateTime.Now;
            platformManager.ChangeSubplatform(platform);

            //Get all users
            IEnumerable <User> users = userRepo.ReadAllUsersWithAlerts();

            if (users == null || users.Count() == 0)
            {
                return(false);
            }

            //Generate weekly review alerts
            foreach (User user in users)
            {
                UserAlert alert = new UserAlert()
                {
                    User      = user,
                    Subject   = "Nieuwe Weekly Review",
                    IsRead    = false,
                    TimeStamp = DateTime.Now,
                    AlertType = AlertType.Weekly_Review
                };
                user.Alerts.Add(alert);
            }

            //Update database & send emails
            SendWeeklyReviewEmails(platformId, users.Where(user => user.AlertsViaEmail));
            userRepo.UpdateUsers(users);
            return(true);
        }