Esempio n. 1
0
        public void WhatIsUserDoingWhen()
        {
            SQLiteConnection conn = HoursUtil.GetConnection();
            UserModel        user = UserModel.Load(conn, 2);

            Assert.Equals(user.GetActivity(), UserModel.NOT_WORKING);
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            UserModel user = HoursUtil.GetCurrentUser(User);

            if (user == null)
            {
                return(View());
            }
            {
                ViewBag.User = user;
                return(user.IsAdmin ? AdminHome() : EmployeeHome(user));
            }
        }
Esempio n. 3
0
        public int GetActivity(DateTime when)
        {
            WorkdayModel day = WorkdayModel.Load(HoursUtil.GetConnection(), Id, when);

            if (day == null)
            {
                if (when.DayOfWeek == DayOfWeek.Sunday || when.DayOfWeek == DayOfWeek.Saturday)
                {
                    return(WEEKEND);
                }
                return(NOT_WORKING);
            }
            else
            {
                if (day.IsHoliday)
                {
                    return(HOLIDAY);
                }
                if (day.IsPaidTimeOff)
                {
                    return(PAID_TIME_OFF);
                }

                // the load function uses DateTime.MaxValue if the entry hasn't been created yet.
                // that is, in the database, if there's a value for StartIn, but the others are all
                // null, they will be represented as DateTime.MaxValue.
                if (when < day.StartIn)
                {
                    return(NOT_WORKING);
                }
                // if there's a punch out time, it doesn't matter whether lunch occurred.
                if (when >= day.EndOut)
                {
                    return(DONE);
                }

                if (when == day.StartIn || when < day.LunchOut)
                {
                    return(MORNING);
                }
                if (when == day.LunchOut || when < day.LunchIn)
                {
                    return(LUNCH);
                }
                if (when == day.LunchIn || when < day.EndOut)
                {
                    return(AFTERNOON);
                }
                return(NOT_WORKING);
            }
        }
        // GET: EmployeeReport
        public ActionResult Index()
        {
            int userId = HoursUtil.GetCurrentUserId(User);

            if (userId == 0)
            {
                return(Redirect("/"));
            }


            SQLiteConnection conn = HoursUtil.GetConnection();
            UserModel        user = UserModel.Load(conn, userId);
            var days = WorkdayModel.LoadDaysInRange(conn, userId, DateTime.Now.AddDays(-7), DateTime.Now);

            conn.Close();

            ViewBag.User = user;
            ViewBag.Days = days;
            return(View());
        }
Esempio n. 5
0
        public void Punch(SQLiteConnection conn, DateTime when, String activity)
        {
            WorkdayModel day = WorkdayModel.Load(HoursUtil.GetConnection(), Id, when);

            if (day == null)
            {
                day      = new WorkdayModel();
                day.Day  = when.Date;
                day.User = this;
                if (activity != PUNCH_START_IN)
                {
                    string message = string.Format("Record for new day {0} should begin with starting work, not '{1}'", when.ToShortDateString(), activity);
                    throw new ArgumentException(message);
                }
            }
            switch (activity)
            {
            case PUNCH_START_IN:
                day.StartIn = when;
                break;

            case PUNCH_LUNCH_OUT:
                day.LunchOut = when;
                break;

            case PUNCH_LUNCH_IN:
                day.LunchIn = when;
                break;

            case PUNCH_END_OUT:
                day.EndOut = when;
                break;

            default:
                throw new ArgumentException("don't recognize punch activity: " + activity);
            }
            day.Save(conn);
        }
Esempio n. 6
0
        private ActionResult EmployeeHome(UserModel user)
        {
            var pageTime = getPageTime();

            if (Request.Form.HasKeys() && Request.Form["punch"] != null)
            {
                var conn = HoursUtil.GetConnection();
                user.Punch(conn, pageTime, Request.Form["punch"]);
            }

            var activityCode = user.GetActivity(pageTime);
            Dictionary <string, string> buttonEnables = new Dictionary <string, string>();

            buttonEnables["StartIn"]  = activityCode < 1 ? "" : "disabled";
            buttonEnables["LunchOut"] = activityCode == 1 ? "" : "disabled";
            buttonEnables["LunchIn"]  = activityCode == 2 ? "" : "disabled";
            buttonEnables["EndOut"]   = activityCode > 0 && activityCode < 4 ? "" : "disabled";

            ViewBag.PageTime      = pageTime;
            ViewBag.Activity      = UserModel.STATE_DESCRIPTION[activityCode];
            ViewBag.ButtonEnables = buttonEnables;
            return(View("EmployeeHome"));
        }