예제 #1
0
        async Task OnSubmitHandle()
        {
            LoadSpinner.Show();
            try
            {
                if (BookModel.CategoryId == null || BookModel.CategoryId.Contains("..."))
                {
                    throw new Exception("Виберіть категорію!");
                }
                BookModel.Year       = Year.ToString();
                BookModel.Image      = null;
                BookModel.DateCreate = DateTime.Now;
                BookModel.IsEbook    = IsEBook;

                await authService.RefreshToken();

                var result = await LibraryService.CreateBookAsync(BookModel);

                await LibraryService.UploadBookImage(result.Id, new ImageApiModel { Photo = ImageBase64 });
                await FileUpload(result.Id);

                Toast.ShowSuccess("Книга успішно додана!");
                NavigationManager.NavigateTo(QueryHelpers.AddQueryString("/book", "bookId", result.Id));
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                Toast.ShowError(ex.Message);
                Console.WriteLine("Error Message: " + ErrorMessage);
            }
            finally
            {
                LoadSpinner.Hide();
            }
        }
예제 #2
0
        async void OnSubmitHandle()
        {
            LoadSpinner.Show();
            try
            {
                var message = new CallOwnerApiModel();
                message.Subject = Subject;
                message.Text    = Text;
                message.BookId  = BookItem.Id;
                await AuthService.RefreshToken();

                await HttpService.Post <CallOwnerApiModel, MessageApiModel>(ApiUrls.CallToOwner, message);

                Toast.ShowSuccess("Повідомлення успішно відправлено!");
                NavigationManager.NavigateTo("/index");
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                Toast.ShowError("Помилка. Повідомлення не відправлено!");
                Console.WriteLine("Error Message: " + ErrorMessage);
            }
            finally
            {
                LoadSpinner.Hide();
            }
        }
예제 #3
0
        async Task ImageFileSelected()
        {
            LoadSpinner.Show();
            IsImageSelected = true;
            foreach (var file in await FileReaderService.CreateReference(InputElementImage).EnumerateFilesAsync())
            {
                using (MemoryStream memoryStream = await file.CreateMemoryStreamAsync(4 * 1024))
                {
                    var imageBytes = new byte[memoryStream.Length];
                    memoryStream.Read(imageBytes, 0, (int)memoryStream.Length);
                    ImageBase64   = Convert.ToBase64String(imageBytes);
                    ImageUrl      = $"data:image/jpeg;base64, {ImageBase64}";
                    IsPhotoLoaded = true;
                }
            }

            StateHasChanged();
            LoadSpinner.Hide();
        }