public static bool CreateNewEvent(string Title, string NewEventDate, string NewEventTime, string NewEventDuration) { try { HotelEntities ent = new HotelEntities(); AppointmentDiary rec = new AppointmentDiary(); rec.Title = Title; rec.DateTimeScheduled = DateTime.ParseExact(NewEventDate + " " + NewEventTime, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); rec.AppointmentLength = Int32.Parse(NewEventDuration); ent.AppointmentDiary.Add(rec); ent.SaveChanges(); } catch (Exception) { return(false); } return(true); }
public static bool InitialiseDiary() { // init connection to database HotelEntities ent = new HotelEntities(); try { for (int i = 0; i < 30; i++) { AppointmentDiary item = new AppointmentDiary(); // record ID is auto generated item.Title = "Appt: " + i.ToString(); item.SomeImportantKey = i; item.StatusENUM = GetRandomValue(0, 3); // random is exclusive - we have three status enums if (i <= 5) // create a few appointments for todays date { item.DateTimeScheduled = GetRandomAppointmentTime(false, true); } else // rest of appointments on previous and future dates { if (i % 2 == 0) { item.DateTimeScheduled = GetRandomAppointmentTime(true, false); // flip/flop between date ahead of today and behind today } else { item.DateTimeScheduled = GetRandomAppointmentTime(false, false); } } item.AppointmentLength = GetRandomValue(1, 5) * 15; // appoiment length in blocks of fifteen minutes in this demo ent.AppointmentDiary.Add(item); ent.SaveChanges(); } } catch (Exception) { return(false); } return(ent.AppointmentDiary.Count() > 0); }