Example #1
0
        // Update Contact & Hours Information
        protected void btnSaveAdminSettings_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Administrator Settings Changed", (int)UserActionEnum.Updated);

            // Clear error label
            lblAdminSettingsErrors.Text = "";

            // Load Administrator Settings Modal Data To Update it
            Contact info = db.Contacts.Find(1);

            // Contact Information
            info.Address   = txtAddress.Text;
            info.Company   = txtCompany.Text;
            info.Email     = txtEmail.Text;
            info.Fax       = txtFax.Text;
            info.Telephone = txtTelephone.Text;

            // Office Hours
            info.Monday    = txtMonday.Text;
            info.Tuesday   = txtTuesday.Text;
            info.Wednesday = txtWednesday.Text;
            info.Thursday  = txtThursday.Text;
            info.Friday    = txtFriday.Text;
            info.Saturday  = txtSaturday.Text;
            info.Sunday    = txtSunday.Text;

            // Banner Message
            info.BannerMessage = txtBanner.Text;
            info.BannerColor   = colorPicker.Attributes["value"];

            try
            {
                // Change the entry state
                db.Entry(info).State = System.Data.Entity.EntityState.Modified;

                // Save to DB
                db.SaveChanges();

                // Create a notification for the database
                string[] role = { "Everyone" };
                NotificationCreator.CreateNotification(role, "Information Updated", "Contact Info and Hours Changed", DateTime.Now, "Info", null, null);

                // To add new info to page
                Response.Redirect(Request.RawUrl);
            }
            catch (DataException dx)
            {
                // Display error to user and log it.
                lblAdminSettingsErrors.Text = "The changes you made failed to save, please try again.\nIf the problem persists contact the administrator.";
                LogFile.WriteToFile("HPFSMaster.Master.cs", "btnSaveAdminSettings_Click", dx, "Admin Settings Information change failed to save in db", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                lblAdminSettingsErrors.Text = "The changes you made failed to save, please try again.\nIf the problem persists contact the administrator.";
                LogFile.WriteToFile("HPFSMaster.Master.cs", "btnSaveAdminSettings_Click", ex, "Admin Settings Information failed to update", "HPSErrorLog.txt");
            }
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ActivityTracker.Track("FitBit Manager", (int)UserActionEnum.Navigated);
            if (Page.User.Identity.IsAuthenticated && Session["UserId"] != null)
            {
                // Find the HPSUser that is currently logged in
                string userId = Session["UserId"].ToString();

                // There are no session cookies for this user, callback and repopulate the session
                if (Session["FitbitAuthToken"] == null || Session["FitbitAuthTokenSecret"] == null || Session["FitbitUserId"] == null)
                {
                    FitBit.FitBit.Callback();
                }

                if (!IsPostBack)
                {
                    try
                    {
                        HPSUser user = db.HPSUsers.Where(u => u.AspNetUser.Id == userId).SingleOrDefault();

                        // Check if the fitbituserId for this user has been set, if not set it
                        if (user.FitBitUserId == null)
                        {
                            string fitBitUserId = Session["FitbitUserId"].ToString();
                            user.FitBitUserId = fitBitUserId;

                            db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                            db.SaveChanges();
                        }
                    }
                    catch (DataException dx)
                    {
                        LogFile.WriteToFile("FitBitManager.aspx.cs", "Page_Load", dx, "The system failed when trying to automatically set the current user's FitBitId.", "HPSErrorLog.txt");
                    }
                    catch (Exception ex)
                    {
                        LogFile.WriteToFile("FitBitManager.aspx.cs", "Page_Load", ex, "The system failed when trying to automatically set the current user's FitBitId.", "HPSErrorLog.txt");
                    }

                    // Automatically Synchronize fitbit data and load the rest of the data
                    UploadFitBitData();

                    // Draw initial chart
                    DrawChart(this.Page, 7, "Steps");
                }

                // Load step, minutes, and distance data
                GetStepGoals();
                GetDistanceGoals();
                GetMinuteGoals();

                // Build tables for viewing all goals
                TableBuilder.BuildStepGoalsTable(tblStepGoals, userId);
                TableBuilder.BuildDistanceGoalsTable(tblDistanceGoals, userId);
                TableBuilder.BuildMinuteGoalsTable(tblMinuteGoals, userId);

                // Check if theres a notification
                if (notification)
                {
                    lblCRUDMessage.Text     = notificationMessage;
                    lblCRUDMessage.CssClass = notificationStyle;
                    notification            = false;

                    // Draw initial chart
                    DrawChart(this.Page, 7, "Steps");
                }
            }
            else
            {
                Response.Redirect("/Main.aspx");
            }
        }