Notes features are ready
This commit is contained in:
@ -30,20 +30,53 @@ else
|
||||
<hr />
|
||||
<SfButton CssClass="e-primary" IconCss="e-icons e-save" Content="Save" type="submit" />
|
||||
</EditForm>
|
||||
<p>
|
||||
<SfMessage Severity="MessageSeverity.Success" Visible="showSuccessMessage">
|
||||
Contact saved successfully.
|
||||
</SfMessage>
|
||||
<SfMessage Severity="MessageSeverity.Error" Visible="showErrorMessage">
|
||||
Oops, something went wrong.
|
||||
</SfMessage>
|
||||
</p>
|
||||
@if(Id is not null)
|
||||
{
|
||||
<h3>Notes</h3>
|
||||
<SfTextBox CssClass="e-outline" Placeholder="New Note" Multiline="true"
|
||||
FloatLabelType="@FloatLabelType.Auto" @bind-Value="newNote.Text"></SfTextBox>
|
||||
<SfButton CssClass="e-inherit" Content="Add Note" OnClick="CreateNote" ></SfButton>
|
||||
<hr />
|
||||
<p>
|
||||
<SfButton IsPrimary="true" Content="Load All Notes" OnClick="LoadNotes"></SfButton>
|
||||
@foreach(var note in notes)
|
||||
{
|
||||
<SfCard>
|
||||
<CardHeader Title="@note.DateCreated.ToString()"></CardHeader>
|
||||
<CardContent Content="@note.Text"></CardContent>
|
||||
<CardFooter>
|
||||
<CardFooterContent>
|
||||
<SfButton
|
||||
Content ="Delete"
|
||||
IsPrimary ="true"
|
||||
OnClick="@(() => DeleteNote(note.Id))"
|
||||
></SfButton>
|
||||
</CardFooterContent>
|
||||
</CardFooter>
|
||||
</SfCard>
|
||||
<br />
|
||||
}
|
||||
</p>
|
||||
}
|
||||
|
||||
</div>
|
||||
<p>
|
||||
<SfMessage Severity="MessageSeverity.Success" Visible="showSuccessMessage">
|
||||
Contact saved successfully.
|
||||
</SfMessage>
|
||||
<SfMessage Severity="MessageSeverity.Error" Visible="showErrorMessage">
|
||||
Oops, something went wrong.
|
||||
</SfMessage>
|
||||
</p>
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public int? Id { get; set; }
|
||||
|
||||
public Contact contact { get; set; } = new Contact();
|
||||
public List<Note> notes { get; set; } = new List<Note>();
|
||||
public Note newNote { get; set; } = new Note { Text = string.Empty };
|
||||
|
||||
bool showSuccessMessage = false;
|
||||
bool showErrorMessage = false;
|
||||
@ -88,4 +121,29 @@ else
|
||||
showErrorMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
async Task CreateNote()
|
||||
{
|
||||
if (Id is null)
|
||||
return;
|
||||
|
||||
newNote.ContactId = Id;
|
||||
var result = await Http.PostAsJsonAsync($"api/notes", newNote);
|
||||
if (result.IsSuccessStatusCode)
|
||||
await LoadNotes();
|
||||
}
|
||||
|
||||
async Task DeleteNote(int noteId)
|
||||
{
|
||||
var result = await Http.DeleteFromJsonAsync<List<Note>>($"api/notes/{noteId}");
|
||||
if (result is not null)
|
||||
notes = result;
|
||||
}
|
||||
|
||||
async Task LoadNotes()
|
||||
{
|
||||
var result = await Http.GetFromJsonAsync<List<Note>>($"api/notes/{contact.Id}");
|
||||
if (result is not null)
|
||||
notes = result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user