Пример #1
0
        /*
         * Function: Logout()
         * Purpose: Return to login page and clear the session
         * Author: Jordan Pitner 9/20/2018
         */
        public ActionResult Logout()
        {
            // Log sign out event
            EventLogger.LogNewEvent(MembershipAuth.GetCurrentUserID(HttpContext.Request), MembershipAuth.GetCurrentUserOrganizationID(HttpContext.Request), LoggingEventType.UserLogout, "");

            // Signout
            FormsAuthentication.SignOut();

            return(RedirectToAction("Login"));
        }
Пример #2
0
        public ActionResult AllContacts()
        {
            string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
            int    userID   = db.Users.FirstOrDefault(u => u.Email == userName).Id;

            if (!(userID > 0))
            {
                return(RedirectToAction("Login", "Home", null));
            }

            return(View());
        }
        public ActionResult Summary()
        {
            // Validate that a session exists, or re-route to login
            string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
            int    userID   = db.Users.FirstOrDefault(u => u.Email == userName).Id;

            if (!(userID > 0))
            {
                return(RedirectToAction("Login", "Home", null));
            }

            return(View());
        }
        public ActionResult YearlySummary(string year)
        {
            // Validate that a session exists, or re-route to login
            string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
            int    userID   = db.Users.FirstOrDefault(u => u.Email == userName).Id;

            if (!(userID > 0))
            {
                return(RedirectToAction("Login", "Home", null));
            }

            User   user = db.Users.Where(u => u.Id == userID).FirstOrDefault();
            string name = user.FirstName + " " + user.LastName;

            // Get the data from the database
            Summary          summary = new Summary();
            List <TimeEvent> times   = db.TimeEvents.Where(t => t.userID == userID).ToList().Where(t =>
                                                                                                   Convert.ToDateTime(t.start).Year == new DateTime(int.Parse(year.Trim()), 1, 1).Year).ToList();

            summary.name         = name;
            summary.payRate      = 9.50;
            summary.yearlyEvents = new Dictionary <int, string>();

            // Add the appropriate date/times to the dictionary for hours processing
            foreach (TimeEvent ev in times)
            {
                DateTime start = Convert.ToDateTime(ev.start);
                DateTime end   = Convert.ToDateTime(ev.end);

                int    month = start.Month;
                double hours = (end - start).TotalHours;

                summary.totalHours += Math.Round(hours, 2);

                if (summary.yearlyEvents.ContainsKey(month))
                {
                    summary.yearlyEvents[month] = (double.Parse(summary.yearlyEvents[month]) + hours).ToString("0.00");
                }
                else
                {
                    summary.yearlyEvents.Add(month, Math.Round(hours, 2).ToString());
                }
            }

            // Sort and set any remaining variables
            summary.yearlyEvents = summary.yearlyEvents.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
            summary.totalPay     = summary.totalHours * summary.payRate;
            summary.totalPay     = Math.Round(summary.totalPay, 2);

            return(View(summary));
        }
        public ActionResult EditProfile()
        {
            string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
            int    userID   = db.Users.FirstOrDefault(u => u.Email == userName).Id;

            if (!(userID > 0))
            {
                return(RedirectToAction("Login", "Home", null));
            }

            // Grab the user information for display
            User user = db.Users.FirstOrDefault(u => u.Id == userID);

            return(View(user));
        }
        public ActionResult Invites()
        {
            // Only let admins access this view
            if (MembershipAuth.IsAdmin(HttpContext.Request))
            {
                // Get credentials to get proper invites
                string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
                int    orgID    = db.Users.SingleOrDefault(u => u.Email == userName).OrganizationID;

                // Return list of invites for viewing
                List <InviteCode> inviteCodes = db.InviteCodes.Where(i => i.OrganizationID == orgID).ToList();

                return(View(inviteCodes));
            }

            return(RedirectToAction("Error", "Error", new { error = 3 }));
        }
        public ActionResult WeeklySummary()
        {
            // Validate that a session exists, or re-route to login
            string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
            int    userID   = db.Users.FirstOrDefault(u => u.Email == userName).Id;

            if (!(userID > 0))
            {
                return(RedirectToAction("Login", "Home", null));
            }

            User   user = db.Users.Where(u => u.Id == userID).FirstOrDefault();
            string name = user.FirstName + " " + user.LastName;

            // Get the data from the database
            Summary          summary = new Summary();
            List <TimeEvent> times   = db.TimeEvents.Where(t => t.userID == userID).ToList();

            summary.name    = name;
            summary.payRate = 9.50;
            summary.events  = new Dictionary <DateTime, string>();

            // Add the appropriate date/times to the dictionary for hours processing
            foreach (TimeEvent ev in times)
            {
                DateTime start = Convert.ToDateTime(ev.start);

                if (start > DateTime.Now.AddDays(-7) && start < DateTime.Now)
                {
                    DateTime end   = Convert.ToDateTime(ev.end);
                    double   hours = (end - start).TotalHours;

                    summary.totalHours += Math.Round(hours, 2);
                    summary.events.Add(start.Date, Math.Round(hours, 2).ToString());
                }
            }

            // Sort and set any remaining variables
            summary.events   = summary.events.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
            summary.totalPay = summary.totalHours * summary.payRate;
            summary.totalPay = Math.Round(summary.totalPay, 2);

            return(View(summary));
        }
        public ActionResult GetTimeEntry(int id)
        {
            // Validate that a session exists, or re-route to login
            string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
            int    userID   = db.Users.FirstOrDefault(u => u.Email == userName).Id;

            if (!(userID > 0))
            {
                return(RedirectToAction("Login", "Home", null));
            }

            TimeEvent timeEntry = db.TimeEvents.Where(t => t.id == id).FirstOrDefault();

            if (timeEntry != null && timeEntry.User.Id == userID)
            {
                return(Json(new { success = true, start = timeEntry.start, end = timeEntry.end }));
            }

            return(Json(new { sucess = false }));
        }
        public ActionResult CreateTimeEntry(TimeEvent timeEvent)
        {
            TimeEvent te = new TimeEvent();
            // Validate that a session exists, or re-route to login
            string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
            int    userID   = db.Users.FirstOrDefault(u => u.Email == userName).Id;

            if (!(userID > 0))
            {
                return(RedirectToAction("Login", "Home", null));
            }

            te.title  = timeEvent.title;
            te.start  = timeEvent.start;
            te.end    = timeEvent.end;
            te.userID = userID;

            // Commit to database
            db.TimeEvents.Add(te);
            db.SaveChanges();

            return(Json(new { success = true, id = te.id }));
        }
Пример #10
0
        // Actions
        #region Actions

        /*
         * Function: Error(int error)
         * Purpose: Return errors based on values passed in server side
         * Author: Jordan Pitner 9/27/2018
         */
        public ActionResult Error(int error)
        {
            string message = "";

            // Determine which error should be fired
            switch (error)
            {
            // Profile Error
            case 1:
                message = PROFILE_ERROR;
                EventLogger.LogNewEvent(MembershipAuth.GetCurrentUserID(HttpContext.Request),
                                        MembershipAuth.GetCurrentUserOrganizationID(HttpContext.Request),
                                        LoggingEventType.Error, "PROFILE_ERROR");
                break;

            // Profile Edit Error
            case 2:
                message = PROFILE_EDIT_ERROR;
                EventLogger.LogNewEvent(MembershipAuth.GetCurrentUserID(HttpContext.Request),
                                        MembershipAuth.GetCurrentUserOrganizationID(HttpContext.Request),
                                        LoggingEventType.Error, "PROFILE_EDIT_ERROR");
                break;

            // Permission Error
            case 3:
                message = PERMISSION_ERROR;
                EventLogger.LogNewEvent(MembershipAuth.GetCurrentUserID(HttpContext.Request),
                                        MembershipAuth.GetCurrentUserOrganizationID(HttpContext.Request),
                                        LoggingEventType.Error, "PERMISSION_ERROR");
                break;

            default:
                break;
            }

            return(View((object)message));
        }
Пример #11
0
        public ActionResult ProfilePage(string id = null)
        {
            int  userID;
            User user;

            // Checks to see if you are viewing yourself, or another user
            if (id == null)
            {
                // Validate that a session exists, or re-route to login
                string userName = MembershipAuth.GetCurrentUser(HttpContext.Request);
                userID = db.Users.FirstOrDefault(u => u.Email == userName).Id;

                if (!(userID > 0))
                {
                    return(RedirectToAction("Login", "Home", null));
                }

                // No user was passed in, get your own information
                user = db.Users.SingleOrDefault(u => u.Id == userID);
            }
            else
            {
                // Another user was passed in, find them
                user = db.Users.SingleOrDefault(u => u.EmployeeID == id);
            }

            // If the user is found, display the page. Otherwise, display an error
            if (user != null)
            {
                return(View(user));
            }
            else
            {
                return(RedirectToAction("Error", "Error", new { error = 1 }));
            }
        }
        public ActionResult EditProfile(User user, HttpPostedFileBase profilePicture)
        {
            if (ModelState.IsValid)
            {
                // Validation that some other user isn't trying to access information
                string userName   = MembershipAuth.GetCurrentUser(HttpContext.Request);
                User   accessUser = db.Users.FirstOrDefault(u => u.Email == userName);

                ImageProcessor processor = new ImageProcessor();

                // If so, present error screen
                if (accessUser.Id != user.Id)
                {
                    return(RedirectToAction("Error", "Error", new { error = 2 }));
                }

                // Imaging processing for profile pictures (new or updated)
                if (profilePicture != null)
                {
                    UserImage image = db.UserImages.FirstOrDefault(i => i.UserID == accessUser.Id);
                    byte[]    bytes = new byte[profilePicture.ContentLength];

                    // Process profile picture coming in
                    if (image == null)
                    {
                        UserImage newImg = new UserImage();
                        newImg.Binary = bytes;
                        profilePicture.InputStream.Read(bytes, 0, profilePicture.ContentLength);
                        newImg.UserID = accessUser.Id;

                        // Commit new image
                        db.UserImages.Add(newImg);
                        db.SaveChanges();
                    }
                    else
                    {
                        if (!bytes.SequenceEqual(image.Binary))
                        {
                            image.Binary = bytes;
                            profilePicture.InputStream.Read(bytes, 0, profilePicture.ContentLength);
                        }
                    }
                }

                // Update the values from edit (some repeats may exist)
                accessUser.FirstName = user.FirstName.Trim();
                accessUser.LastName  = user.LastName.Trim();
                accessUser.Email     = user.Email.Trim();
                accessUser.AboutMe   = user.AboutMe.Trim();
                accessUser.Skills    = user.Skills.Trim();
                accessUser.Phone     = user.Phone.Trim().Replace("-", "").Replace("(", "").Replace(")", "");


                // Commit changes
                db.SaveChanges();

                return(View(accessUser));
            }

            return(RedirectToAction("Error", "Error", new { error = 2 }));
        }