Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ActivityTracker.Track("Contact Us", (int)UserActionEnum.Navigated);

            // Dynamically change contact and hours fields
            Contact data = db.Contacts.Where(u => u.Id == 1).SingleOrDefault();

            // Mobile Hours
            hours3.InnerHtml = "<p><b>Monday: </b>" + data.Monday + "</p>"
                               + "\n<p><b>Tuesday: </b>" + data.Tuesday + "</p>\n<p><b>Wednesday: </b>" + data.Wednesday + "</p>"
                               + "\n<p><b>Thursday: </b>" + data.Thursday + "</p>\n<p><b>Friday: </b>" + data.Friday + "</p>"
                               + "\n<p><b>Saturday: </b>" + data.Saturday + "</p>\n<p><b>Sunday: </b>" + data.Sunday + "</p>";

            // Set tooltips
            tt1.Title = data.Sunday;
            tt2.Title = data.Monday;
            tt3.Title = data.Tuesday;
            tt4.Title = data.Wednesday;
            tt5.Title = data.Thursday;
            tt6.Title = data.Friday;
            tt7.Title = data.Saturday;

            // Contact info
            contact3.InnerHtml = "<h3 style='font-weight: 400;'>" + data.Company + "</h3>\n"
                                 + "<h5>" + data.Address + "</h5>\n<h5 class='call'><b>Telephone: </b>"
                                 + "<a href='tel:" + data.Telephone + "'>" + data.Telephone + "</a></h5>\n"
                                 + "<h5 class='callOff'><b>Telephone: </b>" + data.Telephone + "</h5>\n"
                                 + "<h5><b>Fax: </b>" + data.Fax + "</h5>\n"
                                 + "<h5><b>Email: </b><a href='mailto:" + data.Email + "' class='mail'>" + data.Email + "</a></h5>";
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ActivityTracker.Track("Dashboard", (int)UserActionEnum.Navigated);
            if (Page.User.Identity.IsAuthenticated && Session["UserId"] != null)
            {
                if (!Page.User.IsInRole("Administrator"))
                {
                    pnlUserManager.Visible      = false;
                    pnlSlideShowManager.Visible = false;
                    pnlFeedbackManager.Visible  = false;
                    pnlActivityTracker.Visible  = false;
                    pnlFitBitMonitor.Visible    = false;
                    pnlProgramsManager.Visible  = false;
                }

                // Grab current user Id
                string userId = Session["UserId"].ToString();


                // Query the db and grab the data using the Id
                HPSUser user = db.HPSUsers.Where(u => u.UserId == userId).SingleOrDefault();

                // Display first name in the dashboard h1 tag
                welcome.InnerText = "Welcome " + user.FirstName + " " + user.LastName + "!";
            }
            else
            {
                Response.Redirect("/Main.aspx");
            }
        }
Ejemplo n.º 3
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Logged In", (int)UserActionEnum.LoggedIn);

            //declare the collection of users
            UserStore <IdentityUser> userStore = new UserStore <IdentityUser>();

            //declare the user manager
            UserManager <IdentityUser> manager = new UserManager <IdentityUser>(userStore);

            //try to find the user
            IdentityUser user = manager.Find(txtUsername.Text, txtPassword.Text);

            if (user == null)
            {
                lblMessage.Text = "Username or Password is incorrect";
            }
            else
            {
                //authenticate user
                var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                var userIdentity          = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                authenticationManager.SignIn(userIdentity);

                Session["UserId"] = user.Id;
                Response.Redirect("/Pages/Dashboard.aspx");
            }
        }
Ejemplo n.º 4
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");
            }
        }
Ejemplo n.º 5
0
        protected void btnContactSend_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Sent Contact Email", (int)UserActionEnum.Created);

            // Create an info object to dynamically set email address
            Contact info = db.Contacts.Find(1);

            using (MailMessage mm =
                       new MailMessage(ConfigurationManager.AppSettings["Email"], info.Email))
            {
                mm.Subject    = txtContactSubject.Text;
                mm.Body       = "Reply Address: " + txtContactEmail.Text + "\n\n" + tarContactMessage.InnerText;
                mm.IsBodyHtml = false;
                SmtpClient smtp = new SmtpClient();
                smtp.Host      = "smtp-mail.outlook.com";
                smtp.EnableSsl = true;

                NetworkCredential NetworkCred =
                    new NetworkCredential(ConfigurationManager.AppSettings["Email"],
                                          ConfigurationManager.AppSettings["Password"]);

                smtp.UseDefaultCredentials = true;
                smtp.Credentials           = NetworkCred;
                smtp.Port = 587;

                try
                {
                    // Clear error label
                    lblContactFormErrors.Text = "";

                    // try sending email
                    smtp.Send(mm);

                    // Create a notification for the database
                    string[] role = { "Administrator" };
                    NotificationCreator.CreateNotification(role, "Contact Email Sent", "Subject: " + txtContactSubject.Text, DateTime.Now, "Info", null, null);

                    // Alert user of success
                    ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Your email has been successfully sent. We will get back to you as soon as possible.');", true);
                }
                catch (SmtpException se)
                {
                    lblContactFormErrors.Text += "Email failed to send try again. You may have reached your daily limit. "
                                                 + "If the problem persists contact your administrator.";

                    LogFile.WriteToFile("HPFSMaster.Master.cs", "btnContactSend_Click", se, "Contact email failed to send.", "HPSErrorLog.txt");
                }
                catch (Exception ex)
                {
                    lblContactFormErrors.Text += " An error occured try again. If the problem persists contact your administrator.<br>";
                    LogFile.WriteToFile("HPFSMaster.Master.cs", "btnContactSend_Click", ex, "Error caused Contact email to fail.", "HPSErrorLog.txt");
                }
            }
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ActivityTracker.Track("Home", (int)UserActionEnum.Navigated);

            if (Session["login"] != null)
            {
                // Open the login modal
                ScriptManager.RegisterStartupScript(this, this.GetType(), "loginModal", "$('#mdlLogin').modal('show');", true);
                Session["login"] = null;
            }
        }
Ejemplo n.º 7
0
        protected void btnMinutes_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Viewed the Minutes Fitbit Data", (int)UserActionEnum.Clicked);
            // Get button that was clicked
            HtmlButton edit = (HtmlButton)sender;

            // Get id from button
            int dayCount = Convert.ToInt32(edit.Attributes["data-id"]);

            // Morph graph to appropriate day count
            DrawChart(this.Page, dayCount, "Minutes");
        }
Ejemplo n.º 8
0
        public static void DownloadFile(int id)
        {
            ActivityTracker.Track("Downloaded a File", (int)UserActionEnum.Downloaded);
            // Get the file from the database
            var file = db.HPSFiles.Select(s => s)
                       .Where(f => f.Id == id)
                       .SingleOrDefault();

            // Turn data into byte array
            fileToBeDownloaded = file.FileData;
            fileContentType    = file.FileContentType;
            fileName           = file.FileName;
        }
Ejemplo n.º 9
0
        protected void btnUploadData_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Added Their Fitbit Data to the DB", (int)UserActionEnum.Created);
            // Upload fitbit data
            UploadFitBitData();

            // Repopulate goals
            GetStepGoals();
            GetDistanceGoals();
            GetMinuteGoals();

            // Redraw the initial chart
            DrawChart(this.Page, 7, "Steps");
        }
Ejemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ActivityTracker.Track("User Manager", (int)UserActionEnum.Navigated);

            if (Page.User.Identity.IsAuthenticated && Session["UserId"] != null && Page.User.IsInRole("Administrator"))
            {
                // Get the user id thats currently logged in
                userId = HttpContext.Current.Session["UserId"].ToString();
                user   = db.HPSUsers.Select(u => u)
                         .Where(uid => uid.UserId == userId)
                         .SingleOrDefault();
            }
            else
            {
                Response.Redirect("/Main.aspx");
            }
        }
Ejemplo n.º 11
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Uploaded a File", (int)UserActionEnum.Created);
            UploadFile.Upload(NewFile, ddlUploadFileFolder, lblCRUDMessage);

            // Repopulate the notifications table
            Table  table  = (Table)Master.FindControl("tblNotifications");
            string userId = HttpContext.Current.Session["UserId"].ToString();

            TableBuilder.BuildNotificationTable(userId, table);

            // Rebuild folders
            BuildFolders();

            // Rebuild modals to go with folders for CRUD
            BuildModals();
        }
Ejemplo n.º 12
0
        public static void DeleteMinuteGoal(int id)
        {
            ActivityTracker.Track("Deleted a Minutes Goal", (int)UserActionEnum.Deleted);
            // Get the user id thats currently logged in
            string userId = HttpContext.Current.Session["UserId"].ToString();
            var    user   = db.HPSUsers.Select(u => u)
                            .Where(uid => uid.UserId == userId)
                            .SingleOrDefault();

            try
            {
                // Get the distance goal to be deleted
                MinuteGoal minuteGoal = db.MinuteGoals.Find(id);
                db.MinuteGoals.Remove(minuteGoal);

                // Save changes
                db.SaveChanges();

                // Set the notification
                notificationMessage = "Minute Goal was successfully deleted.";
                notificationStyle   = "text-success";
                notification        = true;
            }
            catch (DataException dx)
            {
                // Set the notification
                notificationMessage = "Minute Goal could not be deleted at this time. Please try again later or inform an Administrator.";
                notificationStyle   = "text-danger";
                notification        = true;

                // Write error to log file Log File Writer
                LogFile.WriteToFile("FitBitManager.aspx.cs", "DeleteMinuteGoal", dx, user.AspNetUser.UserName + " tried to delete a Minute Goal.", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                // Set the notification
                notificationMessage = "Minute Goal could not be deleted at this time. Please try again later or inform an Administrator.";
                notificationStyle   = "text-danger";
                notification        = true;

                // Write error to log file Log File Writer
                LogFile.WriteToFile("FitBitManager.aspx.cs", "DeleteMinuteGoal", ex, user.AspNetUser.UserName + " tried to delete a Minute Goal.", "HPSErrorLog.txt");
            }
        }
Ejemplo n.º 13
0
        protected void btnRemoveAllGoals_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Removed ALL Their Fitbit Goals", (int)UserActionEnum.Deleted);
            // Get userId from session
            string userId = Session["UserId"].ToString();

            try
            {
                // Remove all related goal records
                db.MinuteGoals.RemoveRange(db.MinuteGoals.Where(c => c.UserId == userId));
                db.DistanceGoals.RemoveRange(db.DistanceGoals.Where(c => c.UserId == userId));
                db.StepGoals.RemoveRange(db.StepGoals.Where(c => c.UserId == userId));
                db.SaveChanges();

                // Show message to user
                lblCRUDMessage.Text     = "All goals have been removed.";
                lblCRUDMessage.CssClass = "text-success";
            }
            catch (DataException dx)
            {
                lblCRUDMessage.Text     = "Unable to remove Goals at this time. Please try again later or inform an Administrator.";
                lblCRUDMessage.CssClass = "text-danger";
                LogFile.WriteToFile("FitBitManager.aspx.cs", "btnRemoveAllGoals_Click", dx, User.Identity.Name + " tried to remove all of their Goals.", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                lblCRUDMessage.Text     = "Unable to remove Goals at this time. Please try again later or inform an Administrator.";
                lblCRUDMessage.CssClass = "text-danger";
                LogFile.WriteToFile("FitBitManager.aspx.cs", "btnRemoveAllGoals_Click", ex, User.Identity.Name + " tried to remove all of their Goals.", "HPSErrorLog.txt");
            }

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

            // Redraw the initial graph
            DrawChart(this.Page, 7, "Steps");

            // Build tables for viewing all goals
            TableBuilder.BuildStepGoalsTable(tblStepGoals, userId);
            TableBuilder.BuildDistanceGoalsTable(tblDistanceGoals, userId);
            TableBuilder.BuildMinuteGoalsTable(tblMinuteGoals, userId);
        }
Ejemplo n.º 14
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Searched For User", (int)UserActionEnum.Clicked);
            db = new HPSDB();

            // Get the creation dates
            DateTime startDate = (txtSearchStartDate.Text != String.Empty) ? Convert.ToDateTime(txtSearchStartDate.Text) : DateTime.MinValue;
            DateTime endDate   = (txtSearchStartDate.Text != String.Empty) ? Convert.ToDateTime(txtSearchEndDate.Text) : DateTime.MaxValue;

            // Get the normal textboxes
            string firstName = (txtSearchFirstName.Text != String.Empty) ? txtSearchFirstName.Text : String.Empty;
            string lastName  = (txtSearchLastName.Text != String.Empty) ? txtSearchLastName.Text : String.Empty;
            string email     = (txtSearchEmail.Text != String.Empty) ? txtSearchEmail.Text : String.Empty;
            string username  = (txtSearchUserName.Text != String.Empty) ? txtSearchUserName.Text : String.Empty;
            string role      = (ddlSearchUserRole.SelectedValue != "-1") ? ddlSearchUserRole.SelectedValue : String.Empty;

            // Search based on criteria
            var users = db.HPSUsers
                        .Where(f => f.FirstName.Contains(firstName))
                        .Where(l => l.LastName.Contains(lastName))
                        .Where(em => em.AspNetUser.Email.Contains(email))
                        .Where(u => u.AspNetUser.UserName.Contains(username))
                        .Where(s => s.CreatedOn >= startDate && s.CreatedOn <= endDate)
                        .Where(a => a.RoleName.Contains(role))
                        .ToList();


            if (users.Any())
            {
                // Build the results table
                TableBuilder.BuildUsersTable(tblUsers, users, false);
            }
            else
            {
                lblNoResults.Visible = true;
                lblNoResults.Text    = "No results found.";
            }

            // Show the panel
            pnlSearchResults.Visible = true;
        }
Ejemplo n.º 15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ActivityTracker.Track("Programs", (int)UserActionEnum.Navigated);

            // Build the first visible carousel
            if (!IsPostBack)
            {
                CarouselBuilder.BuildCarousel(plCollectiveKitchen, (int)SlideShowEnums.CollectiveKitchen, "CollectiveKitchenCarousel");

                FillCollectiveKitchenTags();
                FillComputerTutoringTags();
                FillCottageStudioTags();
                FillWednesdayLeisureGroupTags();
                FillWalkingGroupTags();
                FillSummerSportsTags();
                FillTravellingCupTags();
                FillSweetDonationsGroupTags();
                FillMovieGroupTags();
                FillGamingGroupTags();
                FillFridaySocialGroupTags();
                FillOverview();
            }
        }
Ejemplo n.º 16
0
 protected void Page_Load(object sender, EventArgs e)
 {
     ActivityTracker.Track("Education And Research", (int)UserActionEnum.Navigated);
 }
Ejemplo n.º 17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     ActivityTracker.Track("About Us", (int)UserActionEnum.Navigated);
 }
Ejemplo n.º 18
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");
            }
        }
Ejemplo n.º 19
0
        public static void DeleteFile(int id)
        {
            ActivityTracker.Track("Deleted a File", (int)UserActionEnum.Deleted);
            // Get all files attached to folder
            HPSFile file = db.HPSFiles.Find(id);

            // Hold the folder name in a variable before it gets deleted
            string folderName = file.Folder.FolderName;
            string roles      = file.Folder.RoleName;

            string[] roleNamesArray = new string[1];


            // Check for multiple roles there will always be at least 1 role
            if (roles.Contains(','))
            {
                roleNamesArray = roles.Split(',');
            }
            else
            {
                roleNamesArray[0] = roles;
            }

            // Get the user id thats currently logged in
            string userId = HttpContext.Current.Session["UserId"].ToString();
            var    user   = db.HPSUsers.Select(u => u)
                            .Where(uid => uid.UserId == userId)
                            .SingleOrDefault();

            try
            {
                // Remove the file
                db.HPSFiles.Remove(file);

                // Save Changes to the database
                db.SaveChanges();

                // Create a notification for the database
                NotificationCreator.CreateNotification(roleNamesArray, "File Deleted", user.AspNetUser.UserName + " deleted '" + file.FileName + "' from the " + folderName + " folder.", DateTime.Now, "Info", id, null);

                // Set the delete flag and refresh the page so we can rebuild the folders/files
                deleteClicked = true;

                // Set the notification
                notificationMessage = "'" + file.FileName + "'  was successfully deleted.";
                notificationStyle   = "text-success";
                notification        = true;
            }
            catch (DataException dx)
            {
                // Set the notification
                notificationMessage = "'" + file.FileName + " could not be deleted at this time. Please try again later or inform an Administrator.";
                notificationStyle   = "text-danger";
                notification        = true;

                // Write error to log file Log File Writer
                LogFile.WriteToFile("FileManager.aspx.cs", "DeleteFile", dx, user.AspNetUser.UserName + "tried to delete a File named " + file.FileName, "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                // Set the notification
                notificationMessage = "'" + file.FileName + " could not be deleted at this time. Please try again later or inform an Administrator.";
                notificationStyle   = "text-danger";
                notification        = true;

                // Write error to log file Log File Writer
                LogFile.WriteToFile("FileManager.aspx.cs", "DeleteFile", ex, user.AspNetUser.UserName + "tried to delete a File named " + file.FileName, "HPSErrorLog.txt");
            }
        }
Ejemplo n.º 20
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Searched for a File", (int)UserActionEnum.Searched);
            // Get the user id thats currently logged in
            string userId = HttpContext.Current.Session["UserId"].ToString();
            var    role   = db.HPSUsers.Select(u => u)
                            .Where(uid => uid.UserId == userId)
                            .SingleOrDefault();

            // Parse the input
            DateTime startDate     = (txtSearchStartDate.Text != String.Empty) ? Convert.ToDateTime(txtSearchStartDate.Text) : DateTime.MinValue;
            DateTime endDate       = (txtSearchStartDate.Text != String.Empty) ? Convert.ToDateTime(txtSearchEndDate.Text) : DateTime.MaxValue;
            string   fileName      = (txtSearchFileName.Text != String.Empty) ? txtSearchFileName.Text : String.Empty;
            string   fileExtension = (ddlSearchFileType.SelectedValue != "-1") ? ddlSearchFileType.SelectedValue : String.Empty;
            string   folderName    = (ddlSearchFolders.SelectedValue != "-1") ? ddlSearchFolders.SelectedValue : String.Empty;

            // Declare list of HPS files
            List <HPSFileViewModel> files = new List <HPSFileViewModel>();

            //{ "#", "File Name", "Folder Name", "Size", "Type", "Date Uploaded", "Action" };
            // Check if admin is searching or other users
            if (role.RoleName == "Administrator")
            {
                // If role is admin, grab all the files
                files = db.HPSFiles
                        .Where(t => t.FileName.Contains(fileName) && t.FileExtension.Contains(fileExtension))
                        .Where(t => t.FileDate >= startDate && t.FileDate <= endDate)
                        .Where(t => t.Folder.FolderName.Contains(folderName))
                        .Select(file => new HPSFileViewModel {
                    Id = file.Id, FileName = file.FileName, FileSize = file.FileSize, FileExtension = file.FileExtension, FileDate = file.FileDate, Folder = file.Folder
                })
                        .OrderBy(date => date.FileDate)
                        .ToList();
            }
            else
            {
                // Search for files based on role the user is in
                files = db.HPSFiles
                        .Where(t => t.FileName.Contains(fileName) && t.FileExtension.Contains(fileExtension))
                        .Where(t => t.FileDate >= startDate && t.FileDate <= endDate)
                        .Where(t => t.RoleName.Contains(role.RoleName) || t.RoleName.Contains("Everyone"))
                        .Where(t => t.Folder.FolderName.Contains(folderName))
                        .Select(file => new HPSFileViewModel {
                    Id = file.Id, FileName = file.FileName, FileSize = file.FileSize, FileExtension = file.FileExtension, FileDate = file.FileDate, Folder = file.Folder
                })
                        .OrderBy(date => date.FileDate)
                        .ToList();
            }


            if (files.Count > 0)
            {
                TableBuilder.BuildSearchTable(tblFiles, files, role.RoleName);
                lblNoResults.Visible = false;
            }
            else
            {
                lblNoResults.Visible = true;
                lblNoResults.Text    = "No results found.";
            }

            // Show the search results panel
            pnlSearchResults.Visible = true;

            // Rebuild folders
            BuildFolders();

            // Rebuild modals to go with folders for CRUD
            BuildModals();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "showTab", "$.bootstrapSortable(true);", true);
        }
Ejemplo n.º 21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ActivityTracker.Track("File Manager", (int)UserActionEnum.Navigated);
            if (Page.User.Identity.IsAuthenticated && Session["UserId"] != null)
            {
                if (!User.IsInRole("Administrator"))
                {
                    divCreateFolder.Visible                = false;
                    divCreateFolderInfo.Visible            = false;
                    divSearchFiles.Attributes["class"]     = "col-xs-12";
                    divSearchFilesInfo.Attributes["class"] = "col-xs-12 text-center";
                }

                // Check if there is a file that needs to be download
                if (fileToBeDownloaded != null)
                {
                    // Send the file to the browser
                    HttpContext.Current.Response.AddHeader("Content-type", fileContentType);
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                    HttpContext.Current.Response.BinaryWrite(fileToBeDownloaded);
                    HttpContext.Current.Response.Flush();

                    // Reset the file data back to null before the response ends to avoid downloading files twice
                    fileToBeDownloaded = null;
                    fileContentType    = "";
                    fileName           = "";

                    // End the response
                    HttpContext.Current.Response.End();
                }

                // Display the users permission level on the page
                // Get the user id thats currently logged in
                bool   id     = Page.User.IsInRole("Administrator");
                string userId = HttpContext.Current.Session["UserId"].ToString();
                var    role   = db.HPSUsers.Select(u => u)
                                .Where(uid => uid.UserId == userId)
                                .SingleOrDefault();

                // Add access level to page
                HtmlGenericControl permissionLevel = new HtmlGenericControl("label");
                permissionLevel.InnerHtml = "Access Level: " + role.RoleName;
                plPermissionLevel.Controls.Add(permissionLevel);

                if (!IsPostBack || deleteClicked)
                {
                    // Build the drop down lists
                    PopulateFolderDropDownLists();

                    // Build folders
                    BuildFolders();

                    // Build modals to go with folders for CRUD
                    BuildModals();

                    // Create checkbox list depending on role of current user
                    CreateCheckBoxList();

                    // Set the flag for the delete button
                    deleteClicked = false;
                }

                // Check if theres a notification
                if (notification)
                {
                    lblCRUDMessage.Text     = notificationMessage;
                    lblCRUDMessage.CssClass = notificationStyle;
                    notification            = false;
                }
            }
            else
            {
                Response.Redirect("/Main.aspx");
            }
        }
Ejemplo n.º 22
0
        protected void btnCreateFolder_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Created a new Folder", (int)UserActionEnum.Created);
            // Check for existing folder to prevent duplicates
            var checkExistingFolder = db.Folders.Where(f => f.FolderName == txtFolderName.Text);

            if (!checkExistingFolder.Any())
            {
                // Create new instance of folder
                Folder folder = new Folder();

                try
                {
                    // Create variable to hold role names for trimming
                    string roleNames = "";

                    // Loop through checkbox list and add roles to rolename in folder
                    for (int i = 0; i < chkFolderPermissions.Items.Count; i++)
                    {
                        if (chkFolderPermissions.Items[i].Selected)
                        {
                            roleNames += chkFolderPermissions.Items[i].Value + ", ";
                        }
                    }

                    // Trim the trailing and leading comma's and extra spaces
                    char[] charsToTrim = { ',', ' ' };
                    folder.RoleName   = roleNames.Trim(charsToTrim);
                    folder.FolderName = txtFolderName.Text;

                    // Add userid to folder to see who created it
                    folder.UserId = Session["UserId"].ToString();

                    // Add new record to database and save
                    db.Folders.Add(folder);
                    db.SaveChanges();

                    // Hold the folder name in a variable before it gets added
                    string   folderName     = folder.FolderName;
                    string   roles          = folder.RoleName;
                    string[] roleNamesArray = new string[1];

                    // Check for multiple roles there will always be at least 1 role
                    if (roles.Contains(','))
                    {
                        roleNamesArray = roles.Split(',');
                    }
                    else
                    {
                        roleNamesArray[0] = roles;
                    }

                    // Repopulate the notifications table
                    string userId = HttpContext.Current.Session["UserId"].ToString();
                    var    user   = db.HPSUsers.Select(u => u)
                                    .Where(uid => uid.UserId == userId)
                                    .SingleOrDefault();

                    // Create a notification for the database
                    NotificationCreator.CreateNotification(roleNamesArray, "Folder Created", user.AspNetUser.UserName + " created the " + folderName + " folder.", DateTime.Now, "Info", null, null);

                    // Get the table from master page and repopulate
                    Table table = (Table)Master.FindControl("tblNotifications");
                    TableBuilder.BuildNotificationTable(userId, table);

                    // Rebuild folders
                    BuildFolders();

                    // Rebuild modals to go with folders for CRUD
                    BuildModals();

                    // Build the drop down lists
                    PopulateFolderDropDownLists();

                    // Set the notification
                    lblCRUDMessage.Text     = folder.FolderName + " folder was successfully created.";;
                    lblCRUDMessage.CssClass = "text-success";;
                }
                catch (DataException dx)
                {
                    // Set the notification
                    lblCRUDMessage.Text     = folder.FolderName + " folder could not be created at this time. Please try again later or inform an Administrator.";
                    lblCRUDMessage.CssClass = "text-danger";

                    // Write error to log file Log File Writer
                    LogFile.WriteToFile("FileManager.aspx.cs", "btnCreateFolder_Click", dx, User.Identity.Name + "tried to create a Folder named " + txtFolderName.Text + ".", "HPSErrorLog.txt");
                }
                catch (Exception ex)
                {
                    // Set the notification
                    lblCRUDMessage.Text     = folder.FolderName + " folder could not be created at this time. Please try again later or inform an Administrator.";
                    lblCRUDMessage.CssClass = "text-danger";

                    // Write error to log file Log File Writer
                    LogFile.WriteToFile("FileManager.aspx.cs", "btnCreateFolder_Click", ex, User.Identity.Name + "tried to create a Folder named " + txtFolderName.Text + ".", "HPSErrorLog.txt");
                }
            }
            else
            {
                // Set the error message and repopulate folders
                lblCRUDMessage.Text     = txtFolderName.Text + " already exists. Please choose another name.";
                lblCRUDMessage.CssClass = "text-danger";

                // Build the drop down list for folders in the modal
                PopulateFolderDropDownLists();

                // Build folders
                BuildFolders();

                // Build modals to go with folders for CRUD
                BuildModals();
            }
        }
Ejemplo n.º 23
0
        protected void btnSetNewGoal_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Created a New Goal", (int)UserActionEnum.Created);
            try
            {
                if (ddlGoalType.SelectedValue == "Steps")
                {
                    StepGoal sg = new StepGoal();
                    sg.GoalSteps     = Convert.ToInt32(txtGoal.Text);
                    sg.GoalStartDate = Convert.ToDateTime(txtGoalStartDate.Text) + new TimeSpan(0, 0, 0);
                    sg.GoalEndDate   = Convert.ToDateTime(txtGoalEndDate.Text) + new TimeSpan(0, 0, 0);
                    sg.UserId        = Session["UserId"].ToString();
                    db.StepGoals.Add(sg);
                    db.SaveChanges();

                    // Display message
                    lblCRUDMessage.Text     = "New Steps Goal saved.";
                    lblCRUDMessage.CssClass = "text-success";
                }
                else if (ddlGoalType.SelectedValue == "Distance")
                {
                    DistanceGoal dg = new DistanceGoal();
                    dg.GoalDistance  = Convert.ToDecimal(txtGoal.Text);
                    dg.GoalStartDate = Convert.ToDateTime(txtGoalStartDate.Text) + new TimeSpan(0, 0, 0);
                    dg.GoalEndDate   = Convert.ToDateTime(txtGoalEndDate.Text) + new TimeSpan(0, 0, 0);
                    dg.UserId        = Session["UserId"].ToString();
                    db.DistanceGoals.Add(dg);
                    db.SaveChanges();

                    // Display message
                    lblCRUDMessage.Text     = "New Distance Goal saved.";
                    lblCRUDMessage.CssClass = "text-success";
                }
                else if (ddlGoalType.SelectedValue == "Minutes")
                {
                    MinuteGoal mg = new MinuteGoal();
                    mg.GoalMinute    = Convert.ToDecimal(txtGoal.Text);
                    mg.GoalStartDate = Convert.ToDateTime(txtGoalStartDate.Text) + new TimeSpan(0, 0, 0);
                    mg.GoalEndDate   = Convert.ToDateTime(txtGoalEndDate.Text) + new TimeSpan(0, 0, 0);
                    mg.UserId        = Session["UserId"].ToString();
                    db.MinuteGoals.Add(mg);
                    db.SaveChanges();

                    // Display message
                    lblCRUDMessage.Text     = "New Minutes Goal saved.";
                    lblCRUDMessage.CssClass = "text-success";
                }

                // Reset copntrols
                txtGoal.Text              = "";
                txtGoalEndDate.Text       = "";
                txtGoalStartDate.Text     = "";
                ddlGoalType.SelectedValue = "-1";
            }
            catch (DataException dx)
            {
                lblCRUDMessage.Text     = "Goal could not be saved at this time. Please try again later or inform an Administrator.";
                lblCRUDMessage.CssClass = "text-danger";
                LogFile.WriteToFile("FitBitManager.aspx.cs", "btnSetNewGoal_Click", dx, User.Identity.Name + " tried to set a new goal.", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                lblCRUDMessage.Text     = "Goal could not be saved at this time. Please try again later or inform an Administrator.";
                lblCRUDMessage.CssClass = "text-danger";
                LogFile.WriteToFile("FitBitManager.aspx.cs", "btnSetNewGoal_Click", ex, User.Identity.Name + " tried to set a new goal.", "HPSErrorLog.txt");
            }

            // Rebuild the chart and step goals
            DrawChart(this.Page, 7, "Steps");
            GetStepGoals();
            GetDistanceGoals();
            GetMinuteGoals();

            // Build tables for viewing all goals
            string userId = Session["UserId"].ToString();

            TableBuilder.BuildStepGoalsTable(tblStepGoals, userId);
            TableBuilder.BuildDistanceGoalsTable(tblDistanceGoals, userId);
            TableBuilder.BuildMinuteGoalsTable(tblMinuteGoals, userId);
        }
Ejemplo n.º 24
0
 protected void Page_Load(object sender, EventArgs e)
 {
     ActivityTracker.Track("Rehab and Treatment", (int)UserActionEnum.Navigated);
 }
Ejemplo n.º 25
0
        protected void btnCreateUser_Click(object sender, EventArgs e)
        {
            ActivityTracker.Track("Created a New User", (int)UserActionEnum.Created);
            try
            {
                // Create instance of role manager and store
                RoleStore <IdentityRole>   roleStore = new RoleStore <IdentityRole>();
                RoleManager <IdentityRole> roleMgr   = new RoleManager <IdentityRole>(roleStore);

                if (!roleMgr.RoleExists(ddlRole.Text))
                {
                    IdentityResult roleResult = roleMgr.Create(new IdentityRole(ddlRole.Text));
                }

                // Declare UserStore and UserManager
                UserStore <IdentityUser>   userStore = new UserStore <IdentityUser>();
                UserManager <IdentityUser> manager   = new UserManager <IdentityUser>(userStore);

                // Declare/create new user and store in manager object in the userstore
                IdentityUser user = new IdentityUser(txtUsername.Text);
                user.Email = txtEmail.Text;

                // Store result of user creation
                IdentityResult idResult = manager.Create(user, txtPassword.Text);

                // Check if user was created and added to role
                if (idResult.Succeeded)
                {
                    // Add user to role
                    IdentityResult userResult = manager.AddToRole(user.Id, ddlRole.SelectedValue);
                    lblMessage.Text     = "User " + user.UserName + " was created successfully!";
                    lblMessage.CssClass = "text-success";

                    // Add other user information to separate table
                    HPSUser hpsUser = new HPSUser();
                    hpsUser.FirstName = txtUserFirstName.Text;
                    hpsUser.LastName  = txtUserLastName.Text;
                    hpsUser.CreatedOn = DateTime.Now;
                    hpsUser.UserId    = user.Id;
                    hpsUser.RoleName  = ddlRole.SelectedValue;
                    db.HPSUsers.Add(hpsUser);

                    // Add empty row to db for fitbit to help with update if sign up date is on the same day as a synchronization
                    db.Steps.AddOrUpdate(new Step {
                        StepCount = 0, StepDate = DateTime.Now.AddDays(-28), UserId = user.Id
                    });
                    db.Distances.AddOrUpdate(new Distance {
                        DistanceCount = 0, DistanceDate = DateTime.Now.AddDays(-28), UserId = user.Id
                    });
                    db.Minutes.AddOrUpdate(new Minute {
                        MinuteCount = 0, MinuteDate = DateTime.Now.AddDays(-28), UserId = user.Id
                    });

                    // create notification for admin users
                    string[] role = { "Administrator" };
                    NotificationCreator.CreateNotification(role, "User Created", Page.User.Identity.Name + " created the user named '" + user.UserName + "'.", DateTime.Now, "Info", null, null);

                    // Save changes tgo db
                    db.SaveChanges();
                }
                else
                {
                    lblMessage.Text = idResult.Errors.FirstOrDefault();
                }
            }
            catch (DataException dx)
            {
                lblMessage.Text = "A data error occured. Please try again later or contact your Administrator if this continues to happen.";
                LogFile.WriteToFile("UserManager.aspx.cs", "btnCreateUser_Click", dx, "Data error when creating user", "HPSErrorLog.txt");
            }
            catch (Exception ex)
            {
                lblMessage.Text = "An error occured. Please try again later or contact your Administrator if this continues to happen.";
                LogFile.WriteToFile("UserManager.aspx.cs", "btnCreateUser_Click", ex, "Error when creating user", "HPSErrorLog.txt");
            }
        }
Ejemplo n.º 26
0
        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";
        }