コード例 #1
0
        public async Task <string> LoadSampleDataAsync()
        {
            var text = string.Empty;

            if (!_db.Restaurant.Any())
            {
                string file        = System.IO.File.ReadAllText("generated_restaurants.json");
                var    restaurants = JsonSerializer.Deserialize <List <Restaurant> >(file);
                _db.AddRange(restaurants);
                await _db.SaveChangesAsync();

                text += "Sample Data Restaurants Add\n";
            }
            else
            {
                text += "Contains Data Restaurant\n";
            }

            if (!_db.User.Any())
            {
                string file  = System.IO.File.ReadAllText("generated_users.json");
                var    users = JsonSerializer.Deserialize <List <User> >(file);
                _db.AddRange(users);
                await _db.SaveChangesAsync();

                text += "Sample Data User Add";
            }
            else
            {
                text += "Contains Data User";
            }

            return(text);
        }