コード例 #1
0
ファイル: UserSettings.aspx.cs プロジェクト: tuneis/hps
        protected void btnSaveContact_Click(object sender, EventArgs e)
        {
            HelperMethods.ActivityTracker.Track("Saved New Contact Info", (int)UserActionEnum.Updated);

            try
            {
                // Grab current user ID
                string userId = HttpContext.Current.Session["UserId"].ToString();

                // Query database
                HPSUser user = db.HPSUsers.Where(u => u.UserId == userId).SingleOrDefault();

                // Update the information
                user.FirstName = txtFN.Text;
                user.LastName  = txtLN.Text;

                if (txtEmail.Text != user.AspNetUser.Email)
                {
                    user.AspNetUser.EmailConfirmed = false;
                }

                user.AspNetUser.Email = txtEmail.Text;

                if (txtPhone.Text != user.AspNetUser.PhoneNumber)
                {
                    user.AspNetUser.PhoneNumberConfirmed = false;
                }

                user.AspNetUser.PhoneNumber = txtPhone.Text;

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

                // Save to DB
                db.SaveChanges();

                // Display success message
                lblContactSuccess.Text = "<br><br>Contact Information Changes Saved.";
            }
            catch (DataException dx)
            {
                lblContactErrors.Text += "A data error occured, contact your administrator if this continues to happen.<br>";
                LogFile.WriteToFile("UserSettings.aspx.cs", "btnSaveContact_Click", dx, "Database failed to save updated contact information", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                lblContactErrors.Text += "An error occured, contact your administrator if this continues to happen.<br>";
                LogFile.WriteToFile("UserSettings.aspx.cs", "btnSaveContact_Click", ex, "Database failed to save updated contact information", "HPSErrorLog.txt");
            }
        }
コード例 #2
0
ファイル: FitBitMonitor.aspx.cs プロジェクト: tuneis/hps
        protected void PopulateStatistics(string userId, string statisticType)
        {
            HPSUser user = db.HPSUsers.Where(u => u.UserId == userId).SingleOrDefault();

            if (statisticType == "Steps")
            {
                // Get All Data
                int?     max     = db.Steps.Where(d => d.UserId.Contains(userId)).Max(s => (int?)s.StepCount);
                int?     sum     = db.Steps.Where(d => d.UserId.Contains(userId)).Sum(s => (int?)s.StepCount);
                double?  avg     = db.Steps.Where(d => d.UserId.Contains(userId)).Average(s => (double?)s.StepCount);
                int?     min     = db.Steps.Where(d => d.UserId.Contains(userId)).Where(s => s.StepCount > 0).Min(s => (int?)s.StepCount);
                int?     total   = db.Steps.Where(d => d.UserId.Contains(userId)).Count();
                DateTime?minDate = Convert.ToDateTime(db.Steps.Where(d => d.UserId.Contains(userId)).Min(d => d.StepDate));
                DateTime?maxDate = Convert.ToDateTime(db.Steps.Where(d => d.UserId.Contains(userId)).Max(d => d.StepDate));

                // Display Data
                lblStepsUserValue.Text         = (user == null) ? "All Users Combined" : user.FirstName + " " + user.LastName;
                lblStepsMaxValue.Text          = (max == 0 || max == null) ? "No data found." : ((int)max).ToString("N0");
                lblStepsSumValue.Text          = (sum == 0 || sum == null) ? "No data found." : ((int)sum).ToString("N0");
                lblStepsAvgValue.Text          = (avg == 0 || avg == null) ? "No data found." : ((double)avg).ToString("N0");
                lblStepsMinValue.Text          = (min == 0 || min == null) ? "No data found." : ((int)min).ToString("N0");
                lblStepsTotalRecordsValue.Text = (total == 1 || max == null) ? "No data found." : ((int)total) + " records";
                lblStepsDateRangeValue.Text    = (max == null || max == 0 || sum == null || sum == 0 || avg == null || avg == 0 || min == null || min == 0 || total == null || total == 1) ? "No data found." : ((DateTime)minDate).ToShortDateString() + " - " + ((DateTime)maxDate).ToShortDateString();
            }
            else if (statisticType == "Distances")
            {
                // Get All Data
                decimal? max     = db.Distances.Where(d => d.UserId.Contains(userId)).Max(s => (decimal?)s.DistanceCount);
                decimal? sum     = db.Distances.Where(d => d.UserId.Contains(userId)).Sum(s => (decimal?)s.DistanceCount);
                decimal? avg     = db.Distances.Where(d => d.UserId.Contains(userId)).Average(s => (decimal?)s.DistanceCount);
                decimal? min     = db.Distances.Where(d => d.UserId.Contains(userId)).Where(s => s.DistanceCount > 0).Min(s => (decimal?)s.DistanceCount);
                int?     total   = db.Distances.Where(d => d.UserId.Contains(userId)).Count();
                DateTime?minDate = Convert.ToDateTime(db.Distances.Where(d => d.UserId.Contains(userId)).Min(d => d.DistanceDate));
                DateTime?maxDate = Convert.ToDateTime(db.Distances.Where(d => d.UserId.Contains(userId)).Max(d => d.DistanceDate));

                // Display Data
                lblDistancesUserValue.Text           = (user == null) ? "All Users Combined" : user.FirstName + " " + user.LastName;
                lblDistancesMaxValue.Text            = (max == 0 || max == null) ? "No data found." : ((decimal)max).ToString("N2") + " km";
                lblDistancesSumValue.Text            = (sum == 0 || sum == null) ? "No data found." : ((decimal)sum).ToString("N2") + " km";
                lblDistancesAvgValue.Text            = (avg == 0 || avg == null) ? "No data found." : ((decimal)avg).ToString("N2") + " km";
                lblDistancesMinValue.Text            = (min == 0 || min == null) ? "No data found." : ((decimal)min).ToString("N2") + " km";
                lblDistancesTotalRecordsValue.Text   = (total == 1 || max == null) ? "No data found." : ((int)total) + " records";
                lblDistancesDateRangeEntryValue.Text = (max == null || max == 0 || sum == null || sum == 0 || avg == null || avg == 0 || min == null || min == 0 || total == null || total == 1) ? "No data found." : ((DateTime)minDate).ToShortDateString() + " - " + ((DateTime)maxDate).ToShortDateString();
            }
            else
            {
                // Get All Data
                decimal? max     = db.Minutes.Where(d => d.UserId.Contains(userId)).Max(s => (decimal?)s.MinuteCount);
                decimal? sum     = db.Minutes.Where(d => d.UserId.Contains(userId)).Sum(s => (decimal?)s.MinuteCount);
                decimal? avg     = db.Minutes.Where(d => d.UserId.Contains(userId)).Average(s => (decimal?)s.MinuteCount);
                decimal? min     = db.Minutes.Where(d => d.UserId.Contains(userId)).Where(s => s.MinuteCount > 0).Min(s => (decimal?)s.MinuteCount);
                int?     total   = db.Minutes.Where(d => d.UserId.Contains(userId)).Count();
                DateTime?minDate = Convert.ToDateTime(db.Minutes.Where(d => d.UserId.Contains(userId)).Min(d => d.MinuteDate));
                DateTime?maxDate = Convert.ToDateTime(db.Minutes.Where(d => d.UserId.Contains(userId)).Max(d => d.MinuteDate));

                // Display Data
                lblMinutesUserValue.Text         = (user == null) ? "All Users Combined" : user.FirstName + " " + user.LastName;
                lblMinutesMaxValue.Text          = (max == 0 || max == null) ? "No data found." : ((decimal)max).ToString("N0") + " min";
                lblMinutesSumValue.Text          = (sum == 0 || sum == null) ? "No data found." : ((decimal)sum).ToString("N0") + " min";
                lblMinutesAvgValue.Text          = (avg == 0 || avg == null) ? "No data found." : ((decimal)avg).ToString("N0") + " min";
                lblMinutesMinValue.Text          = (min == 0 || min == null) ? "No data found." : ((decimal)min).ToString("N0") + " min";
                lblMinutesTotalRecordsValue.Text = (total == 1 || max == null) ? "No data found." : ((int)total) + " records";
                lblMinutesDateRangeValue.Text    = (max == null || max == 0 || sum == null || sum == 0 || avg == null || avg == 0 || min == null || min == 0 || total == null || total == 1) ? "No data found." : ((DateTime)minDate).ToShortDateString() + " - " + ((DateTime)maxDate).ToShortDateString();
            }
        }