コード例 #1
0
ファイル: RestService.cs プロジェクト: basaaaaa/MeetingApp
        /// <summary>
        /// 会議に対するラベルを新規追加するAPIコール
        /// </summary>
        /// <param name="uri">コールするURL</param>
        /// <param name="labelName">追加するラベルの名前</param>
        /// <param name="mid">ラベルを追加する対象の会議ID</param>
        /// <returns>CreateMeetingLabelParam</returns>
        public async Task <CreateMeetingLabelParam> CreateMeetingLabelDataAsync(string uri, string labelName, int mid)
        {
            var meetingLabel = new MeetingLabelData(mid, labelName);
            var json         = JsonConvert.SerializeObject(meetingLabel);

            var createMeetingLabelParam = new CreateMeetingLabelParam();

            try
            {
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                //入力されたカードラベル名が空かどうかチェック
                if (string.IsNullOrEmpty(labelName))
                {
                    //存在していた場合POSTを失敗で終了
                    createMeetingLabelParam.HasError       = true;
                    createMeetingLabelParam.BlankLabelName = true;
                    return(createMeetingLabelParam);
                }


                var response = await _client.PostAsync(uri, content);

                if (response.IsSuccessStatusCode)
                {
                    string responseContent = await response.Content.ReadAsStringAsync();

                    Console.WriteLine(responseContent);
                    createMeetingLabelParam.IsSuccessed = response.IsSuccessStatusCode;
                    return(createMeetingLabelParam);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(createMeetingLabelParam);
        }
コード例 #2
0
        public CreateMeetingLabelParam InputValidate(string labelName)
        {
            var createMeetingLabelParam = new CreateMeetingLabelParam();

            //ラベル名が空だった場合
            if (string.IsNullOrEmpty(labelName))
            {
                createMeetingLabelParam.HasError       = true;
                createMeetingLabelParam.BlankLabelName = true;
                return(createMeetingLabelParam);
            }
            //ラベル名が長すぎた場合
            if (labelName.Length > 12)
            {
                createMeetingLabelParam.HasError = true;
                createMeetingLabelParam.MeetingLabelNameCharactersOver = true;
                return(createMeetingLabelParam);
            }

            createMeetingLabelParam.IsSuccessed = true;

            return(createMeetingLabelParam);
        }
コード例 #3
0
        public MeetingDataCreatePageViewModel(INavigationService navigationService) : base(navigationService)
        {
            _navigationService = navigationService;

            _restService           = new RestService();
            _applicationProperties = new ApplicationProperties();

            _createMeetingParam      = new CreateMeetingParam();
            _createMeetingLabelParam = new CreateMeetingLabelParam();

            _createMeetingValidation      = new CreateMeetingValidation();
            _createMeetingLabelValidation = new CreateMeetingLabelValidation();

            Labels = new ObservableCollection <MeetingLabelData>();


            //入力初期値
            InputMeetingDate = DateTime.UtcNow;

            CreateMeetingDataCommand = new DelegateCommand(async() =>

            {
                //会議情報入力値のバリデーション処理
                CreateMeetingParam = _createMeetingValidation.InputValidate(InputMeetingTitle, InputMeetingDate, InputMeetingStartTime, InputMeetingEndTime, InputMeetingLocation, Labels);

                //バリデーションエラーが存在すれば失敗で返す
                if (CreateMeetingParam.HasError == true)
                {
                    return;
                }

                //DateTimeとTimeSpanを結合
                var InputMeetingStartDateTime = InputMeetingDate + InputMeetingStartTime;
                var InputMeetingEndDateTime   = InputMeetingDate + InputMeetingEndTime;

                //userIdに対するidを取得
                var getUserParam = await _restService.GetUserDataAsync(UserConstants.OpenUserEndPoint, _applicationProperties.GetFromProperties <string>("userId"));

                //ユーザー取得時にエラーがあれば処理終了
                if (getUserParam.HasError == true)
                {
                    return;
                }

                //Json用のモデルを作成
                CreateMeetingData = new MeetingData();

                CreateMeetingData.Title         = InputMeetingTitle;
                CreateMeetingData.StartDatetime = InputMeetingStartDateTime;
                CreateMeetingData.EndDatetime   = InputMeetingEndDateTime;
                CreateMeetingData.Regular       = false;
                CreateMeetingData.Owner         = getUserParam.User.Id;
                CreateMeetingData.Location      = InputMeetingLocation;
                CreateMeetingData.IsVisible     = true;

                //会議作成APIのコール
                CreateMeetingParam = await _restService.CreateMeetingDataAsync(MeetingConstants.OpenMeetingEndPoint, CreateMeetingData, Labels);

                //会議作成が成功すればMeetingDataTopPageに遷移する
                if (CreateMeetingParam.IsSuccessed == true)
                {
                    await _navigationService.NavigateAsync("/NavigationPage/MeetingDataTopPage");
                }
            });

            //ラベル追加の際のコマンド
            CreateMeetingLabelCommand = new DelegateCommand(() =>
            {
                //作成するラベル名のバリデーション
                CreateMeetingLabelParam = _createMeetingLabelValidation.InputValidate(CreateLabelName);
                //ラベル作成に失敗すれば処理中断
                if (CreateMeetingLabelParam.HasError == true)
                {
                    return;
                }

                //リストにラベル情報を保持
                var label = new MeetingLabelData(CreateLabelName);
                Labels.Add(label);
                CreateLabelName = "";

                //ViewにおけるFrameの高さを大きくする
                LabelListViewHeight += 85;
            });

            NavigateMeetingDataTopPage = new DelegateCommand(() =>
            {
                //会議情報TOPページへ遷移
                _navigationService.NavigateAsync("/NavigationPage/MeetingDataTopPage");
            });
        }