Esempio n. 1
0
        /// <summary>
        /// 教师发起签到
        /// </summary>
        /// <param name="TeaNo">教工编号</param>
        /// <param name="CourseNo">课程编号</param>
        /// <returns></returns>
        public ActionResult InitiatedCheckIn(string TeaNo, string CourseNo)
        {
            if (TeaNo == null || CourseNo == null)
            {
                return(null);
            }
            using (var tran = AttendanceService.dal.dbContext.Database.BeginTransaction())
            {
                AttendanceResult result = AttendanceService.InitiatedAttendance(TeaNo, CourseNo);
                try
                {
                    if (result.ResultCode == ResultCode.Ok)
                    {
                        string HostIP = IPUtils.GetHostAddresse();
                        string data   = $"http://{HostIP}:8080/api/Attendance/StudentCheckIn?AttendanceId={result.AttendanceId}&CourseNo={CourseNo}&StuNo=";
                        byte[] bytes  = QRCodeHelper.GetQRCode(data);

                        var    room         = RoomService.GetEntity(u => u.F_EnCode == result.RoomNo).FirstOrDefault();
                        string mac          = room?.F_ComputeMac;
                        string connectionId = Cache.GetCache <string>(mac);

                        GlobalHost.ConnectionManager.GetHubContext <QRCodeHub>().Clients.Client(connectionId)
                        .ReciverImg(bytes);
                        tran.Commit();
                    }
                }
                catch (Exception exception)
                {
                    ExceptionHelper.AddException(exception);
                    result.ResultCode   = ResultCode.Error;
                    result.Message      = "教室网页已断开连接";
                    result.AttendanceId = null;
                    tran.Rollback();
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }