Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.2 kB
3
Indexable
SimilarFilmsPortal

@inject IAdminService AdminService

@if (!string.IsNullOrEmpty(Alert))
{
    <div class="d-flex">
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <strong>@Alert</strong>
            <button type="button" @onclick="CloseAlert" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    </div>
}

@if (Navigation == PageType.Create)
{
    <ChangeSimilarFilms Page="@Navigation" OnChange="OnChange"></ChangeSimilarFilms>
}
@if (Navigation == PageType.Delete)
{
    <ChangeSimilarFilms Page="@Navigation" OnChange="OnChange" Model="SimilarFilm"></ChangeSimilarFilms>
}


<div class="d-flex me-1">
    <a href="/" class="btn btn-outline-secondary rounded-0 me-1">Home</a>
    <button type="button" class="btn btn-outline-primary rounded-0 me-1" @onclick="()=>ChangePageType(PageType.Index)">SimilarFilm</button>
    <button type="button" class="btn btn-outline-success rounded-0" @onclick="()=>ChangePageType(PageType.Create)">Add SimilarFilm</button>
</div>

<SimilarFilmsIndex OnClick="OnClick" Model="Model"></SimilarFilmsIndex>

@code {
    List<SimilarFilmsDTO> Model = new();
    string Alert { get; set; } = "";
    string Navigation { get; set; } = PageType.Index;
    public SimilarFilmsDTO SimilarFilm { get; set; } = new();

    protected override async Task OnInitializedAsync()
    {
        Alert = "";
        Model = await AdminService.GetAsync<SimilarFilmsDTO>("similarfilms");
    }

    void ChangePageType(string pageType) => Navigation = pageType;

    void CloseAlert() => Alert = "";

    async Task OnClick(ClickReferenceModel model)
    {
        if (model.PageType.Equals(PageType.Delete))
            SimilarFilm.FilmId = model.firstId;
        SimilarFilm.SimilarFilmId = model.secondId;

        ChangePageType(model.PageType);
    }

    async Task OnChange(string alert)
    {
        try
        {
            Alert = alert;
            Model = await AdminService.GetAsync<SimilarFilmsDTO>("similarfilms");
            ChangePageType(PageType.Index);
        }
        catch
        {
            Alert = "Couldn't create/edit/delete the SimilarFilm.";
        }
    }
}