Skip to content

Instantly share code, notes, and snippets.

@mikebrind
Created July 12, 2018 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebrind/7fdde27009654d249af06628c3c5b27e to your computer and use it in GitHub Desktop.
Save mikebrind/7fdde27009654d249af06628c3c5b27e to your computer and use it in GitHub Desktop.
using KnockoutTS.Models;
using Microsoft.AspNetCore.Hosting;
using Newtonsoft.Json;
using System.IO;
using System.Linq;
namespace KnockoutTS.Services
{
public interface IMailService
{
Folder GetMailByFolder(string folder);
Mail GetMail(int id);
}
public class MailService : IMailService
{
IHostingEnvironment _env;
WebMail webMail;
public MailService(IHostingEnvironment env)
{
_env = env;
webMail = LoadMail();
}
public Folder GetMailByFolder(string folder)
{
return webMail.Folders.First(f => f.Id == folder);
}
public Mail GetMail(int id)
{
var mailItems = webMail.Folders.SelectMany(f => f.Mails);
return mailItems.Single(m => m.Id == id);
}
private WebMail LoadMail()
{
var data = File.ReadAllText(Path.Combine(_env.ContentRootPath, "Data", "webmail.json"));
return JsonConvert.DeserializeObject<WebMail>(data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment