yavsc/src/Org/Controllers/Accounting/DevicesController.cs

75 lines
2.3 KiB
C#
Raw Normal View History

2023-03-19 17:57:55 +00:00
using System.Security.Claims;
2018-02-03 20:17:29 +01:00
2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Mvc;
2018-02-03 20:17:29 +01:00
namespace Yavsc.Controllers
{
2023-03-19 17:57:55 +00:00
using Microsoft.EntityFrameworkCore;
2018-02-03 20:17:29 +01:00
using Models;
using Models.Identity;
2019-05-08 01:35:10 +01:00
public class DevicesController : Controller
2018-02-03 20:17:29 +01:00
{
2020-09-12 01:11:30 +01:00
private readonly ApplicationDbContext _context;
2018-02-03 20:17:29 +01:00
2019-05-08 01:35:10 +01:00
public DevicesController(ApplicationDbContext context)
2018-02-03 20:17:29 +01:00
{
_context = context;
}
// GET: GCMDevices
public async Task<IActionResult> Index()
{
2023-03-19 17:57:55 +00:00
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
2018-02-03 20:17:29 +01:00
2019-05-08 01:35:10 +01:00
var applicationDbContext = _context.DeviceDeclaration.Include(g => g.DeviceOwner).Where(d=>d.DeviceOwnerId == uid);
2018-02-03 20:17:29 +01:00
return View(await applicationDbContext.ToListAsync());
}
// GET: GCMDevices/Details/5
public async Task<IActionResult> Details(string id)
{
if (id == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-02-03 20:17:29 +01:00
}
2019-05-08 01:35:10 +01:00
DeviceDeclaration googleCloudMobileDeclaration = await _context.DeviceDeclaration.SingleAsync(m => m.DeviceId == id);
2018-02-03 20:17:29 +01:00
if (googleCloudMobileDeclaration == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-02-03 20:17:29 +01:00
}
return View(googleCloudMobileDeclaration);
}
// GET: GCMDevices/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string id)
{
if (id == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-02-03 20:17:29 +01:00
}
2019-05-08 01:35:10 +01:00
DeviceDeclaration googleCloudMobileDeclaration = await _context.DeviceDeclaration.SingleAsync(m => m.DeviceId == id);
2018-02-03 20:17:29 +01:00
if (googleCloudMobileDeclaration == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-02-03 20:17:29 +01:00
}
return View(googleCloudMobileDeclaration);
}
// POST: GCMDevices/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
2019-05-08 01:35:10 +01:00
DeviceDeclaration googleCloudMobileDeclaration = await _context.DeviceDeclaration.SingleAsync(m => m.DeviceId == id);
_context.DeviceDeclaration.Remove(googleCloudMobileDeclaration);
2018-02-03 20:17:29 +01:00
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}