public IHttpActionResult GetSeasons([FromUri] string leagueName, [FromUri] string seasonIds = null, [FromUri] string fields = null, [FromUri] bool excludeFields = false) { try { logger.Info($"Get data for season ids: {seasonIds} - league: {leagueName}"); CheckLeagueRole(User, leagueName); // check for empty parameters if (string.IsNullOrEmpty(leagueName)) { return(BadRequestEmptyParameter(nameof(leagueName))); } // try to parse seasonIds string List <long> seasonIdValues = null; if (seasonIds != null) { seasonIdValues = new List <long>(); foreach (var idString in seasonIds.Split(',')) { if (long.TryParse(idString, out long id) == false) { return(BadRequestInvalidType(nameof(seasonIds), idString, typeof(long))); } seasonIdValues.Add(id); } } var databaseName = GetDatabaseNameFromLeagueName(leagueName); // Get session data from data access layer SeasonConvenieneDTO[] data; using (var dbContext = CreateDbContext(databaseName)) { ISeasonDataProvider sessionsDataProvider = new SeasonDataProvider(dbContext); data = sessionsDataProvider.GetSeasons(seasonIdValues?.ToArray()); } // return complete DTO or select fields logger.Info($"Send data - {nameof(SeasonConvenieneDTO)}[{data.Count()}] ids: {string.Join(",", data.Select(x => x?.SeasonId))}"); if (string.IsNullOrEmpty(fields)) { return(Ok(data)); } else { data.ForEach(x => x.SetSerializableProperties(fields.Split(','), excludeFields)); var response = data.Select(x => SelectFieldsHelper.GetSelectedFieldObject(x)); return(Json(response)); } } catch (Exception e) { logger.Error("Error!", e); throw e; } }
public IHttpActionResult GetModel(string requestId, string requestType, string leagueName, string fields, bool excludeFields = false) { try { logger.Info($"Get Model Fields request || type: {requestType} - league: {leagueName} - id: [{requestId}] - fields: {fields}"); CheckLeagueRole(User, leagueName); if (requestId == null || requestType == null || leagueName == null) { return(BadRequest("Parameter requestType or leagueName can not be null!")); } string[] fieldValues = new string[0]; try { fieldValues = fields?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) ?? fieldValues; } catch (Exception e) { throw new ArgumentException("Invalid field names", e); } long[] requestIdValue = GetIdFromString(requestId); Type requestTypeType = GetRequestType(requestType); var databaseName = GetDatabaseNameFromLeagueName(leagueName); MappableDTO data; using (var dbContext = new LeagueDbContext(databaseName)) using (IModelDataProvider modelDataProvider = new ModelDataProvider(dbContext)) { data = modelDataProvider.Get(requestTypeType, requestIdValue); } //GC.Collect(); data.SetSerializableProperties(fieldValues, excludeFields); var response = SelectFieldsHelper.GetSelectedFieldObject(data); logger.Info($"Get Model Fields request || send data: {data} - fields: {string.Join(",", fieldValues)}"); return(Json(response)); } catch (Exception e) { logger.Error("Error in GetModel Fields", e); throw; } }
public IHttpActionResult GetSchedule([FromUri] string leagueName, [FromUri] long scheduleId, [FromUri] string fields = null, [FromUri] bool excludeFields = false) { try { logger.Info($"Get Sessions for schedule id: {scheduleId} - league: {leagueName}"); CheckLeagueRole(User, leagueName); // check for empty parameters if (string.IsNullOrEmpty(leagueName)) { return(BadRequestEmptyParameter(nameof(leagueName))); } if (scheduleId == 0) { return(BadRequestEmptyParameter(nameof(scheduleId))); } var databaseName = GetDatabaseNameFromLeagueName(leagueName); // Get session data from data access layer ScheduleSessionsDTO data; using (var dbContext = CreateDbContext(databaseName)) { var sessionsDataProvider = new SessionsDataProvider(dbContext); data = sessionsDataProvider.GetSessionsFromSchedule(scheduleId); } // return complete DTO or select fields logger.Info($"Send data - {nameof(ScheduleSessionsDTO)} id: {data.ScheduleId}"); if (string.IsNullOrEmpty(fields)) { return(Ok(data)); } else { data.SetSerializableProperties(fields.Split(','), excludeFields); var response = SelectFieldsHelper.GetSelectedFieldObject(data); return(Json(response)); } } catch (Exception e) { logger.Error("Error in get Sessions", e); throw e; } }
public IHttpActionResult Get([FromUri] string leagueName, [FromUri] long seasonId = 0, [FromUri] long?sessionId = null, [FromUri] bool includeRaw = false, [FromUri] string fields = null, [FromUri] bool excludeFields = false) { try { logger.Info($"Get Results for session id: {sessionId} - league: {leagueName}"); CheckLeagueRole(User, leagueName); // check for empty parameters if (string.IsNullOrEmpty(leagueName)) { return(BadRequestEmptyParameter(nameof(leagueName))); } var databaseName = GetDatabaseNameFromLeagueName(leagueName); SeasonStandingsDTO data; using (var dbContext = CreateDbContext(databaseName)) { IStandingsDataProvider standingsDataProvider = new StandingsDataProvider(dbContext); data = standingsDataProvider.GetStandingsFromSeason(seasonId, sessionId); } // return complete DTO or select fields logger.Info($"Send data - SeasonStandingsDTO id: {data.SeasonId}"); if (string.IsNullOrEmpty(fields)) { return(Ok(data)); } else { data.SetSerializableProperties(fields.Split(','), excludeFields); var response = SelectFieldsHelper.GetSelectedFieldObject(data); return(Json(response)); } } catch (Exception e) { logger.Error("Error in get Season Standings", e); throw e; } }
public IHttpActionResult GetModelsSelectFields([FromUri] string[] requestIds, string requestType, string leagueName, string fields, bool excludeFields = false) { try { logger.Info($"Get Models Fields request || type: {requestType} - league: {leagueName} - ids: {string.Join("/", requestIds.Select(x => $"[{string.Join(",", x)}]"))} - fields: {fields}"); CheckLeagueRole(User, leagueName); if (requestType == null || leagueName == null) { //return BadRequest("Parameter requestType or leagueName can not be null!"); } string[] fieldValues = new string[0]; try { fieldValues = fields?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) ?? fieldValues; } catch (Exception e) { throw new ArgumentException("Invalid field names", e); } long[][] requestIdValues; if (requestIds != null && requestIds.Count() > 0) { requestIdValues = requestIds.Select(x => GetIdFromString(x)).ToArray(); } else { requestIdValues = null; } Type requestTypeType = GetRequestType(requestType); if (requestTypeType == null) { throw new InvalidOperationException($"Requested type {requestType} not found"); } var databaseName = GetDatabaseNameFromLeagueName(leagueName); MappableDTO[] data; using (var dbContext = new LeagueDbContext(databaseName)) using (IModelDataProvider modelDataProvider = new ModelDataProvider(dbContext)) { data = modelDataProvider.GetArray(requestTypeType, requestIdValues); } //GC.Collect(); data.ForEach(x => x.SetSerializableProperties(fieldValues, excludeFields)); var response = data.Select(x => SelectFieldsHelper.GetSelectedFieldObject(x)); logger.Info($"Get Models Fields request || send data: {string.Join("/", (object[])data)} - fields: {string.Join(",", fieldValues)}"); return(Json(response)); } catch (Exception e) { logger.Error("Error in GetModels Fields", e); throw; } }