public static List <NpcShift> GenerateShifts(Event activeEvent, DateTime start, DateTime end, int lengthInMins, int minutesBetweenShifts) { var npcShiftStart = start; var npcShiftEnd = start.AddMinutes(lengthInMins); var npcShifts = new List <NpcShift>(); var isEndOfEvent = end - npcShiftEnd; while (isEndOfEvent.TotalMinutes >= 0) { var npcShift = new NpcShift { EventId = activeEvent.Id, Event = activeEvent, StartDateTime = npcShiftStart, EndDateTime = npcShiftEnd }; npcShifts.Add(npcShift); npcShiftStart = npcShiftStart.AddMinutes(minutesBetweenShifts); npcShiftEnd = npcShiftStart.AddMinutes(lengthInMins); isEndOfEvent = end - npcShiftEnd; } return(npcShifts); }
public IActionResult GetCurrentEventNpcShifts() { var npcShifts = _context.tblNpcShift.Include(n => n.Event).Where(n => n.Event.IsActiveEvent).ToList(); if (!npcShifts.Any()) { var activeEvent = _eventService.GetActiveEvent(); var npcShiftBegins = activeEvent.StartDate.AddDays(1).AddHours(8); var npcShiftsEnds = activeEvent.EndDate.AddHours(2).AddMinutes(30); npcShifts = NpcShiftGenerator.GenerateShifts(activeEvent, npcShiftBegins, npcShiftsEnds, 150, 60); var fridayNightShiftStart = activeEvent.StartDate.AddHours(21); var fridayNightShiftEnd = activeEvent.StartDate.AddHours(23).AddMinutes(30); var fridayNightShift = new NpcShift { Event = activeEvent, EventId = activeEvent.Id, EndDateTime = fridayNightShiftEnd, StartDateTime = fridayNightShiftStart }; npcShifts.Add(fridayNightShift); var saturdayMorningShiftStart = activeEvent.StartDate.AddDays(1).AddHours(7).AddMinutes(30); var saturdayMorningShiftEnd = activeEvent.StartDate.AddDays(1).AddHours(10); var saturdayNightShift = new NpcShift { Event = activeEvent, EventId = activeEvent.Id, EndDateTime = saturdayMorningShiftEnd, StartDateTime = saturdayMorningShiftStart }; npcShifts.Add(saturdayNightShift); _context.tblNpcShift.AddRange(npcShifts); _context.SaveChanges(); return(Ok(npcShifts)); } List <NpcShiftWithCountAndPlayers> npcShiftsWithCountsAndPlayers; try { var npcShiftsWithCounts = _context.Sp_GetNpcShiftsWithPlayerCount.FromSql("GetNpcShiftsWithPlayerCount").ToList(); npcShiftsWithCountsAndPlayers = new List <NpcShiftWithCountAndPlayers>(); foreach (var npcShift in npcShiftsWithCounts) { var players = _playerService.GetPlayersFromNpcShift(npcShift.Id); var npcShiftWithCountAndPlayers = new NpcShiftWithCountAndPlayers { EventId = npcShift.EventId, Id = npcShift.Id, StartDateTime = npcShift.StartDateTime, EndDateTime = npcShift.EndDateTime, NpcCount = npcShift.NpcCount, Players = players }; npcShiftsWithCountsAndPlayers.Add(npcShiftWithCountAndPlayers); } } catch (Exception e) { Console.WriteLine(e); throw; } return(Ok(npcShiftsWithCountsAndPlayers)); }