예제 #1
0
        async void AddNew(object sender, System.EventArgs e)
        {
            if (string.IsNullOrEmpty(folderID))
            {
                var promptConfig = new PromptConfig
                {
                    Text          = "New Folder",
                    OnTextChanged = args =>
                    {
                        args.IsValid = true;                         // setting this to false will disable the OK/Positive button
                    }
                };
                PromptResult dialog = await UserDialogs.Instance.PromptAsync(promptConfig);

                if (dialog.Ok)
                {
                    var folder = new FolderRequest
                    {
                        categoryName = dialog.Value,
                        visibility   = true
                    };
                    var result = service.InsertFolder(App.Current.Properties["defaultPid"].ToString(), folder);
                    if (result != null)
                    {
                        await LoadFolder();
                    }
                }
            }
            else
            {
                try
                {
                    var picker = await CrossFilePicker.Current.PickFile();

                    var    byteArray = picker.DataArray;
                    string filePath  = App.Current.Properties["defaultPid"].ToString() + "/files/upload/";
                    var    name      = picker.FileName;
                    this.isBusy         = true;
                    newButton.IsEnabled = false;
                    var fileUpload = await AzureStorage.UploadFileAsync(ContainerType.condo, new MemoryStream(byteArray), filePath + name);

                    if (!string.IsNullOrEmpty(fileUpload))
                    {
                        var file = new FileRequest
                        {
                            filePath    = fileUpload,
                            fileName    = name,
                            visibility  = true,
                            description = name,
                        };

                        var result = await service.InsertFile(App.Current.Properties["defaultPid"].ToString(), folderID, file);

                        if (result != null)
                        {
                            if (result.status_code == System.Net.HttpStatusCode.Created)
                            {
                                await LoadFiles(folderID);
                            }
                            else
                            {
                                await DisplayAlert("Error", result.message, "OK");
                            }
                        }
                        else
                        {
                            await DisplayAlert("Error", Config.CommonErrorMsg, "OK");
                        }

                        newButton.IsEnabled = true;
                    }
                    this.isBusy = false;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
예제 #2
0
        async void FolderButton_Clicked(object sender, EventArgs e)
        {
            Button button       = sender as Button;
            var    promptConfig = new PromptConfig
            {
                OnTextChanged = args =>
                {
                    args.IsValid = true;                     // setting this to false will disable the OK/Positive button
                }
            };

            if (folderList.ContainsKey(button.StyleId))
            {
                string lockButtonName = "Lock";
                if (folderList[button.StyleId].visibility == false)
                {
                    lockButtonName = "Unlock";
                }
                var res = await DisplayActionSheet("Select Action", "OK", "Cancel", "Rename", lockButtonName, "Delete");

                if (res == "Rename")
                {
                    promptConfig.Text = "New folder name";
                    PromptResult dialog = await UserDialogs.Instance.PromptAsync(promptConfig);

                    if (dialog.Ok)
                    {
                        var folder = new FolderRequest
                        {
                            categoryName = dialog.Value
                        };
                        isBusy = true;
                        var result = await service.UpdateFolder(App.Current.Properties["defaultPid"].ToString(), button.StyleId, folder);

                        isBusy = false;
                        if (result != null)
                        {
                            await LoadFolder();
                        }
                    }
                }
                else if (res == "Lock")
                {
                    var folder = new FolderRequest
                    {
                        visibility = false
                    };
                    isBusy = true;
                    var result = await service.UpdateFolder(App.Current.Properties["defaultPid"].ToString(), button.StyleId, folder);

                    isBusy = false;
                    if (result != null)
                    {
                        await LoadFolder();
                    }
                }
                else if (res == "Unlock")
                {
                    var folder = new FolderRequest
                    {
                        visibility = true
                    };
                    isBusy = true;
                    var result = await service.UpdateFolder(App.Current.Properties["defaultPid"].ToString(), button.StyleId, folder);

                    isBusy = false;
                    if (result != null)
                    {
                        await LoadFolder();
                    }
                }
                else if (res == "Delete")
                {
                    var alert = await DisplayAlert("Confirm", "Are you sure to remove?", "OK", "Cancel");

                    if (alert)
                    {
                        isBusy = true;
                        var result = await service.DeleteFolder(App.Current.Properties["defaultPid"].ToString(), button.StyleId);

                        isBusy = false;
                        if (result != null)
                        {
                            await LoadFolder();
                        }
                    }
                }
            }
        }