I tried this way to add meeting on calendar but was unable to see on screen.
private void CreateCalendarEvents(ScheduleAppointmentCollection Meetings)
{
Meetings = new ScheduleAppointmentCollection();
ScheduleAppointment meeting = new ScheduleAppointment();
Calendar calendar = Calendar.Instance;
Calendar startTimeCalendar = Calendar.Instance;
foreach (var calendarEvent in remoteData)
{
var DefaultHour = 9;
if (!string.IsNullOrEmpty(calendarEvent.start) && !string.IsNullOrEmpty(calendarEvent.end))
{
var startDate = GetDate(calendarEvent.start);
var startYear = startDate.Year;
var startMonth = startDate.Month;
var startDay = startDate.Day;
var startTime = GetDate(calendarEvent.start);
var startHour = startTime.Hour == 0 ? DefaultHour : startTime.Hour;
var startMinute = startTime.Minute;
var endDate = GetDate(calendarEvent.end);
var endYear = endDate.Year;
var endMonth = endDate.Month;
var endDay = endDate.Day;
var endTime = GetDate(calendarEvent.end);
var endHour = endTime.Hour==0 ? DefaultHour : endTime.Hour;
var endMinute = endTime.Minute;
// startTimeCalendar.Set(calendar.Get(CalendarField.Year), calendar.Get(CalendarField.Month), calendar.Get(CalendarField.Date), hour, 0);
startTimeCalendar.Set(startYear, startMonth, calendar.Get(CalendarField.Date), startHour, startMinute, 0);
meeting.StartTime = startTimeCalendar;
Calendar endTimeCalendar = Calendar.Instance;
endTimeCalendar.Set(endYear, endMonth, calendar.Get(CalendarField.Date), endHour, endMinute, 0);
meeting.EndTime = endTimeCalendar;
meeting.Color = GetColor(calendarEvent.color);
meeting.Subject = calendarEvent.title ?? "";
meeting.IsAllDay = calendarEvent.allDay;
meeting.Notes = calendarEvent.title ?? "";
Meetings.Add(meeting);
}
}
}
private int GetColor(string color)
{
var defaultColor = "#086A87";
try
{
if(!string.IsNullOrEmpty(color))
{
return Color.ParseColor(color);
}
return Color.ParseColor(defaultColor);
}catch(Exception ex)
{
Log.Debug(TAG, ex.StackTrace);
return Color.ParseColor(defaultColor);
}
}
private DateTimeOffset GetDate(string date)
{
try
{
if(!string.IsNullOrEmpty(date))
{
return DateTime.Parse(date);
}else
{
return DateTime.UtcNow.AddHours(5).AddMinutes(45);
}
}
catch(Exception e)
{
var dateTime = DateTimeOffset.Parse(date, System.Globalization.CultureInfo.InvariantCulture);
return dateTime;
}
}