Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
@code {
    List<FilmDTO> Model { get; set; } = new();
    string Alert = string.Empty;
    string Navigation = string.Empty;
    public FilmDTO Film { get; set; } = new();
    void ChangePageType(string pageType) => Navigation = pageType;
    void CloseAlert() => Alert = string.Empty;

    async Task OnClick(ClickModel model)
    {
        if (model.pageType.Equals(PageType.Edit) || model.pageType.Equals(PageType.Delete))
            Film = await AdminService.SingleAsync<FilmDTO>($"films/{model.id}") ?? new();

        ChangePageType(model.pageType);
    }

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

    //List<FilmDTO> Model { get; set; } = new();
    protected override async Task OnInitializedAsync()
    {
        Alert = string.Empty;

        await AdminService.CreateAsync<FilmCreateDTO>($"Films", new FilmCreateDTO(){ ThumbnailURL="", Title="FreeGuy", Free = true, Description ="", DirectorId=2, FilmUrl ="", Released= new DateTime(12,01,01)} );
        //await AdminService.EditAsync<FilmDTO>($"Films/1", new FilmDTO());
        //Alert = "Test message";//string.Empty;
        Model = await AdminService.GetAsync<FilmDTO>($"Films?freeonly=true");
    }