public bool CreateNewEvent(string Title, string NewEventDate, string NewEventTime, string NewEventDuration) { Event events = new Event() ; try { events.Id = 1; events.Title = Title; events.EventDuration = Int32.Parse(NewEventDuration); events.EventDate = NewEventDate; events.EventTime = NewEventTime; events.EventStart = DateTime.ParseExact(NewEventDate + " " + NewEventTime, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); events.EventEnd = DateTime.ParseExact(NewEventDate + " " + NewEventTime, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); db.Events.Add(events); db.SaveChanges(); } catch (Exception) { return false; } return true; }
public List<SaveData> LoadAppointmentSummaryInDateRange(double start, double end) { var fromDate = ConvertFromUnixTimestamp(start); var toDate = ConvertFromUnixTimestamp(end); Event ent = new Event(); var rslt = db.Events.Where(s => s.EventStart >= fromDate && s.EventStart <= toDate) .GroupBy(s => System.Data.Objects.EntityFunctions.TruncateTime(s.EventStart)) .Select(x => new { DateTimeScheduled = x.Key, Count = x.Count() }); List<SaveData> result = new List<SaveData>(); int i = 0; foreach (var item in rslt) { SaveData rec = new SaveData(); rec.ID = i; //we dont link this back to anything as its a group summary but the fullcalendar needs unique IDs for each event item (unless its a repeating event) rec.SomeImportantKeyID = -1; string StringDate = string.Format("{0:yyyy-MM-dd}", item.DateTimeScheduled); rec.StartDateString = StringDate + "T00:00:00"; //ISO 8601 format rec.EndDateString = StringDate + "T23:59:59"; rec.Title = "Booked: " + item.Count.ToString(); result.Add(rec); i++; } return result; }