Exemplo n.º 1
0
        public ActionResult ClockOut(WorkTimeEventModel workTimeEventModel, LoginViewModel lvm)
        {
            //gets user from db by email or username
            var user = db.Users.SingleOrDefault(x => x.UserName == lvm.Email || x.Email == lvm.Email);
            // Checks Db users for email that matches the email user typed in
            ApplicationUser dbUser   = db.Users.FirstOrDefault(x => x.Email == lvm.Email || x.UserName == lvm.Email);
            var             worktime = db.EventModels.FirstOrDefault(x => x.User.Id == dbUser.Id && !x.EndTime.HasValue);

            if (worktime != null)
            {  //Update the current open event with an end datetime.
                //Updates message column in db Event
                worktime.Message += "clock out: " + lvm.Message;
                DateTime endTime = DateTime.Now;
                worktime.EndTime = endTime;
                workTimeEventModel.Clockout();
                db.SaveChanges();
                db.SaveChanges();
                //displays message to user *currently using to keep track of methods
                TempData["message"] = "Clock out: " + DateTime.Now.ToString("h:mm tt") + " Have a great day!";
                return(RedirectToAction("Login", "Account"));
            }
            //displays message to user *currently using to keep track of methods
            else
            {
                TempData["message"] = "Unable to clock out, please clock in to clock out";
            }
            return(RedirectToAction("Login", "Account"));
        }
Exemplo n.º 2
0
        public ActionResult ClockOut(WorkTimeEventModel workTimeEventModel, LoginViewModel lvm)
        {
            var user     = db.Users.SingleOrDefault(x => x.Id == lvm.UserId);
            var worktime = db.EventModels.FirstOrDefault(x => x.User.Id == user.Id && !x.EndTime.HasValue);

            if (worktime != null)
            {  //Update the current open event with an end datetime.
                //Updates message column in db Event
                worktime.Message += "clock out: " + lvm.Message;
                DateTime endTime = DateTime.Now;
                worktime.EndTime = endTime;
                workTimeEventModel.Clockout();
                db.SaveChanges();
                db.SaveChanges();
                //displays message to user *currently using to keep track of methods
                TempData["message"] = "Clock out: " + DateTime.Now.ToString("h:mm tt") + " Have a great day!";
                return(RedirectToAction("ClockInPage", "WorkTimeEvent"));
            }
            //displays message to user *currently using to keep track of methods
            else
            {
                TempData["message"] = "Unable to clock out, please clock in to clock out";
            }
            return(RedirectToAction("ClockInPage", "WorkTimeEvent"));
        }