コード例 #1
0
ファイル: HPFSMaster.Master.cs プロジェクト: tuneis/hps
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Submitted Feedback", (int)UserActionEnum.Created);

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

            try
            {
                // declare variables
                int    rec = Convert.ToInt32(radRec.SelectedValue);
                int    nav = Convert.ToInt32(radNav.SelectedValue);
                int    app = Convert.ToInt32(radAppear.SelectedValue);
                int    acc = Convert.ToInt32(radAccess.SelectedValue);
                double avg = (Convert.ToDouble(rec) + Convert.ToDouble(nav) + Convert.ToDouble(app) + Convert.ToDouble(acc)) / 4;

                // Create new entry and build it
                var fb = new FeedBack();
                fb.FeedBackAccRating = acc;
                fb.FeedBackAppRating = app;
                fb.FeedBackNavRating = nav;
                fb.FeedBackRecRating = rec;
                fb.FeedBackAvg       = avg;
                fb.FeedBackDate      = DateTime.Now.Date;
                fb.FeedBackComment   = txtComment.InnerText;
                fb.FeedBackArea      = ddlSiteArea.SelectedValue.ToString();

                // Add item to db and save changes
                db.Feedbacks.Add(fb);
                db.SaveChanges();

                // Create a notification for the database
                string[] role    = { "Administrator" };
                string   comment = "";
                if (txtComment.InnerText.Length >= 24)
                {
                    comment = txtComment.InnerText.Substring(0, 24);
                }
                else
                {
                    comment = txtComment.InnerText;
                }

                NotificationCreator.CreateNotification(role, "Feedback Submitted", "Comment: " + comment + "...", DateTime.Now, "Info", null, null);
            }
            catch (DataException dx)
            {
                // Display error to user and log it.
                lblFeedbackErrors.Text = "Your feedback failed to submit, please try again.\nIf the problem persists contact the administrator.";
                LogFile.WriteToFile("HPFSMaster.Master.cs", "btnSubmit_Click", dx, "Feedback failed to save in database", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                lblFeedbackErrors.Text = "Your feedback failed to submit, please try again.\nIf the problem persists contact the administrator.";
                LogFile.WriteToFile("HPFSMaster.Master.cs", "btnSubmit_Click", ex, "Feedback failed to submit", "HPSErrorLog.txt");
            }

            // reset feedback form values
            txtComment.Value        = "";
            radAccess.SelectedValue = "5";
            radAppear.SelectedValue = "5";
            radNav.SelectedValue    = "5";
            radRec.SelectedValue    = "5";
        }
コード例 #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");
            }
        }