public object GetLineRoomByRoomID(int roomID) { var data = db.LineRooms.Where(x => x.RoomID == roomID).Select(x => new { id = x.LineRoomID, title = x.LineRoomName, start = x.TimeStart, end = x.TimeEnd }).ToList(); List <FullCalendarModel> dataFullCalendar = new List <FullCalendarModel>(); foreach (var item in data) { FullCalendarModel lineRoomModel = new FullCalendarModel { id = item.id, title = item.title, start = item.start.Value.ToString("yyyy-MM-dd HH:mm"), end = item.end.Value.ToString("yyyy-MM-dd HH:mm") }; dataFullCalendar.Add(lineRoomModel); } return(dataFullCalendar); }
public ActionResult AllGames() { using (var context = new FcDeHoekContext()) { var currentSeason = SeasonQueries.GetCurrentSeason(context); var calendars = GameQueries.GetAllGamesByIdSeason(context, currentSeason.IdSeason).OrderBy(g => g.MatchDate).ToList(); var model = new FullCalendarModel { SeasonDescription = $"{currentSeason.SeasonStartYear} - {currentSeason.SeasonEndYear}", GamesPerDate = GetGamesPerDate(context, calendars) }; return(View(model)); } }
public ActionResult <List <FullCalendarModel> > GetFullCalendar(DateTime from, DateTime to) { var addDateFilter = false; if (!from.Equals(DateTime.MinValue) && !from.ToString("u").Equals("0000-00-00 00:00:00Z") || !to.Equals(DateTime.MinValue) && !to.ToString("u").Equals("0000-00-00 00:00:00Z") ) { addDateFilter = true; } _logger.LogInformation($" [*********************** >][Request - from] : {from.ToString ("u")}"); _logger.LogInformation($" [*********************** >][Request - to] : {to.ToString ("u")}"); var result = new List <FullCalendarModel> (); try { using (MySqlConnection connection = new MySqlConnection(_appSettings.GetDataBaseConnectionString())) { var query = $"SELECT * FROM CALENDAR_EVENT WHERE 1=1 "; var command = new MySqlCommand(); if (addDateFilter) { query += $"AND start BETWEEN @to AND @from "; command.Parameters.Add("@from", MySqlDbType.DateTime); command.Parameters["@from"].Value = from; command.Parameters.Add("@to", MySqlDbType.DateTime); command.Parameters["@to"].Value = to; } command.CommandText = query; _logger.LogInformation($" Query : {query}"); command.Connection = connection; connection.Open(); var sqlReader = command.ExecuteReader(); if (sqlReader.HasRows) { while (sqlReader.Read()) { var item = new FullCalendarModel(); item.Id = sqlReader.GetInt32(sqlReader.GetOrdinal("id")); item.Title = sqlReader.GetString(sqlReader.GetOrdinal("title")); item.Start = sqlReader.GetDateTime(sqlReader.GetOrdinal("start")).ToString("u"); item.End = sqlReader.GetDateTime(sqlReader.GetOrdinal("end")).ToString("u"); item.AllDay = false; result.Add(item); } } else { _logger.LogInformation($" No results ."); return(StatusCode(204)); } } } catch (System.Exception ex) { _logger.LogError($"{ex.Message}"); return(StatusCode(500)); } _logger.LogInformation($" [*********************** >][Result - count] : {result.Count}"); return(result); }