public IActionResult yesterdayVal(DateTime ysd)//判斷前一天是否有打卡
        {
            int userId = int.Parse(HttpContext.Session.GetString(CDictionary.CURRENT_LOGINED_USERID));

            TAbsence ab  = db.TAbsences.FirstOrDefault(a => a.CEmployeeId == userId && a.CDate.Value.Date == ysd); //尋找昨天的打卡紀錄
            var      day = ysd.DayOfWeek;                                                                          //星期
            TUser    u   = db.TUsers.FirstOrDefault(u => u.COnBoardDay != DateTime.Today && u.CEmployeeId == userId);

            if (u != null)
            {
                if (ab == null)
                {
                    if (day != DayOfWeek.Sunday && day != DayOfWeek.Saturday)//判斷昨天是否為六日
                    {
                        TAbsence absence = new TAbsence()
                        {
                            CEmployeeId = userId,
                            CDate       = ysd,
                            CStatus     = "異常"
                        };
                        db.Add(absence);
                        db.SaveChanges();
                    }
                }
                else if (ab != null)//昨天有打上班卡,但未打下班卡
                {
                    if (ab.COff == null)
                    {
                        ab.CStatus = "異常";
                        db.Update(ab);
                        db.SaveChanges();
                    }
                }
            }
            DateTime dtMonday = DateTime.Now.AddDays(1 - Convert.ToInt16(DateTime.Now.DayOfWeek)); //當週週一
            DateTime dtSunday = dtMonday.AddDays(6);                                               //當週週日

            var table = db.TAbsences
                        .Where(a => a.CEmployeeId == userId &&
                               a.CDate >= dtMonday &&
                               a.CDate <= dtSunday)
                        .OrderByDescending(a => a.CDate).ToList();
            List <CAbsenceViewModel> list = new List <CAbsenceViewModel>();

            foreach (var item in table)
            {
                CAbsenceViewModel avm = new CAbsenceViewModel()
                {
                    CApplyNumber = item.CApplyNumber,
                    CDate        = item.CDate,
                    COn          = item.COn,
                    COff         = item.COff,
                    CStatus      = item.CStatus
                };
                list.Add(avm);
            }
            getCountNum();
            return(PartialView("date_search", list));
        }
Esempio n. 2
0
        // 新增通知
        public void AddNoti(int toUserId, string notiHeader, string notiBody)
        {
            var           user = HttpContext.Session.GetObject <TUser>(CDictionary.Current_User);
            TNotification noti = new TNotification();

            noti.FromUserId  = user.CEmployeeId;
            noti.ToUserId    = toUserId;
            noti.NotiHeader  = notiHeader;
            noti.NotiBody    = notiBody;
            noti.IsRead      = false;
            noti.Url         = "123";
            noti.CreatedDate = DateTime.Now;

            myHR.Add(noti);
            myHR.SaveChanges();
        }