public IHttpActionResult CreateNotification([FromBody]NotificationDTO _notification, TeamListDTO _teamList, LeagueDTO _league) { String teamsId = ""; List<TeamDTO> teams = _teamList.items; foreach (TeamDTO t in teams) { teamsId = teamsId + "<" + t.Id + ">"; } notification n = new notification { Content = _notification.Content, Date = DateTime.Parse(_notification.Date), Enabled = true, Title = _notification.Title, TeamsId = teamsId, LeagueId = (int)_league.Id }; using (var context = new escorcenterdbEntities()) { context.notifications.Add(n); context.SaveChanges(); } return Ok(); }
private Boolean IncludeNotification(notification n, HashSet<int> teamIds, HashSet<int> leagueIds) { bool hasTeam = false; foreach (int t in teamIds) { if (n.TeamsId.Contains("<" + t.ToString() + ">")) { hasTeam = true; } } return n.Enabled == true && (hasTeam || leagueIds.Contains(n.LeagueId)); }