public async Task <object> GetReservations(string start) { var calendarDate = Convert.ToDateTime(start); var m = new Models.TableReservations.TableReservationsModel(); m.TRs = await _db.Reservations .Include(r => r.TableReservations) .Where(r => r.StartDateTime >= calendarDate && r.StartDateTime < calendarDate.AddDays(1)) .Where(r => r.ReservationStatusId != 3) // 3 is cancelled .Select(r => new Models.TableReservations.TR { Id = r.Id, //ResourceId = r.TableReservations.Any() ? r.TableReservations.First().TableSittingId : 0, ResourceId = r.TableReservations.FirstOrDefault().TableSitting.TableId, Start = r.StartDateTime, End = r.EndDateTime, Title = $"Res-{r.Id}", Guests = r.Guests, Notes = r.Notes_Requirements, }) .ToListAsync(); foreach (var r in m.TRs) { if (r.ResourceId == null) { r.ResourceId = 0; } } return(m.TRs); }
public async Task <object> GetSittingsEvent(string start) { var m = new Models.TableReservations.TableReservationsModel(); var calendarDate = Convert.ToDateTime(start); string[,] colours = new string[4, 2] { { "Breakfast", "#6495ed" }, { "Lunch", "#ed6495" }, { "Dinner", "#64edbc" }, { "Event", "#edbc64" } }; m.SittingEvents = await _db.TableSittings .Include(s => s.Table) .Include(s => s.Sitting) .Where(ts => ts.Sitting.StartDateTime > calendarDate && ts.Sitting.StartDateTime < calendarDate.AddDays(1)) .Select(s => new Models.TableReservations.SittingEvent { Title = s.Sitting.SittingType.Description, Start = s.Sitting.StartDateTime, End = s.Sitting.EndDateTime, ResourceId = s.TableId, Rendering = "background", Color = "#6495ed", GroupId = s.Id }) .ToListAsync(); foreach (var s in m.SittingEvents) { for (int i = 0; i < colours.GetLength(0); i++) { if (s.Title == colours[i, 0]) { s.Color = colours[i, 1]; } } } return(m.SittingEvents); }