-
Notifications
You must be signed in to change notification settings - Fork 328
/
SessionsController.cs
69 lines (58 loc) · 1.72 KB
/
SessionsController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Rnwood.Smtp4dev.DbModel;
using Rnwood.Smtp4dev.Hubs;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System.IO;
using MimeKit;
using HtmlAgilityPack;
using Rnwood.Smtp4dev.Data;
using Rnwood.Smtp4dev.Server;
namespace Rnwood.Smtp4dev.Controllers
{
[Route("api/[controller]")]
[ApiController]
[UseEtagFilterAttribute]
public class SessionsController : Controller
{
public SessionsController(Smtp4devDbContext dbContext, Smtp4devServer server)
{
this.dbContext = dbContext;
this.server = server;
}
private Smtp4devDbContext dbContext;
private Smtp4devServer server;
[HttpGet]
public IEnumerable<ApiModel.SessionSummary> GetSummaries()
{
return dbContext.Sessions.Where(s => s.EndDate.HasValue)
.Select(m => new ApiModel.SessionSummary(m));
}
[HttpGet("{id}")]
public ApiModel.Session GetSession(Guid id)
{
Session result = dbContext.Sessions.SingleOrDefault(m => m.Id == id);
return new ApiModel.Session(result);
}
[HttpGet("{id}/log")]
public string GetSessionLog(Guid id)
{
Session result = dbContext.Sessions.SingleOrDefault(m => m.Id == id);
return result.Log;
}
[HttpDelete("{id}")]
public async Task Delete(Guid id)
{
await server.DeleteSession(id);
}
[HttpDelete("*")]
public async Task DeleteAll()
{
await server.DeleteAllSessions();
}
}
}