Exemplo n.º 1
0
        /// <summary>
        /// 老師更新點名簽到記錄
        /// </summary>
        /// <param name="learningId">學習圈Id</param>
        /// <param name="token">老師token</param>
        /// <param name="eventId">點名活動Guid</param>
        /// <param name="studId">被編輯點名狀態的學生MemberId</param>
        /// <param name="status">點名狀態 1出席,2缺席,3遲到,4早退,5請假</param>
        /// <returns></returns>
        public async Task SignIn_Modify(string circleKey, Guid token, string outerKey, int stuId, int status)
        {
            try
            {
                var auth = new ServerCheckItem()
                {
                    OuterKey = outerKey, CircleKey = circleKey, ModuleFun = SignInFunction.Admin
                };
                bool chekc = AuthCheck(token, ref auth);
                if (chekc)
                {
                    if (auth.ModuleAuth)
                    {
                        if (AttendanceState.Status.ContainsKey(status.ToString()))
                        {
                            // 更新點名紀錄
                            var log = signInLogService.UpdateLog(auth.MemberId, auth.EventId, stuId, status.ToString());

                            // 新增一筆通知
                            string stateName     = AttendanceState.GetStateName(status.ToString());
                            string text          = "您的狀態已更新:" + stateName;
                            var    noticeService = new NoticeService();
                            noticeService.AddNoticeSaveChange(circleKey, stuId, auth.EventId, text);
                            var signalrService = new SignalrService();
                            //發通知給學生
                            var connectIdAndNoticeData = signalrService.GetConnectIdAndData(circleKey.ToLower(), log.StuId, SignalrConnectIdType.One, SignalrDataType.Notice);

                            SignalrClientHelper.SendNotice(connectIdAndNoticeData);
                            //告訴同學點名狀態已改變
                            Clients.Group(circleKey.ToLower()).signIn_StatusChanged(outerKey, log);

                            // 發送推播
                            await PushOnChangedSignIn(circleKey.ToLower(), auth.EventId, log.StudId, stateName);
                        }
                        else
                        {
                            Clients.Caller.onError("SignIn_Modify", "狀態錯誤!");
                        }
                    }
                    else
                    {
                        Clients.Caller.onError("SignIn_Modify", "您沒有權限!");
                    }
                }
                else
                {
                    Clients.Caller.onError("SignIn_Modify", "身分驗證失敗,請重新登入!token:[" + token + "]");
                }
            }
            catch (Exception ex)
            {
                Clients.Caller.onError("SignIn_Modify", "老師點名發生意外: " + ex.Message);
            }
        }
Exemplo n.º 2
0
        private BaseResponse <string> UpdateSignIn(string circleKey, Guid token, string outerKey, string checkType, string[] keys)
        {
            var response = new BaseResponse <string>();

            try
            {
                var auth = new ServerCheckItem()
                {
                    OuterKey = outerKey, CircleKey = circleKey, ModuleFun = SignInFunction.Member
                };
                bool check = AuthCheck(token, ref auth);
                if (check)
                {
                    // 取出目前的點名活動
                    var eve = signInService.GetSignInInfomation(auth.EventId);

                    #region //確認活動正在進行

                    var act = activityService.GetByEventId(auth.EventId);

                    var endTime = act.StartDate.Value.Add(new TimeSpan(0, 0, act.Duration.Value));
                    if (act.StartDate != null && (DateTime.UtcNow <= act.StartDate || DateTime.UtcNow >= endTime))
                    {
                        response.Success = false;
                        response.Message = "現在活動不是進行中";
                        Clients.Caller.signIn_Failed("UpdateSignIn", outerKey, "現在活動不是進行中");
                        return(response);
                    }
                    #endregion

                    #region //確認學生可以被點名

                    if (auth.ModuleAuth == false)
                    {
                        response.Success = false;
                        response.Message = "你沒有修這堂課";
                        Clients.Caller.signIn_Failed("UpdateSignIn", outerKey, "你沒有修這堂課");
                        return(response);
                    }

                    #endregion

                    #region //缺席才可簽到

                    var log = signInLogService.GetLogData(eve.Id, auth.MemberId, AttendanceState.Absence);
                    if (log == null)
                    {
                        Clients.Caller.signIn_Failed("UpdateSignIn", outerKey, "只有缺席的學生可以簽到");
                        response.Success = false;
                        response.Message = "只有缺席的學生可以簽到";
                        return(response);
                    }
                    #endregion

                    #region // 簽到碼檢查

                    switch (checkType)
                    {
                    // 若學生不在教室,回傳錯誤訊息
                    case "beacon":
                        if (!keys.Contains(eve.SignInKey))
                        {
                            var msg = string.Format("你不在教室!\n教室beacons:\n{0}\n\n偵測到:\n{1}", eve.SignInKey, string.Join("\n", keys));
                            Clients.Caller.signIn_Failed("SignIn_BeaconSignIn", outerKey, msg);
                            response.Success = false;
                            response.Message = msg;
                            return(response);
                        }
                        break;

                    // 簽到密碼錯誤,回傳錯誤訊息
                    case "pwd":
                        if (eve.SignInPwd != keys[0])
                        {
                            response.Success = false;
                            response.Message = "驗證碼錯誤";
                            Clients.Caller.signIn_Failed("SignIn_PasswordSignIn", outerKey, "驗證碼錯誤!");
                            return(response);
                        }
                        break;
                    }
                    #endregion

                    string stateCode = AttendanceState.Attend;

                    // 檢查通過,save data
                    var mylog = signInLogService.UpdateLog(auth.MemberId, auth.EventId, auth.MemberId, stateCode);

                    // 新增一筆通知
                    string stateName = AttendanceState.GetStateName(stateCode);
                    string text      = "您的狀態已更新:" + stateName;
                    AddNotice(circleKey, auth.EventId, auth.MemberId, text);
                    //告訴同學點名狀態已改變
                    Clients.Group(circleKey.ToLower()).signIn_StatusChanged(outerKey, mylog);


                    // 2016-09-20 mark by sophiee:APP team告知,如果是學生自己簽到就不發送推播
                    // await PushOnChangedSignIn(circleKey, auth.EventId, mylog.StudId, stateName);
                    response.Success = true;
                }
                else
                {
                    response.Message = "身分驗證失敗,請重新登入";
                    Clients.Caller.onError("UpdateSignIn", "身分驗證失敗,請重新登入!token:[" + token + "]");
                    response.Success = false;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "學生簽到發生意外";
                Clients.Caller.onError("UpdateSignIn", "學生簽到發生意外: " + string.Format("{0}\n\n{1}", ex.Message, ex.StackTrace));
            }
            return(response);
        }