I am new to Visual Studio. I am trying to initialize the Calendars using the following.
using Dapper;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Data.SqlClient;
using System.Threading.Tasks;
namespace SamsSchedule.Data
{
public class CalendarService : ICalendarService
{
private readonly SamsConfiguration _configuration;
public CalendarService(SamsConfiguration samsConfiguration)
{
_configuration = samsConfiguration;
}
public async Task<List<CalendarData>> GetCalendarAll()
{
using (var conn = new SqlConnection(_configuration.Value))
{
const string sql = @"SELECT * FROM CalendarData";
List<CalendarData> crew = (List<CalendarData>)await conn.QueryAsync<CalendarData>(sql);
return crew.ToList();
}
}
}
}
// Calendars.AddRange has an error
public List<CalendarData> Calendars { get; set; } = new List<CalendarData>
{
Calendars.AddRange(CalendarService.GetCalendarAll())
};