public static bool CreateNewEvent(string Title, string NewEventDate, string NewEventTime, string NewEventTimeEnd) { try { var start = DateTime.ParseExact(NewEventDate + " " + NewEventTime, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); var end = DateTime.ParseExact(NewEventDate + " " + NewEventTimeEnd, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); var span = end.Subtract(start); var ent = new MyDbContext(); var rec = new AppointmentDiary { Title = Title, DateTimeScheduled = start, AppointmentLength = (int)span.TotalMinutes }; ent.AppointmentDiaries.Add(rec); ent.SaveChanges(); } catch (Exception) { return(false); } return(true); }
public static bool CreateHolidayNewEvent(string NewEventDate) { try { var ent = new MyDbContext(); var rec = new AppointmentDiary { Title = "Geen les", DateTimeScheduled = DateTime.ParseExact(NewEventDate + " " + "00:00", "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture), AppointmentLength = 1440, StatusEnum = 3 }; ent.AppointmentDiaries.Add(rec); ent.SaveChanges(); } catch (Exception) { return(false); } return(true); }