Notes features are ready

This commit is contained in:
2023-04-20 22:00:58 +02:00
parent ede368b963
commit 0b69e0b13a
4 changed files with 146 additions and 9 deletions

View File

@ -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<ActionResult<List<Note>>> GetNotesFromContact(int contactId)
{
return await _context.Notes
.Where(n => n.ContactId == contactId)
.OrderByDescending(n => n.DateCreated)
.ToListAsync();
}
[HttpPost]
public async Task<ActionResult<List<Note>>> 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<ActionResult<List<Note>>> 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();
}
}
}