예제 #1
0
        public IActionResult Json(string secretKey)
        {
            if (String.CompareOrdinal(_bot.SecretKey, secretKey) != 0)
            {
                return(StatusCode(403));
            }

            return(Json(MongoDBHelper.All().Result));
        }
예제 #2
0
        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"));
        }
예제 #3
0
        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");
                }
            }
        }