78 lines
2.5 KiB
C#
78 lines
2.5 KiB
C#
using MudBlazor;
|
|
|
|
namespace Netina.AdminPanel.PWA.Dialogs;
|
|
|
|
public class PageSectionActionDialogBoxViewModel : BaseViewModel<BasePageSection>
|
|
{
|
|
private readonly ISnackbar _snackbar;
|
|
private readonly IRestWrapper _restWrapper;
|
|
private readonly IUserUtility _userUtility;
|
|
private readonly IDialogService _dialogService;
|
|
private readonly MudDialogInstance _mudDialog;
|
|
|
|
public bool IsEditing = false;
|
|
|
|
|
|
public PageSectionActionDialogBoxViewModel(ISnackbar snackbar,
|
|
IRestWrapper restWrapper,
|
|
IUserUtility userUtility,
|
|
IDialogService dialogService,
|
|
MudDialogInstance mudDialog) : base(userUtility)
|
|
{
|
|
_snackbar = snackbar;
|
|
_restWrapper = restWrapper;
|
|
_userUtility = userUtility;
|
|
_dialogService = dialogService;
|
|
_mudDialog = mudDialog;
|
|
}
|
|
|
|
public PageSectionActionDialogBoxViewModel(ISnackbar snackbar,
|
|
IRestWrapper restWrapper,
|
|
IUserUtility userUtility,
|
|
IDialogService dialogService,
|
|
MudDialogInstance mudDialog,
|
|
BasePageSection page) : base(userUtility)
|
|
{
|
|
_snackbar = snackbar;
|
|
_restWrapper = restWrapper;
|
|
_userUtility = userUtility;
|
|
_dialogService = dialogService;
|
|
_mudDialog = mudDialog;
|
|
IsEditing = true;
|
|
PageDto = page;
|
|
}
|
|
|
|
public void Cancel() => _mudDialog.Cancel();
|
|
|
|
public void Submit()
|
|
{
|
|
_snackbar.Add($"ویرایش {PageDto.Title} با موفقیت انجام شد", Severity.Success);
|
|
_mudDialog.Close(DialogResult.Ok(PageDto));
|
|
}
|
|
|
|
public SectionItem SelectedSectionItem { get; set; } = new();
|
|
public StorageFileSDto SelectedFile { get; set; } = new();
|
|
public bool IsFileSelected { get; set; } = false;
|
|
public void AddItem()
|
|
{
|
|
SelectedSectionItem.ImageLocation = SelectedFile.FileLocation;
|
|
PageDto.SectionItems.Add(SelectedSectionItem);
|
|
SelectedSectionItem = new SectionItem();
|
|
SelectedFile = new StorageFileSDto();
|
|
IsFileSelected = false;
|
|
}
|
|
|
|
|
|
public async Task SelectFileAsync()
|
|
{
|
|
DialogOptions maxWidth = new DialogOptions() { MaxWidth = MaxWidth.Medium, FullWidth = true, DisableBackdropClick = true };
|
|
var dialog = await _dialogService.ShowAsync<StorageDialogBox>("انتخاب عکس", maxWidth);
|
|
var result = await dialog.Result;
|
|
var file = result.Data;
|
|
if (file is StorageFileSDto storageFile)
|
|
{
|
|
SelectedFile = storageFile;
|
|
IsFileSelected = true;
|
|
}
|
|
}
|
|
} |