public async Task <IHttpActionResult> Get()
        {
            var response = new Infrastructure.ViewModel.Base.BaseResponse <string>();

            multipartFormDataModel = new SetNewAbsenceFormRequest();
            await SetFileData();

            if (multipartFormDataStreamProvider.FormData == null)
            {
                response.Message = "遺漏參數";
                response.State   = Infrastructure.ViewModel.Base.LogState.RequestDataError;
                return(Content(HttpStatusCode.BadRequest, response));
            }
            //設定參數
            var token = multipartFormDataStreamProvider.FormData.Get("icantoken") != null?multipartFormDataStreamProvider.FormData.GetValues("icantoken")[0] : null;

            var circleKey = multipartFormDataStreamProvider.FormData.Get("classid") != null?multipartFormDataStreamProvider.FormData.GetValues("classid")[0] : null;

            var title = multipartFormDataStreamProvider.FormData.Get("title") != null?multipartFormDataStreamProvider.FormData.GetValues("title")[0] : null;

            var content = multipartFormDataStreamProvider.FormData.Get("content") != null?multipartFormDataStreamProvider.FormData.GetValues("content")[0] : null;

            var leavedate = multipartFormDataStreamProvider.FormData.Get("leavedate") != null?multipartFormDataStreamProvider.FormData.GetValues("leavedate")[0] : null;

            var leavecategoryid = multipartFormDataStreamProvider.FormData.Get("leavecategoryid") != null?multipartFormDataStreamProvider.FormData.GetValues("leavecategoryid")[0] : null;

            if (token == null || circleKey == null || title == null || content == null || leavedate == null || leavecategoryid == null)
            {
                response.Message = "遺漏參數";
                response.State   = Infrastructure.ViewModel.Base.LogState.RequestDataError;
                return(Content(HttpStatusCode.BadRequest, response));
            }

            multipartFormDataModel.Token           = Guid.Parse(token);
            multipartFormDataModel.CircleKey       = circleKey.ToLower();
            multipartFormDataModel.Title           = HttpUtility.UrlDecode(title);
            multipartFormDataModel.Content         = HttpUtility.UrlDecode(content);
            multipartFormDataModel.LeaveDate       = Convert.ToDateTime(leavedate);
            multipartFormDataModel.LeaveCategoryId = Convert.ToInt32(leavecategoryid);

            var service = new LeaveService();

            var data = service.SetNewAbsenceForm(multipartFormDataModel, multipartFormDataFiles, fileStreams);

            objHub.Clients.Group(multipartFormDataModel.CircleKey.ToLower()).addLeave(data);


            var tokenService = new TokenService();
            var checkToken   = tokenService.GetTokenInfo(multipartFormDataModel.Token.ToString()).Result;

            if (checkToken == null)
            {
                response.Success = false;
                response.Message = "已登出";
                response.State   = Infrastructure.ViewModel.Base.LogState.Logout;
                return(Ok(response));
            }

            response.Success = data != null ? true : false;
            response.Message = data != null ? "建立成功" : "建立失敗";

            //單元測試結果
            if (HttpContext.Current == null)
            {
                return(Ok(response));
            }

            var pushService = new PushService();
            // 檢查通過,save data
            var message         = pushService.PushOnCreatedLeave(multipartFormDataModel.CircleKey, data.EventId, checkToken.MemberId, multipartFormDataModel.LeaveDate.ToLocalTime()).Result;
            var activityService = new ActivityService();

            var signalrService = new SignalrService();

            //發通知給老師們
            var connectIdAndNoticeData = signalrService.GetConnectIdAndData(multipartFormDataModel.CircleKey, checkToken.MemberId, SignalrConnectIdType.Teachers, SignalrDataType.Notice);
            var learningCircleService  = new LearningCircleService();
            var teachers = learningCircleService.GetCircleTeacherIdListBySql(multipartFormDataModel.CircleKey.ToLower(), checkToken.MemberId);

            // 將通知寫入資料庫
            activityService.AddMutipleNotice(multipartFormDataModel.CircleKey, teachers, data.EventId, message);
            SignalrClientHelper.SendNotice(connectIdAndNoticeData);

            foreach (var item in data.OuterKeySignInLog)
            {
                //告訴同班的有活動的開始時間被修改
                SignalrClientHelper.SignIn_StatusChanged(multipartFormDataModel.CircleKey, item.Key, item.Value);
            }
            //    return result;
            return(Ok(response));
        }
Exemplo n.º 2
0
        public IHttpActionResult Get([FromUri] string strAccess)
        {
            var requestData = JsonConvert.DeserializeObject <Infrastructure.ViewModel.ActivityFunction.Leave.SetAbsenceFormStatusRequest>(strAccess);

            if (requestData.Account == null ||
                requestData.ClassID == null ||
                requestData.ICanToken == null ||
                requestData.OuterKey == null)
            {
                return(Content(HttpStatusCode.BadRequest, "遺漏參數"));
            }

            var response = new Infrastructure.ViewModel.Base.ResultBaseModel <Infrastructure.ViewModel.ActivityFunction.Leave.SetAbsenceFormStatusResponse>();

            var tokenService = new TokenService();
            var checkToken   = tokenService.GetTokenInfo(requestData.ICanToken).Result;

            if (checkToken == null)
            {
                response.Success = false;
                response.Message = "已登出";
                response.State   = Infrastructure.ViewModel.Base.LogState.Logout;
                return(Ok(response));
            }

            var learningService = new LearningCircleService();
            var learningId      = learningService.GetDetailByOuterKey(requestData.ClassID).Id;
            var authService     = new AuthService();

            // 是否有審核請假單的權限
            var reviewLeave      = authService.CheckFunctionAuth(learningId, ParaCondition.LeaveFunction.Review, checkToken.MemberId);
            var activityService  = new ActivityService();
            var service          = new LeaveService();
            var pushService      = new PushService();
            var signalrService   = new SignalrService();
            var signInLogService = new SignInLogService();
            var reViewData       = new List <Infrastructure.ViewModel.ActivityFunction.Leave.SetAbsenceFormStatusResponse>();
            //設定審核狀態
            var status = string.Empty;

            switch (requestData.status)
            {
            case Infrastructure.ValueObject.enumAbsenceFormStatus.Invalid:
                status = "00";
                break;

            case Infrastructure.ValueObject.enumAbsenceFormStatus.Pass:
                status = "10";
                break;

            case Infrastructure.ValueObject.enumAbsenceFormStatus.Wait:
                status = "20";
                break;

            case Infrastructure.ValueObject.enumAbsenceFormStatus.Recall:
                status = "30";
                break;

            case Infrastructure.ValueObject.enumAbsenceFormStatus.Reject:
                status = "40";
                break;

            default:
                break;
            }
            foreach (var leave in requestData.OuterKey)
            {
                var eventId = Service.Utility.OuterKeyHelper.CheckOuterKey(leave);
                if (eventId.HasValue == false)
                {
                    continue;
                }
                //修改狀態
                var data = service.Update(eventId.Value, null, null, requestData.reason, status);
                //修改點名狀態
                //老師審核
                if (reviewLeave)
                {
                    var compareDay = activityService.GetActivitys(requestData.ClassID, data.LeaveDate);
                    if (requestData.status == enumAbsenceFormStatus.Pass)
                    {
                        response.Message = "審核成功";

                        foreach (var _signInInfo in compareDay)
                        {
                            var resReviewData  = new Infrastructure.ViewModel.ActivityFunction.Leave.SetAbsenceFormStatusResponse();
                            var signInOuterKey = OuterKeyHelper.GuidToPageToken(_signInInfo.OuterKey);
                            // 更新點名紀錄為請假   { 0, "未開放您參加此活動"},  { 1, "出席"}, { 2, "缺席"}, { "3", "遲到"}, { "4", "早退"},{"5", "請假"}
                            var signInlogInfo = signInLogService.GetSignInLog(checkToken.MemberId, _signInInfo.OuterKey, data.StudId);
                            if (signInlogInfo.Status == "2")
                            {
                                var updateSignInLog = signInLogService.UpdateLog(checkToken.MemberId, _signInInfo.OuterKey, data.StudId, "5");

                                //var mylog = _logService.GetLogs(eventId);
                                updateSignInLog.LeaveStatus = requestData.status.ToString();
                                SignalrClientHelper.SignIn_StatusChanged(requestData.ClassID, signInOuterKey, updateSignInLog);
                                if (_signInInfo.StartDate.Value != null)
                                {
                                    resReviewData.SignInOuterKey = signInOuterKey;
                                    resReviewData.SignInDateTime = _signInInfo.StartDate.Value;
                                    reViewData.Add(resReviewData);
                                }
                            }
                            else
                            {
                                var mylog = signInLogService.GetSignInLog(Convert.ToInt32(_signInInfo.CreateUser.ToString()), _signInInfo.OuterKey, data.StudId);
                                if (_signInInfo.StartDate.Value != null)
                                {
                                    resReviewData.SignInOuterKey = signInOuterKey;
                                    resReviewData.SignInDateTime = _signInInfo.StartDate.Value;
                                    reViewData.Add(resReviewData);
                                }
                                SignalrClientHelper.SignIn_StatusChanged(requestData.ClassID, signInOuterKey, mylog);
                            }
                            //_array.SetValue(signInOuterKey, _index);
                            // _index++;
                        }
                        response.Success = true;
                        //推播
                        pushService.PushOnUpdatedLeave(requestData.ClassID, eventId.Value, data.StudId, data.LeaveDate.ToLocalTime(), "已通過");
                        var noticeMsg = string.Format("您在({0:yyyy/MM/dd})的請假單「{1}」", data.LeaveDate.ToLocalTime(), "已通過", requestData.ClassID, DateTime.Now);
                        // 將通知寫入資料庫
                        activityService.AddNotice(requestData.ClassID.ToLower(), data.StudId, data.EventId, noticeMsg);
                        //發通知給學生
                        var connectIdAndNoticeData = signalrService.GetConnectIdAndData(requestData.ClassID, data.StudId, SignalrConnectIdType.One, SignalrDataType.Notice);
                        SignalrClientHelper.SendNotice(connectIdAndNoticeData);
                    } //駁回
                    else if (requestData.status == enumAbsenceFormStatus.Reject)
                    {
                        response.Message = string.Format("駁回,原因:{0}", requestData.reason);

                        foreach (var _signInInfo in compareDay)
                        {
                            var resReviewData = new Infrastructure.ViewModel.ReviewDataModel();
                            // var signInLog = _logService.GetLogs(_signInInfo.EventId);
                            var mylog = signInLogService.GetSignInLog(Convert.ToInt32(_signInInfo.CreateUser.ToString()), _signInInfo.OuterKey, data.StudId);
                            mylog.LeaveStatus = requestData.status.ToString();
                            var signInOuterKey = Service.Utility.OuterKeyHelper.GuidToPageToken(_signInInfo.OuterKey);
                            //var mylog = _logService.GetLogs(eventId);
                            SignalrClientHelper.SignIn_StatusChanged(requestData.ClassID, signInOuterKey, mylog);
                            //if (_signInInfo.Updated != null)
                            //{
                            //    resReviewData.SignInOuterKey = signInOuterKey;
                            //    resReviewData.SignInDateTime = _signInInfo.Updated.Local.Value;
                            //    reViewData.Add(resReviewData);
                            //}
                            // _array.SetValue(signInOuterKey, _index);
                            // _index++;
                        }
                        response.Success = true;
                        //推播
                        pushService.PushOnUpdatedLeave(requestData.ClassID, eventId.Value, data.StudId, data.LeaveDate.ToLocalTime(), "未通過");
                        var noticeMsg = string.Format("您在({0:yyyy/MM/dd})的請假單「{1}」", data.LeaveDate.ToLocalTime(), "未通過", requestData.ClassID, DateTime.Now);

                        // 將通知寫入資料庫
                        activityService.AddNotice(requestData.ClassID, data.StudId, eventId.Value, noticeMsg);

                        //發通知給學生
                        var connectIdAndNoticeData = signalrService.GetConnectIdAndData(requestData.ClassID, data.StudId, SignalrConnectIdType.One, SignalrDataType.Notice);
                        SignalrClientHelper.SendNotice(connectIdAndNoticeData);
                    }
                }//學生抽回
                else
                {
                    if (requestData.status == enumAbsenceFormStatus.Recall)
                    {
                        response.Message = "已抽回";

                        if (data != null)
                        {
                            response.Success = true;
                        }
                        else
                        {
                            response.State   = Infrastructure.ViewModel.Base.LogState.Error;
                            response.Success = false;
                            response.Message = "查無此請假單";
                        }
                    }
                    else
                    {
                        response.State   = Infrastructure.ViewModel.Base.LogState.Error;
                        response.Message = "無審核權限";
                        response.Success = false;
                    }
                }
                //發送推播
            }

            var _finalReviewData = new List <Infrastructure.ViewModel.ActivityFunction.Leave.SetAbsenceFormStatusResponse>();

            foreach (var _item in reViewData)
            {
                var che = _finalReviewData.Where(t => t.SignInOuterKey == _item.SignInOuterKey);
                if (!che.Any())
                {
                    _finalReviewData.Add(_item);
                }
            }
            response.Data = _finalReviewData.ToArray();
            return(Ok(response));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> POST()
        {
            discussionService = new DiscussionService();
            var result = new Infrastructure.ViewModel.Base.BaseResponse <string>();

            result.Success = false;
            result.Data    = "";
            await SetFileData();

            if (multipartFormDataStreamProvider.FormData == null)
            {
                result.Message = "遺漏參數";
                result.State   = Infrastructure.ViewModel.Base.LogState.RequestDataError;
                return(Content(HttpStatusCode.BadRequest, result));
            }
            //設定參數
            var token = multipartFormDataStreamProvider.FormData.Get("ICanToken") != null?multipartFormDataStreamProvider.FormData.GetValues("ICanToken")[0] : null;

            var circleKey = multipartFormDataStreamProvider.FormData.Get("ClassID") != null?multipartFormDataStreamProvider.FormData.GetValues("ClassID")[0] : null;

            var title = multipartFormDataStreamProvider.FormData.Get("Title") != null?multipartFormDataStreamProvider.FormData.GetValues("Title")[0] : null;

            var content = multipartFormDataStreamProvider.FormData.Get("Content") != null?multipartFormDataStreamProvider.FormData.GetValues("Content")[0] : null;

            if (token == null || circleKey == null || title == null)
            {
                result.Message = "遺漏參數";
                result.State   = Infrastructure.ViewModel.Base.LogState.RequestDataError;
                return(Content(HttpStatusCode.BadRequest, result));
            }
            multipartFormDataModel           = new DiscussionCreateRequestModel();
            multipartFormDataModel.Token     = Guid.Parse(token);
            multipartFormDataModel.CircleKey = circleKey.ToLower();
            multipartFormDataModel.Title     = title;
            multipartFormDataModel.Content   = content;
            var activityOuterKey = streamProvider.FormData.Get("activityOuterKey") != null?streamProvider.FormData.GetValues("activityOuterKey")[0] : null;

            var commentOuterKey = streamProvider.FormData.Get("commentOuterKey") != null?streamProvider.FormData.GetValues("commentOuterKey")[0] : null;

            var replyOuterKey = streamProvider.FormData.Get("replyOuterKey") != null?streamProvider.FormData.GetValues("replyOuterKey")[0] : null;

            var msg = streamProvider.FormData.Get("msg") != null?streamProvider.FormData.GetValues("msg")[0] : null;

            multipartFormDataModel.ActivityOuterKey = activityOuterKey != null ? activityOuterKey : null;
            multipartFormDataModel.CommentOuterKey  = commentOuterKey != null ? commentOuterKey : null;
            multipartFormDataModel.ReplyOuterKey    = replyOuterKey != null ? replyOuterKey : null;
            multipartFormDataModel.Msg = msg != null ? msg : null;

            //驗證token
            var checkMember = tokenService.GetTokenInfo(multipartFormDataModel.Token.ToString()).Result;

            if (checkMember != null)
            {
                authService           = new AuthService();
                discussionFileService = new DiscussionFuncFile();
                cacheService          = new CacheService();
                learingCircleService  = new LearningCircleService();
                var learningCircleInfo = learingCircleService.GetCourseLearningInfo(multipartFormDataModel.CircleKey);
                var hasAuth            = authService.CheckFunctionAuth(learningCircleInfo.Id, DiscussionFunction.Manage, checkMember.MemberId);
                //老師新增主題討論活動
                if (hasAuth)
                {
                    var newDiscussion = new Infrastructure.Entity.ActDiscussion();
                    //建立有附加檔案的主題討論
                    if (fileStreams.Count > 0)
                    {
                        var fileService = new FileService();
                        var files       = fileService.UploadFiles(checkMember.MemberId, multipartFormDataFiles, fileStreams.ToArray());
                        newDiscussion = discussionService.Add(multipartFormDataModel.CircleKey, checkMember.MemberId, multipartFormDataModel.Title, multipartFormDataModel.Content, files.Count(), 1);
                        //建立主題討論與檔案的關聯
                        var discussionFileReference = discussionFileService.DiscussionFileReference(newDiscussion.Id, files, null);
                    }
                    else
                    {
                        newDiscussion = discussionService.Add(multipartFormDataModel.CircleKey, checkMember.MemberId, multipartFormDataModel.Title, multipartFormDataModel.Content, 0, 1);
                    }
                    var rtn = new Infrastructure.ViewModel.ActivitysViewModel();
                    if (newDiscussion != null)
                    {
                        result.Success  = true;
                        result.Message  = "成功建立主題討論活動";
                        activityService = new ActivityService();
                        //顯示回傳app資訊
                        rtn = activityService.SignalrResponse(multipartFormDataModel.CircleKey, newDiscussion.EventId, ModuleType.Discussion, checkMember.MemberId, true);
                        //新增主題討論活動
                        var objHub = GlobalHost.ConnectionManager.GetHubContext <WiicoHub>();
                        objHub.Clients.Group(multipartFormDataModel.CircleKey.ToLower()).appendActivity(rtn, "");
                        //為了推播與發通知查詢學習圈成員
                        var members = cacheService.GetCircleMember(multipartFormDataModel.CircleKey);
                        if (members == null)
                        {
                            return(Ok(result));
                        }
                        var signalrService = new SignalrService();
                        //發通知
                        var connectIdAndData = signalrService.GetConnectIdAndData(multipartFormDataModel.CircleKey, checkMember.MemberId, SignalrConnectIdType.All, SignalrDataType.Activity);
                        SignalrClientHelper.ShowRecordListById(connectIdAndData);
                        //發通知
                        //  ShowRecordList(members, discussionData.CircleKey);
                        // 推播
                        PushDiscussionOnCreatedAsync(members, multipartFormDataModel.CircleKey, rtn.OuterKey, multipartFormDataModel.Title, checkMember.MemberId);
                    }
                    else
                    {
                        rtn            = null;
                        result.Success = false;
                        result.Message = "新增失敗";
                    }
                }
                else
                {
                    result.Success = false;
                    result.Message = "沒有權限";
                }
            }
            return(Ok(result));
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> POST()
        {
            var response = new Infrastructure.ViewModel.Base.BaseResponse <string>();

            response.Success = false;
            response.Data    = "";
            await SetFileData();

            multipartFormDataModel = new UploadFileModel();
            if (multipartFormDataStreamProvider.FormData == null)
            {
                response.Message = "遺漏參數";
                response.State   = Infrastructure.ViewModel.Base.LogState.RequestDataError;
                return(Content(HttpStatusCode.BadRequest, response));
            }

            //設定參數
            var token = multipartFormDataStreamProvider.FormData.Get("icantoken") != null?multipartFormDataStreamProvider.FormData.GetValues("icantoken")[0] : null;

            var circleKey = multipartFormDataStreamProvider.FormData.Get("classid") != null?multipartFormDataStreamProvider.FormData.GetValues("classid")[0] : null;

            var clientkey = multipartFormDataStreamProvider.FormData.Get("clientkey") != null?multipartFormDataStreamProvider.FormData.GetValues("clientkey")[0] : null;

            if (token == null || circleKey == null || clientkey == null)
            {
                response.Message = "遺漏參數";
                response.State   = Infrastructure.ViewModel.Base.LogState.RequestDataError;
                return(Content(HttpStatusCode.BadRequest, response));
            }

            multipartFormDataModel.Token     = Guid.Parse(token);
            multipartFormDataModel.CircleKey = circleKey.ToLower();
            multipartFormDataModel.ClientKey = clientkey;

            //新增上傳檔案活動
            var objHub = GlobalHost.ConnectionManager.GetHubContext <WiicoApi.SignalRHub.WiicoHub>();

            #region  的設定參數方法

            /*  var _info = HttpContext.Current.Request.Form;
             * var files = HttpContext.Current.Request.Files;
             *
             *
             * //文大版 參數
             * if (_info["token"] != null)
             * {
             *    uploadInfo.CircleKey = _info["circleKey"].ToString();
             *    uploadInfo.ClientKey = _info["clientKey"].ToString();
             *    uploadInfo.Token = Guid.Parse(_info["token"].ToString());
             * }
             * //雲端版 參數
             * if (_info["icantoken"] != null)
             * {
             *    uploadInfo.Token = Guid.Parse(_info["icantoken"].ToString());
             *    uploadInfo.CircleKey = _info["classid"].ToString();
             *    uploadInfo.ClientKey = _info["clientkey"].ToString();
             * }*/
            //uploadInfo.Title = _info["title"].ToString();
            //uploadInfo.Content = _info["content"].ToString();
            #endregion
            var data = materialService.Insert(multipartFormDataModel.CircleKey, multipartFormDataModel.Token.ToString(), multipartFormDataFiles, fileStreams.ToArray());
            var rtn  = materialService.addPanelInfo(data.OuterKey, Convert.ToInt32(data.Creator), multipartFormDataModel.CircleKey);

            objHub.Clients.Group(multipartFormDataModel.CircleKey.ToLower()).appendActivity(rtn, multipartFormDataModel.ClientKey.ToLower());
            response.Success = true;
            response.Message = "上傳成功";
            response.Data    = "上傳成功";
            //單元測試結果
            if (HttpContext.Current == null)
            {
                return(Ok(response));
            }

            var signalrService = new SignalrService();
            //發通知
            var connectIdAndData = signalrService.GetConnectIdAndData(multipartFormDataModel.CircleKey, Convert.ToInt32(data.Creator), SignalrConnectIdType.All, SignalrDataType.Activity);
            SignalrClientHelper.ShowRecordListById(connectIdAndData);
            //發通知
            // ShowRecordList(uploadInfo.CircleKey.ToLower());
            // 推播
            PushMaterialOnCreatedAsync(multipartFormDataModel.CircleKey.ToLower(), data.OuterKey, multipartFormDataModel.Title, Convert.ToInt32(data.Creator));
            return(Ok(response));
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> Put()
        {
            discussionService = new DiscussionService();
            var response = new Infrastructure.ViewModel.Base.BaseResponse <string>();

            response.Success = false;
            response.Data    = "";
            await SetFileData();

            if (multipartFormDataStreamProvider.FormData == null)
            {
                response.Message = "遺漏參數";
                response.State   = Infrastructure.ViewModel.Base.LogState.RequestDataError;
                return(Content(HttpStatusCode.BadRequest, response));
            }

            //設定參數
            var token = multipartFormDataStreamProvider.FormData.Get("ICanToken") != null?multipartFormDataStreamProvider.FormData.GetValues("ICanToken")[0] : null;

            var circleKey = multipartFormDataStreamProvider.FormData.Get("ClassID") != null?multipartFormDataStreamProvider.FormData.GetValues("ClassID")[0] : null;

            var title = multipartFormDataStreamProvider.FormData.Get("Title") != null?multipartFormDataStreamProvider.FormData.GetValues("Title")[0] : null;

            var content = multipartFormDataStreamProvider.FormData.Get("Content") != null?multipartFormDataStreamProvider.FormData.GetValues("Content")[0] : null;

            var activityOuterKey = multipartFormDataStreamProvider.FormData.Get("activityOuterKey") != null?multipartFormDataStreamProvider.FormData.GetValues("activityOuterKey")[0] : null;

            var removeFiles = multipartFormDataStreamProvider.FormData.Get("removeFiles") != null?multipartFormDataStreamProvider.FormData.GetValues("removeFiles")[0] : null;

            if (token == null || circleKey == null || title == null || activityOuterKey == null)
            {
                response.Message = "遺漏參數";
                response.State   = Infrastructure.ViewModel.Base.LogState.RequestDataError;
                return(Content(HttpStatusCode.BadRequest, response));
            }
            multipartFormDataModel           = new  DiscussionCreateRequestModel();
            multipartFormDataModel.Token     = Guid.Parse(token);
            multipartFormDataModel.CircleKey = circleKey.ToLower();
            multipartFormDataModel.Title     = title;
            multipartFormDataModel.Content   = content;

            var commentOuterKey = multipartFormDataStreamProvider.FormData.Get("commentOuterKey") != null?multipartFormDataStreamProvider.FormData.GetValues("commentOuterKey")[0] : null;

            var replyOuterKey = multipartFormDataStreamProvider.FormData.Get("replyOuterKey") != null?multipartFormDataStreamProvider.FormData.GetValues("replyOuterKey")[0] : null;

            var msg = multipartFormDataStreamProvider.FormData.Get("msg") != null?multipartFormDataStreamProvider.FormData.GetValues("msg")[0] : null;

            multipartFormDataModel.ActivityOuterKey = activityOuterKey != null ? activityOuterKey : null;
            multipartFormDataModel.CommentOuterKey  = commentOuterKey != null ? commentOuterKey : null;
            multipartFormDataModel.ReplyOuterKey    = replyOuterKey != null ? replyOuterKey : null;
            multipartFormDataModel.Msg = msg != null ? msg : null;

            //驗證token
            var checkMember = tokenService.GetTokenInfo(multipartFormDataModel.Token.ToString()).Result;

            if (checkMember != null && activityOuterKey != null)
            {
                authService          = new AuthService();
                learingCircleService = new LearningCircleService();
                var learningCircleInfo = learingCircleService.GetCourseLearningInfo(multipartFormDataModel.CircleKey);
                var hasAuth            = authService.CheckFunctionAuth(learningCircleInfo.Id, DiscussionFunction.Manage, checkMember.MemberId);

                //老師編輯主題討論活動
                if (hasAuth)
                {
                    discussionFileService = new DiscussionFuncFile();
                    var updateDiscussion = new Infrastructure.Entity.ActDiscussion();
                    if (multipartFormDataFiles.Count > 0)
                    {
                        var fileService    = new FileService();
                        var uploadFileInfo = fileService.UploadFiles(checkMember.MemberId, multipartFormDataFiles, fileStreams.ToArray());
                        updateDiscussion = discussionService.Update(multipartFormDataModel, checkMember.MemberId, uploadFileInfo.Count);
                        //建立主題討論與檔案的關聯
                        var discussionFileReference = discussionFileService.DiscussionFileReference(updateDiscussion.Id, uploadFileInfo, null);
                    }
                    else
                    {
                        updateDiscussion = discussionService.Update(multipartFormDataModel, checkMember.MemberId, 0);
                    }

                    if (updateDiscussion != null)
                    {
                        cacheService = new CacheService();
                        //刪除檔案
                        if (removeFiles != null && removeFiles != string.Empty)
                        {
                            var removeFilesArray = removeFiles.Split(',');
                            //刪除主題討論與檔案的關聯
                            discussionFileService.DeleteDiscussionFileReference(updateDiscussion.Id, removeFilesArray);
                        }
                        var rtn = discussionService.GetUpdateDetailByEventId(updateDiscussion.EventId);
                        response.Success = true;
                        response.Message = "成功編輯主題討論活動";
                        objHub.Clients.Group(multipartFormDataModel.CircleKey.ToLower()).updateDetail("discussion", rtn);
                        //為了推播與發通知查詢學習圈成員
                        var members = cacheService.GetCircleMember(multipartFormDataModel.CircleKey);
                        //為了單元測試用
                        if (members == null)
                        {
                            return(Ok(response));
                        }
                        // 推播
                        PushDiscussionOnUpdateAsync(members, multipartFormDataModel.CircleKey, updateDiscussion.EventId, multipartFormDataModel.Title, checkMember.MemberId);

                        var signalrService = new SignalrService();
                        //發通知
                        var connectIdAndData = signalrService.GetConnectIdAndData(multipartFormDataModel.CircleKey, checkMember.MemberId, SignalrConnectIdType.All, SignalrDataType.Activity);
                        SignalrClientHelper.ShowRecordListById(connectIdAndData);
                        //發通知
                        //ShowRecordList(members, discussionData.CircleKey);
                    }
                    else
                    {
                        response.Success = false;
                        response.Message = "編輯失敗";
                    }
                }
                else
                {
                    response.Success = false;
                    response.Message = "沒有權限";
                }
            }
            return(Ok(response));
        }