Example #1
0
        public ActionResult Signout()
        {
            //未登录用户,不允许签退
            if (Session["user"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var db = new ARSEntitis();

            //var context = DbHelper.getInstance().createDbContext();

            //var attendanceRecords = context.GetTable<AttendanceRecord>();
            var todayDate = DateTime.Now.Date;
            var nextDate  = todayDate.AddDays(1).Date;
            var id        = ((Employee)Session["user"]).id.Value;
            //没有签到记录,不允许签退
            var query = from ar in db.AttendanceRecords
                        where ar.user_id == id &&
                        ar.sign_time > todayDate &&
                        ar.sign_time < nextDate &&
                        ar.type == 1
                        select ar;

            if (query.Count() == 0)
            {
                TempData["SignOutSuccess"] = false;
                TempData["ErrorInfo"]      = "还未签到!";
            }
            else
            {
                TimeSpan ts = DateTime.Now - query.Single().sign_time;
                if (ts.TotalMinutes < 30)
                {
                    TempData["SignOutSuccess"] = false;
                    TempData["ErrorInfo"]      = "签到还未满30分钟!";
                }
                else
                {
                    TempData["SignOutSuccess"] = true;
                    var signoutRecord = new AttendanceRecord()
                    {
                        user_id = ((Employee)Session["user"]).id.Value, type = 2, sign_time = DateTime.Now
                    };

                    db.AttendanceRecords.Add(signoutRecord);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Example #2
0
        public ActionResult SignIn()
        {
            //未登录用户,不允许签到
            if (Session["user"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }


            var db = new ARSEntitis();

            var todayDate = DateTime.Now.Date;
            var nextDate  = todayDate.AddDays(1).Date;

            var id = ((Employee)Session["user"]).id.Value;
            //已存在签到记录,不允许签到
            var query = from ar in db.AttendanceRecords
                        where ar.user_id == id &&
                        ar.sign_time > todayDate &&
                        ar.sign_time < nextDate &&
                        ar.type == 1
                        select ar;

            if (query.Count() > 0)
            {
                TempData["SignInSuccess"] = false;
                TempData["ErrorInfo"]     = "今日已经签到!";
            }
            else
            {
                TempData["SignInSuccess"] = true;
                var signinRecord = new AttendanceRecord()
                {
                    user_id = ((Employee)Session["user"]).id.Value, type = 1, sign_time = DateTime.Now
                };

                db.AttendanceRecords.Add(signinRecord);
                db.SaveChanges();
                //context.SubmitChanges();
            }

            return(RedirectToAction("Index"));
        }