public async Task <EmployeeTimeClockDto> CheckIn([FromBody] CheckInRequestDto checkInRequest, CancellationToken cancellationToken) { var response = await _service.CheckInAsync(_mapper.Map <CheckInRequest>(checkInRequest), cancellationToken); return(_mapper.Map <EmployeeTimeClockDto>(response)); }
public async Task <ResponseDto> TakeLeave([FromBody] CheckInRequestDto request) { if (!ModelState.IsValid) { return(new ResponseDto(ResponseCode.Validate, "Đầu vào không hợp lệ")); } if (request.CheckInResult != (int)StudentStatus.OnLeave) { return(new ResponseDto(ResponseCode.Validate, "Đầu vào không hợp lệ")); } var res = await _studentService.CheckIn(request); if (res.StatusCode == ResponseCode.Success) { // Message to web manager await _hubContext.Clients.All.SendAsync("ReceiveCheckIn", res); // Message to monitor var notification = await _studentService.AddNotification(res.Result); await _hubContext.Clients.User(res.Result.MonitorId.ToString()).SendAsync("ReceiveNotication", notification); } // Api response to Parent return(res); }
public async Task <ResultDto <StudentCheckInDto> > CheckIn([FromBody] CheckInRequestDto request) { if (!ModelState.IsValid) { return(new ResultDto <StudentCheckInDto>(ResponseCode.Validate, "Đầu vào không hợp lệ", null)); } var res = await _studentService.CheckIn(request); if (res.StatusCode == ResponseCode.Success) { // Message to All await _hubContext.Clients.All.SendAsync("ReceiveCheckIn", res); var notification = await _studentService.AddNotification(res.Result); if (notification.TypeNotification == (int)TypeMessage.InClass | notification.TypeNotification == (int)TypeMessage.NotInClass) { // Message to parent and monitor await _hubContext.Clients.User(res.Result.ParentId.ToString()).SendAsync("ReceiveNotication", notification); await _hubContext.Clients.User(res.Result.MonitorId.ToString()).SendAsync("ReceiveNotication", notification); } else if (notification.TypeNotification != (int)TypeMessage.AtHome && notification.TypeNotification != (int)TypeMessage.OnLeave) { // Message to parent and teacher await _hubContext.Clients.User(res.Result.ParentId.ToString()).SendAsync("ReceiveNotication", notification); await _hubContext.Clients.User(res.Result.TeacherId.ToString()).SendAsync("ReceiveNotication", notification); } else { // Message to monitor and teacher await _hubContext.Clients.User(res.Result.MonitorId.ToString()).SendAsync("ReceiveNotication", notification); await _hubContext.Clients.User(res.Result.TeacherId.ToString()).SendAsync("ReceiveNotication", notification); } } return(res); }
/// <summary> /// Điểm danh học sinh lúc đi và lúc về (Cho app của GSX) /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <ResultDto <StudentCheckInDto> > CheckIn(CheckInRequestDto request) { var studentCheckIn = new StudentCheckIn() { CheckInResult = (StudentStatus)request.CheckInResult, CheckInTime = request.CheckInTime, CheckInType = (CheckInType)request.CheckInType, MonitorId = request.MonitorId, Latitude = request.Latitude, Longitude = request.Longitude, StudentId = request.StudentId }; var student = await this.GetById(request.StudentId); var checkInTimeSpan = new TimeSpan(studentCheckIn.CheckInTime.Hour, (studentCheckIn.CheckInTime.Minute), 00); if (studentCheckIn.CheckInResult == StudentStatus.PickedUp) { TimeSpan timeCheck = checkInTimeSpan.Subtract(student.StopPickTime); if (timeCheck.TotalMinutes > 5) { studentCheckIn.CheckInState = CheckInState.Late; } else if (timeCheck.TotalMinutes < -5) { studentCheckIn.CheckInState = CheckInState.Soon; } else { studentCheckIn.CheckInState = CheckInState.OnTime; } } else if (studentCheckIn.CheckInResult == StudentStatus.DropedOff) { TimeSpan timeCheck = checkInTimeSpan.Subtract(student.StopDropTime); if (timeCheck.TotalMinutes > 5) { studentCheckIn.CheckInState = CheckInState.Late; } else if (timeCheck.TotalMinutes < -5) { studentCheckIn.CheckInState = CheckInState.Soon; } else { studentCheckIn.CheckInState = CheckInState.OnTime; } } // Lưu điểm danh vào DB await _context.StudentCheckIns.AddAsync(studentCheckIn); var result = await _context.SaveChangesAsync(); if (result > 0) { // Cập nhật trạng thái HS var studentUpdateResult = await this.UpdateStatus(studentCheckIn.StudentId, (StudentStatus)request.CheckInResult); // Cập nhật trạng thái warning var updateWarningResult = await this.UpdateWarningState(studentCheckIn.StudentId, false); // Lấy StudentCheckInDto var itemCheckIn = await this.GetItemCheckInById(studentCheckIn.Id); if (studentUpdateResult != 0 && itemCheckIn != null) { return(new ResultDto <StudentCheckInDto>(ResponseCode.Success, "Điểm danh thành công", itemCheckIn)); } return(new ResultDto <StudentCheckInDto>(ResponseCode.LogicError, "Điểm danh thất bại", null)); } else { return(new ResultDto <StudentCheckInDto>(ResponseCode.LogicError, "Điểm danh thất bại", null)); } }