Files
upo-senior-assistant/SeniorAssistant/Controllers/Services/CrudController.cs
Giacomo Bertolazzi 20015159 1246116804 Besciamello (#1)
* Fixed login & auth
* Added dynamic breadcrumb
* Added DOC
* Added Patient
* Added Notifications
* Added Messages
* Refactoring api
* Re-writed menu
* Removed unused things
* Created README
2019-01-15 21:35:00 +01:00

34 lines
995 B
C#

using LinqToDB;
using Microsoft.AspNetCore.Mvc;
using SeniorAssistant.Models;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SeniorAssistant.Controllers.Services
{
public abstract class CrudController<TEntity> : BaseController
where TEntity : class, IHasUsername
{
[HttpGet("{username}")]
public async Task<IActionResult> Read(string username)
{
return LoggedAccessDataOf(username, () =>
{
return Json(Db.GetTable<TEntity>().Where((u) => u.Username.Equals(username)).ToArray());
});
}
[HttpPut("{username}")]
public async Task<IActionResult> Update(string username, [FromBody] TEntity entity)
{
return LoggedAccessDataOf(username, () =>
{
entity.Username = username;
Db.Update(entity);
return Json(OkJson);
}, false);
}
}
}