diff --git a/BlazorSyncfusionCrm/Client/Pages/EditContact.razor b/BlazorSyncfusionCrm/Client/Pages/EditContact.razor
index 9a1cf12..59da650 100644
--- a/BlazorSyncfusionCrm/Client/Pages/EditContact.razor
+++ b/BlazorSyncfusionCrm/Client/Pages/EditContact.razor
@@ -30,20 +30,53 @@ else
+
+
+ Contact saved successfully.
+
+
+ Oops, something went wrong.
+
+
+ @if(Id is not null)
+ {
+ Notes
+
+
+
+
+
+ @foreach(var note in notes)
+ {
+
+
+
+
+
+
+
+
+
+
+ }
+
+ }
+
-
-
- Contact saved successfully.
-
-
- Oops, something went wrong.
-
-
+
+
@code {
[Parameter]
public int? Id { get; set; }
public Contact contact { get; set; } = new Contact();
+ public List notes { get; set; } = new List();
+ 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>($"api/notes/{noteId}");
+ if (result is not null)
+ notes = result;
+ }
+
+ async Task LoadNotes()
+ {
+ var result = await Http.GetFromJsonAsync>($"api/notes/{contact.Id}");
+ if (result is not null)
+ notes = result;
+ }
}
diff --git a/BlazorSyncfusionCrm/Client/Pages/Notes.razor b/BlazorSyncfusionCrm/Client/Pages/Notes.razor
new file mode 100644
index 0000000..f6aac0d
--- /dev/null
+++ b/BlazorSyncfusionCrm/Client/Pages/Notes.razor
@@ -0,0 +1,39 @@
+@page "/notes"
+@inject HttpClient Http
+@inject NavigationManager NavigationManager
+
+Notes
+
+@foreach (var note in NoteList)
+{
+
+
+
+
+
+ @if(note.Contact is not null)
+ {
+
+ }
+
+
+
+}
+
+@code {
+ public List NoteList { get; set; } = new List();
+
+ protected override async Task OnInitializedAsync()
+ {
+ var result = await Http.GetFromJsonAsync>("api/notes");
+ if (result is not null)
+ NoteList = result;
+ }
+
+ void NavigateToContact(int contactId)
+ {
+ NavigationManager.NavigateTo($"contacts/edit/{contactId}");
+ }
+}
diff --git a/BlazorSyncfusionCrm/Client/_Imports.razor b/BlazorSyncfusionCrm/Client/_Imports.razor
index 8be29fe..50ab631 100644
--- a/BlazorSyncfusionCrm/Client/_Imports.razor
+++ b/BlazorSyncfusionCrm/Client/_Imports.razor
@@ -16,4 +16,5 @@
@using Syncfusion.Blazor.Calendars
@using Syncfusion.Blazor.Notifications
@using Syncfusion.Blazor.Popups
+@using Syncfusion.Blazor.Cards
diff --git a/BlazorSyncfusionCrm/Server/Controllers/NotesController.cs b/BlazorSyncfusionCrm/Server/Controllers/NotesController.cs
index 919c2ab..91c7a98 100644
--- a/BlazorSyncfusionCrm/Server/Controllers/NotesController.cs
+++ b/BlazorSyncfusionCrm/Server/Controllers/NotesController.cs
@@ -1,4 +1,5 @@
-using BlazorSyncfusionCrm.Server.Data;
+using BlazorSyncfusionCrm.Client.Pages;
+using BlazorSyncfusionCrm.Server.Data;
using BlazorSyncfusionCrm.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -28,6 +29,44 @@ namespace BlazorSyncfusionCrm.Server.Controllers
}
+ [HttpGet("{contactId}")]
+ public async Task>> GetNotesFromContact(int contactId)
+ {
+ return await _context.Notes
+ .Where(n => n.ContactId == contactId)
+ .OrderByDescending(n => n.DateCreated)
+ .ToListAsync();
+ }
+
+ [HttpPost]
+ public async Task>> CreateNote(Note note)
+ {
+ _context.Notes.Add(note);
+ await _context.SaveChangesAsync();
+ return await _context.Notes
+ .Where(n => n.ContactId == note.ContactId)
+ .OrderByDescending(n => n.DateCreated)
+ .ToListAsync();
+
+ }
+
+ [HttpDelete("{id}")]
+ public async Task>> DeleteNote(int id)
+ {
+ var dbNote = await _context.Notes.FindAsync(id);
+ if ( dbNote is null)
+ {
+ return NotFound("Note not found.");
+ }
+ _context.Notes.Remove(dbNote);
+ await _context.SaveChangesAsync();
+
+ return await _context.Notes
+ .Where(n => n.ContactId == dbNote.ContactId)
+ .OrderByDescending(n => n.DateCreated)
+ .ToListAsync();
+
+ }
}
}