Exemplo n.º 1
0
        public static async Task <List <T> > GetDataSample <T>(IMongoService <T> ms)
        {
            var file = $"{Startup.PATH}/Data/{typeof(T).Name}_SEED.json";

            if (File.Exists(file))
            {
                try {
                    var documents = JsonSerializer.Deserialize <List <T> >(File.ReadAllText(file));
                    // write
                    var data = await ms.GetDocumentsAsync();

                    if (data.ToList().Any() == false)
                    {
                        foreach (T document in documents)  // prevent others
                        {
                            await ms.AddDocumentAsync(document);
                        }
                    }
                    return(documents);
                }
                catch (Exception exception) {
                    Trace.WriteLine($"Exception: {exception.Message}");
                }
            }
            return(new List <T>());
        }
Exemplo n.º 2
0
 public async Task <bool> Post([FromBody] Book value)
 {
     return(await _ms.AddDocumentAsync(value));
 }