public IActionResult Json(string secretKey) { if (String.CompareOrdinal(_bot.SecretKey, secretKey) != 0) { return(StatusCode(403)); } return(Json(MongoDBHelper.All().Result)); }
public IActionResult Csv(string secretKey) { if (String.CompareOrdinal(_bot.SecretKey, secretKey) != 0) { return(StatusCode(403)); } var sb = new StringBuilder(); sb.AppendLine("EMail;Name;Profession;University;Phone;Telegram;"); var students = MongoDBHelper.All().Result; if (students.Count() > 0) { foreach (var stud in students) { sb.AppendLine($"{stud.EMail};{stud.Name};{stud.Profession};{stud.University};{stud.Phone};{stud.TelegramName};"); } } return(File(System.Text.Encoding.UTF8.GetBytes(sb.ToString()), "text/csv", "data.csv")); }
private static void TestDB() { var students = MongoDBHelper.All().Result; if (students.Count() == 0) { var student = new Student { EMail = "*****@*****.**", Name = "Test Student", Profession = "Haskell", University = "sgu" }; MongoDBHelper.AddStudent(student); students = MongoDBHelper.All().Result; if (students.Count() == 0) { throw new Exception("Fail to start DB"); } } }