Пример #1
0
        public void InsertRelationTest()
        {
            var testValue = new SmartTAPostRequest()
            {
                CircleKeys  = new List <string>(),
                ClassRoomId = "smartTAClassRoom1"
            };

            testValue.CircleKeys.Add("9999testcourse");
            var service      = new SmartTAService("AzureUnitTestDB");
            var testResponse = service.InsertRelation(testValue);

            // Assert.IsNotNull(testResponse);
            Assert.IsInstanceOfType(testResponse, typeof(SmartTAGetResponse));
        }
Пример #2
0
        /// <summary>
        /// 加入學習圈
        /// </summary>
        /// <param name="circleKey"></param>
        /// <param name="token"></param>
        public BaseResponse <JObject> joinGroup(string circleKey, Guid token)
        {
            var    result   = new BaseResponse <JObject>();
            string error    = string.Empty;
            string groupKey = circleKey.ToLower();
            var    version  = 0;

            if (Context.QueryString != null && !string.IsNullOrEmpty(Context.QueryString["version"]))
            {
                version = Convert.ToInt32(Context.QueryString["version"]);
            }
            //塞人至相對應的group
            _connections.Add(groupKey, Context.ConnectionId, version);
            try
            {
                var memberService = new MemberService();
                var memberInfo    = memberService.TokenToMember(token.ToString()).Result;
                if (memberInfo == null)
                {
                    return(null);
                }

                //如果是smartTA登入
                if (memberInfo.RoleName == "3")
                {
                    var smartTAService = new Service.Backend.SmartTAService();
                    //先把學習圈內的smartTA都踢掉
                    var smartTAs = smartTAService.GetSmartTAs(groupKey);
                    if (smartTAs != null)
                    {
                        foreach (var smartTA in smartTAs)
                        {
                            Groups.Remove(smartTA.ConnectionId, groupKey);
                        }
                    }
                    var setSmartTAValue = new SmartTAPostRequest()
                    {
                        CircleKeys  = new List <string>(),
                        ClassRoomId = memberInfo.Account
                    };
                    setSmartTAValue.CircleKeys.Add(groupKey);
                    //建立smartTA關聯
                    var setSmartTA = smartTAService.InsertRelation(setSmartTAValue);
                }
                var learningCircleService = new LearningCircleService();
                var learningCircleInfo    = learningCircleService.GetDetailByOuterKey(groupKey);
                var activityService       = new ActivityService();
                var authList = activityService.CircleAuth(memberInfo.Id, learningCircleInfo.Id);
                // 將 連接ID 與 群組代碼 放入SignalR的Groups,之後就能透過Groups(群組代碼)將訊息廣播給使用者
                error = "Groups.Add";
                Groups.Add(Context.ConnectionId, groupKey);
                mqttCircleKey = groupKey;
                // 呼叫前端的Method(發送連接成功的Request)
                error = "joinGroup Clients.Caller.onConnected token:[" + token + "]";
                Clients.Caller.onConnected(groupKey, token, Context.ConnectionId, authList);
                result.Data    = authList;
                result.Success = true;
                return(result);
            }
            catch (Exception ex)
            {
                Clients.Caller.onError("joinGroup", "連接學習圈發生意外: token:[" + token + "]" + ex.Message + error);
                result.Success = false;
                return(result);
            }
        }
Пример #3
0
        /// <summary>
        /// 建立SmartTA與學習圈的關聯
        /// </summary>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public SmartTAGetResponse InsertRelation(SmartTAPostRequest requestData)
        {
            if (requestData.CircleKeys.FirstOrDefault() == null)
            {
                return(null);
            }
            var learningCircleService = new LearningCircleService(_uow);
            int?orgId = 1;

            foreach (var circlekey in requestData.CircleKeys)
            {
                var learningCircleInfo = learningCircleService.GetDetailByOuterKey(circlekey.ToLower());
                if (learningCircleInfo == null)
                {
                    return(null);
                }
                orgId = learningCircleInfo.OrgId;
                var smartTAInfo = _uow.DbContext.Members.FirstOrDefault(t => t.Name.ToLower() == requestData.ClassRoomId && t.OrgId == learningCircleInfo.OrgId);
                if (smartTAInfo == null)
                {
                    return(null);
                }
                //確認是否已經有smartTA存在於學習圈內
                var checkHadSmartTA = _uow.DbContext.SmartTAJoinGroupLog.Where(t => t.CircleKey.ToLower() == circlekey.ToLower());
                //要刪掉該smartTA的關聯
                if (checkHadSmartTA.FirstOrDefault() != null)
                {
                    foreach (var smartTA in checkHadSmartTA)
                    {
                        smartTA.Enabled       = false;
                        smartTA.CreateUtcDate = DateTime.UtcNow;
                    }
                }
                var checkWasInserted = checkHadSmartTA.FirstOrDefault(t => t.SmartTAName.ToLower() == requestData.ClassRoomId.ToLower());
                //如果有加入過就修改為true
                if (checkWasInserted != null)
                {
                    checkWasInserted.Enabled       = true;
                    checkWasInserted.CreateUtcDate = DateTime.UtcNow;
                }
                //沒有就新增一筆關聯
                else
                {
                    var insertEntity = new SmartTAJoinGroupLog()
                    {
                        CircleKey     = circlekey.ToLower(),
                        CreateUtcDate = DateTime.UtcNow,
                        SmartTAName   = requestData.ClassRoomId.ToLower(),
                        Enabled       = true,
                        ConnectionId  = smartTAInfo.ConnectionId
                    };
                    _uow.DbContext.SmartTAJoinGroupLog.Add(insertEntity);
                }

                if (learningCircleInfo == null)
                {
                    continue;
                }
                /*更新學習圈課綱資料*/
                var weekTableDatas = _uow.DbContext.WeekTable.Where(t => t.LearningCircleId == learningCircleInfo.Id);
                foreach (var weektableData in weekTableDatas)
                {
                    weektableData.ClassRoomId = smartTAInfo.Name;
                    //weektableData.Place = smartTAInfo.Name;
                    weektableData.Updater       = smartTAInfo.Id;
                    weektableData.UpdateUtcDate = DateTime.UtcNow;
                }
                var timeTableDatas = _uow.DbContext.TimeTable.Where(t => t.Course_No.ToLower() == circlekey.ToLower());
                foreach (var timeTableData in timeTableDatas)
                {
                    timeTableData.OriginClassRoomID   = timeTableData.ClassRoomId;
                    timeTableData.OriginClassRoomName = timeTableData.ClassRoom;
                    timeTableData.ClassRoomId         = smartTAInfo.Name;
                    //   timeTableData.ClassRoom = smartTAInfo.Name;
                    timeTableData.UpdateDate = DateTime.UtcNow;
                }
            }
            _uow.SaveChanges();
            return(GetDataByClassRoomId(requestData.ClassRoomId, orgId.Value));
        }