示例#1
0
        public MeetingAttendPageViewModel(INavigationService navigationService) : base(navigationService)
        {
            _navigationService     = navigationService;
            _restService           = new RestService();
            _operateDateTime       = new OperateDateTime();
            _applicationProperties = new ApplicationProperties();

            _createMeetingLabelItemParam = new CreateMeetingLabelItemParam();
            _attendMeetingParam          = new AttendMeetingParam();
            _deleteMeetingLabelItemParam = new DeleteMeetingLabelItemParam();

            _createMeetingLabelItemValidation = new CreateMeetingLabelItemValidation();
            _tokenCheckValidation             = new TokenCheckValidation(_restService);
            _attendMeetingValidation          = new AttendMeetingValidation();


            //ラベルに関する項目を追加するページへ遷移するコマンド
            NavigateMeetingLabelItemDataCreatePage = new DelegateCommand <object>((meetingLabelData) =>
            {
                var targetMeetingLabelData = (MeetingLabelData)(meetingLabelData);

                var p = new NavigationParameters
                {
                    { "meetingLabelData", targetMeetingLabelData },
                };
                _navigationService.NavigateAsync("MeetingLabelItemDataCreatePage", p);
            });


            //会議に入室するコマンド
            EnterMeetingCommand = new DelegateCommand(async() =>
            {
                //バリデーション
                AttendMeetingParam = _attendMeetingValidation.ButtonPushedValidate(new List <MeetingLabelData>(TargetMeetingLabels));


                if (AttendMeetingParam.IsSuccessed == true)
                {
                    GetUserParam = await _restService.GetUserDataAsync(UserConstants.OpenUserEndPoint, _applicationProperties.GetFromProperties <string>("userId"));

                    var mid = GetMeetingParam.MeetingData.Id;
                    var uid = GetUserParam.User.Id;

                    //ParticipantDBに既にユーザーが居ないかチェック
                    CheckParticipantParam = await _restService.CheckParticipantDataAsync(MeetingConstants.OPENMeetingParticipantEndPoint, uid, mid);

                    //ユーザーが既にParticipantDBに存在していた場合
                    if (CheckParticipantParam.IsSuccessed == true)
                    {
                        //会議参加済みかつisDeletedがfalseの場合は最終更新時刻のみ更新し遷移する
                        if (CheckParticipantParam.Participant.isDeleted == false)
                        {
                            var operateDateTime = new OperateDateTime();
                            CheckParticipantParam.Participant.LastUpdateTime = operateDateTime.CurrentDateTime;
                            var updateParticipant = CheckParticipantParam.Participant;
                            await _restService.UpdateParticipantDataAsync(MeetingConstants.OPENMeetingParticipantEndPoint, updateParticipant);

                            var p = new NavigationParameters
                            {
                                { "mid", GetMeetingParam.MeetingData.Id }
                            };
                            await _navigationService.NavigateAsync("MeetingExecuteTopPage", p);
                        }
                        else
                        //参加済みかつ論理削除済みの場合はisDeletedをtrue→falseにして再入室
                        {
                            var operateDateTime = new OperateDateTime();
                            CheckParticipantParam.Participant.isDeleted      = false;
                            CheckParticipantParam.Participant.LastUpdateTime = operateDateTime.CurrentDateTime;
                            var updateParticipant = CheckParticipantParam.Participant;

                            await _restService.UpdateParticipantDataAsync(MeetingConstants.OPENMeetingParticipantEndPoint, updateParticipant);

                            var p = new NavigationParameters
                            {
                                { "mid", GetMeetingParam.MeetingData.Id }
                            };
                            await _navigationService.NavigateAsync("MeetingExecuteTopPage", p);
                        }
                    }
                    //ParticipantDBに該当者が居なければ追加
                    else
                    {
                        CreateParticipateParam = await _restService.CreateParticipateDataAsync(MeetingConstants.OPENMeetingParticipantEndPoint, uid, mid);

                        if (CreateParticipateParam.IsSuccessed == true)
                        {
                            var p = new NavigationParameters
                            {
                                { "mid", GetMeetingParam.MeetingData.Id }
                            };
                            await _navigationService.NavigateAsync("MeetingExecuteTopPage", p);
                        }
                    }
                }
            });

            //会議入室画面から退室するコマンド
            ExitMeetingCommand = new DelegateCommand(async() =>
            {
                //TargetMeetingLabelsが所持しているItemsを削除する
                foreach (MeetingLabelData l in TargetMeetingLabels)
                {
                    foreach (MeetingLabelItemData i in l.MeetingLabelItemDatas)
                    {
                        DeleteMeetingLabelItemParam = await _restService.DeleteMeetingLabelItemDataAsync(MeetingConstants.OPENMeetingLabelItemEndPoint, i.Id);
                    }
                }

                await _navigationService.NavigateAsync("/NavigationPage/MeetingDataTopPage");
            });
        }