public async Task <ReturnData <bool> > CreateAsync(AddAttendanceDto model)
        {
            var result         = new ReturnData <bool>();
            var attendanceTime = await _context.AttendanceTimeSets.FirstOrDefaultAsync();

            if (attendanceTime != null)
            {
                var attendanceAccess = await _context.Attendances.FirstOrDefaultAsync(i => i.WorkingTime.ToString("yyyy/MM/dd") == model.CreateTime.ToString("yyyy/MM/dd"));

                if (attendanceAccess != null)
                {
                    //如果当前有打卡记录 则更新下班时间
                    attendanceAccess.OffworkTime = model.CreateTime;
                    if (Convert.ToDateTime(model.CreateTime.ToString("HH:mm:ss")) > Convert.ToDateTime(attendanceTime.OffworkTime.AddSeconds(-1).ToString("HH:mm:ss")))
                    {
                        //判断打卡时间是否超过规定下班时间 超过则是正常下班 否者早退
                        attendanceAccess.IsLeaveEarly = false;
                    }
                    else
                    {
                        attendanceAccess.IsLeaveEarly = true;
                    }
                }
                else
                {
                    //否则新增上班时间
                    if (Convert.ToDateTime(model.CreateTime.ToString("HH:mm:ss")) > Convert.ToDateTime(attendanceTime.WorkingTime.AddSeconds(59).ToString("HH:mm:ss")))
                    {
                        //判断打卡时间是否超过规定上班班时间 超过则是迟到 否者正常
                        _context.Attendances.Add(new Model.Model.Attendance()
                        {
                            IsLeaveEarly = false,
                            IsLate       = true,
                            OffworkTime  = null,
                            StaffInfoId  = model.StaffInfoId,
                            WorkingTime  = model.CreateTime,
                        });
                    }
                    else
                    {
                        _context.Attendances.Add(new Model.Model.Attendance()
                        {
                            IsLeaveEarly = false,
                            IsLate       = false,
                            OffworkTime  = null,
                            StaffInfoId  = model.StaffInfoId,
                            WorkingTime  = model.CreateTime,
                        });
                    }
                }
            }
            result.Result = await _context.SaveChangesAsync() > 0;

            return(result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(AddAttendanceDto model)
        {
            var result = await _service.CreateAsync(model);

            return(Ok(result));
        }