Notes features are ready
This commit is contained in:
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user