WeekDTO GetPastMatchesByWeekId(long weekId, DateTime date)
        {
            match[]         _matches = null;
            List <MatchDTO> matches  = new List <MatchDTO>();
            week            _week    = null;

            using (var context = new escorcenterdbEntities())
            {
                _week    = (from w in context.weeks where w.enabled == true && w.id == weekId select w).FirstOrDefault <week>();
                _matches = (from m in context.matches where m.enabled == true && m.week == _week.id && m.date < date select m).OrderByDescending(m => m.date).ToArray <match>();
            }
            matches = ParseMatches(_matches);
            if (matches == null || _week == null)
            {
                return(null);
            }

            WeekDTO week = new WeekDTO()
            {
                DateFrom    = _week.dateFrom.ToString(),
                DateTo      = _week.dateTo.ToString(),
                Description = _week.description,
                Id          = _week.id,
                Season      = _week.season,
                Title       = _week.title
            };

            week.matches.AddRange(matches);
            return(week);
        }
        List <MatchDTO> ParseMatches(match[] _matches)
        {
            List <MatchDTO> matches = new List <MatchDTO>();

            using (var context = new escorcenterdbEntities())
            {
                foreach (match _match in _matches)
                {
                    team     team1 = (from t in context.teams where t.Id == _match.team1 select t).FirstOrDefault <team>();
                    team     team2 = (from t in context.teams where t.Id == _match.team2 select t).FirstOrDefault <team>();
                    field    field = (from f in context.fields where f.Id == _match.field select f).FirstOrDefault <field>();
                    MatchDTO match = new MatchDTO
                    {
                        Team1               = AutoMapper.Mapper.Map <team, TeamDTO>(team1),
                        ScoreTeam1          = _match.scoreTeam1,
                        Team2               = AutoMapper.Mapper.Map <team, TeamDTO>(team2),
                        ScoreTeam2          = _match.scoreTeam2,
                        Date                = _match.date.ToString(),
                        Details             = _match.details,
                        Field               = AutoMapper.Mapper.Map <field, FieldDTO>(field),
                        Finished            = _match.finished,
                        Forfeit             = _match.forfeit,
                        Id                  = _match.Id,
                        ScoreExtraTimeTeam1 = 0,
                        ScoreExtraTimeTeam2 = 0
                    };
                    matches.Add(match);
                }
            }
            return(matches);
        }
        public int getLeagueIdByTeamId(long id)
        {
            int leagueId = 0;

            using (var context = new escorcenterdbEntities())
            {
                leagueId = (from t in context.teams where t.Id == id select t.League).FirstOrDefault <int>();
            }
            return(leagueId);
        }
        public String getLeagueNameById(long id)
        {
            league l;

            using (var context = new escorcenterdbEntities())
            {
                l = (from t in context.leagues where t.Id == id select t).FirstOrDefault();
            }
            return(l.Name);
        }
Ejemplo n.º 5
0
        public static int getWeekId(long id)
        {
            int weekId = 0;

            using (var context = new escorcenterdbEntities())
            {
                weekId = (from w in context.weeks where w.id == id select w.id).FirstOrDefault <int>();
            }
            return(weekId);
        }
Ejemplo n.º 6
0
        public IHttpActionResult GetWeekId(long id)
        {
            int  weekId = getWeekId(id);
            week _week;

            using (var context = new escorcenterdbEntities())
            {
                _week = (from w in context.weeks where w.id == weekId select w).FirstOrDefault <week>();
            }
            return(Ok(_week));
        }
        public IHttpActionResult GetLeagueByTeamId(long id)
        {
            int    leagueId = getLeagueIdByTeamId(id);
            league league;

            using (var context = new escorcenterdbEntities())
            {
                league = (from l in context.leagues where l.Id == leagueId select l).FirstOrDefault <league>();
            }
            return(Ok(league));
        }
        public IHttpActionResult DeleteField(long id)
        {
            field f;

            using (var context = new escorcenterdbEntities())
            {
                f = (from r in context.fields where r.Id == id select r).FirstOrDefault();
                context.SaveChanges();
            }
            return(Ok(f));
        }
Ejemplo n.º 9
0
        public IHttpActionResult DeleteWeek(long id)
        {
            week w;

            using (var context = new escorcenterdbEntities())
            {
                w = (from r in context.weeks where r.id == id select r).FirstOrDefault();
                context.SaveChanges();
            }
            return(Ok(w));
        }
Ejemplo n.º 10
0
        public IHttpActionResult DeleteMatch(long id)
        {
            match _match;

            using (var context = new escorcenterdbEntities())
            {
                _match = (from m in context.matches where m.Id == id select m).FirstOrDefault();
                context.matches.Remove(_match);
                context.SaveChanges();
            }
            return(Ok(_match));
        }
        public IHttpActionResult DeleteNotification(long id)
        {
            notification _notification;

            using (var context = new escorcenterdbEntities())
            {
                _notification = (from n in context.notifications where n.Id == id select n).FirstOrDefault();
                context.notifications.Remove(_notification);
                context.SaveChanges();
            }
            return(Ok(_notification));
        }
        public IHttpActionResult DeleteTeams(long id)
        {
            team _team;

            using (var context = new escorcenterdbEntities())
            {
                _team = (from t in context.teams where t.Id == id select t).FirstOrDefault();
                context.teams.Remove(_team);
                context.SaveChanges();
            }
            return(Ok(_team));
        }
        public IHttpActionResult DeleteLeague(long id)
        {
            league l;

            using (var context = new escorcenterdbEntities())
            {
                l = (from r in context.leagues where r.Id == id select r).FirstOrDefault();
                context.leagues.Remove(l);
                context.SaveChanges();
            }
            return(Ok(l));
        }
        public IHttpActionResult UpdateField([FromBody] FieldDTO _field)
        {
            field fieldMap = AutoMapper.Mapper.Map <FieldDTO, field>(_field);
            field f;

            using (var context = new escorcenterdbEntities())
            {
                f = (from r in context.fields where r.Id == fieldMap.Id select r).FirstOrDefault();
                f = fieldMap;
                context.SaveChanges();
            }
            return(Ok(f));
        }
        public IHttpActionResult UpdateNotification([FromBody] NotificationDTO notificationDTO)
        {
            notification notificationMap = AutoMapper.Mapper.Map <NotificationDTO, notification>(notificationDTO);
            notification _notification;

            using (var context = new escorcenterdbEntities())
            {
                _notification = (from n in context.notifications where n.Id == notificationMap.Id select n).FirstOrDefault();
                _notification = notificationMap;
                context.SaveChanges();
            }
            return(Ok(_notification));
        }
Ejemplo n.º 16
0
        public IHttpActionResult UpdateWeeks([FromBody] WeekDTO _week)
        {
            week weekMap = AutoMapper.Mapper.Map <WeekDTO, week>(_week);
            week w;

            using (var context = new escorcenterdbEntities())
            {
                w = (from r in context.weeks where r.id == weekMap.id select r).FirstOrDefault();
                w = weekMap;
                context.SaveChanges();
            }
            return(Ok(w));
        }
        public IHttpActionResult CreateField([FromBody] FieldDTO field)
        {
            field f = new field {
                address = field.Address, description = field.Description, enabled = true, latitude = (float)field.latitude, longitude = (float)field.longitude, name = field.Name, sport = (int)field.sport
            };

            using (var context = new escorcenterdbEntities())
            {
                context.fields.Add(f);
                context.SaveChanges();
            }
            return(Ok(f));
        }
Ejemplo n.º 18
0
        public IHttpActionResult CreateWeek(WeekDTO _week)
        {
            week w = new week {
                dateFrom = DateTime.Now, dateTo = new DateTime(2016, 02, 29), enabled = true, description = _week.Description, season = (int)_week.Season, title = _week.Title
            };

            using (var context = new escorcenterdbEntities())
            {
                context.weeks.Add(w);
                context.SaveChanges();
            }
            return(Ok(w));
        }
        public IHttpActionResult insertarequipos()
        {
            team t = null;

            using (var context = new escorcenterdbEntities())
            {
                t = new team {
                    Name = "", League = 2, Enabled = true, Description = "Omar es Joto", Logo = "http://pintarimagenes.org/wp-content/uploads/2014/04/toro5.jpg"
                };
                context.teams.Add(t);
            }
            return(Ok(t));
        }
        public IHttpActionResult UpdateTeams([FromBody] TeamDTO teamDTO)
        {
            team teamMap = AutoMapper.Mapper.Map <TeamDTO, team>(teamDTO);
            team _team;

            using (var context = new escorcenterdbEntities())
            {
                _team = (from t in context.teams where t.Id == teamMap.Id select t).FirstOrDefault();
                _team = teamMap;
                context.SaveChanges();
            }
            return(Ok(_team));
        }
Ejemplo n.º 21
0
        public IHttpActionResult UpdateMatch([FromBody] MatchDTO matchDTO)
        {
            match matchMap = AutoMapper.Mapper.Map <MatchDTO, match>(matchDTO);
            match _match;

            using (var context = new escorcenterdbEntities())
            {
                _match = (from m in context.matches where m.Id == matchMap.Id select m).FirstOrDefault();
                _match = matchMap;
                context.SaveChanges();
            }
            return(Ok(_match));
        }
        public IHttpActionResult UpdateLeague([FromBody] LeagueDTO leagueDto)
        {
            league leagueMap = AutoMapper.Mapper.Map <LeagueDTO, league>(leagueDto);
            league l;

            using (var context = new escorcenterdbEntities())
            {
                l = (from r in context.leagues where r.Id == leagueMap.Id select r).FirstOrDefault();
                l = leagueMap;
                context.SaveChanges();
            }
            return(Ok(l));
        }
        public ActionResult League(int regionId)
        {
            region region = null;

            using (var context = new escorcenterdbEntities())
            {
                region = context.regions.Find(regionId);
            }
            if (region != null)
            {
                ViewBag.regionName = region.Name;
            }
            return(View());
        }
Ejemplo n.º 24
0
        public IHttpActionResult CreateMatch(MatchDTO _match)
        {
            int   weekId = WeeksApiController.getWeekId(_match.Id);
            match m      = new match {
                date = DateTime.Parse(_match.Date), details = _match.Details, enabled = true, field = (int)_match.Field.Id, scoreTeam1 = (sbyte)_match.ScoreTeam1, scoreTeam2 = (sbyte)_match.ScoreTeam2, team1 = (int)_match.Team1.Id, team2 = (int)_match.Team2.Id, week = weekId
            };

            using (var context = new escorcenterdbEntities())
            {
                context.matches.Add(m);
                context.SaveChanges();
            }
            return(Ok(m));
        }
Ejemplo n.º 25
0
        public IHttpActionResult CreateSeason([FromBody] SeasonDTO _season)
        {
            season s = new season()
            {
                description = _season.Description, league = (int)_season.League, dateFrom = DateTime.Now, dateTo = new DateTime(2016, 04, 29), title = _season.Title
            };

            using (var context = new escorcenterdbEntities())
            {
                context.seasons.Add(s);
                context.SaveChanges();
            }
            return(Ok(s));
        }
Ejemplo n.º 26
0
 public IHttpActionResult GetSeasons()
 {
     season[] _season = null;
     using (var context = new escorcenterdbEntities())
     {
         _season = (from s in context.seasons select s).ToArray <season>();
     }
     if (_season == null)
     {
         return(Ok());
     }
     SeasonDTO[] seasons = AutoMapper.Mapper.Map <season[], SeasonDTO[]>(_season);
     return(Ok(seasons));
 }
        public IHttpActionResult CreateLeague([FromBody] LeagueDTO _league)
        {
            league l = new league()
            {
                Name = _league.Name, Description = _league.Description, Enabled = true, Region = _league.Region
            };

            using (var context = new escorcenterdbEntities())
            {
                context.leagues.Add(l);
                context.SaveChanges();
            }
            return(Ok(l));
        }
        public long GetCurrentSeasonId(long leagueId, DateTime date)
        {
            season _season = null;

            using (var context = new escorcenterdbEntities())
            {
                _season = (from s in context.seasons where s.league == leagueId && s.dateFrom <= date && s.dateTo >= date && s.enabled == true select s).FirstOrDefault <season>();
            }
            if (_season == null)
            {
                return(0);
            }
            return(_season.id);
        }
        public IHttpActionResult GetNotifications(string AllValues)
        {
            string[]      values       = AllValues.Split('/');
            HashSet <int> leagueId     = new HashSet <int>();
            HashSet <int> teamId       = new HashSet <int>();
            bool          teamAppeared = false;

            foreach (string value in values)
            {
                if (value.Equals("teams"))
                {
                    teamAppeared = true;
                }
                else if (teamAppeared)
                {
                    teamId.Add(int.Parse(value));
                }
                else
                {
                    leagueId.Add(int.Parse(value));
                }
            }

            List <notification> _notifications;

            using (var context = new escorcenterdbEntities())
            {
                _notifications = ((from n in context.notifications.AsEnumerable()
                                   where IncludeNotification(n, teamId, leagueId)
                                   select n).OrderBy(n => n.Date).ToList <notification>());
            }

            if (_notifications == null)
            {
                return(Ok());
            }

            _notifications = _notifications.OrderBy(n => n.Id).ToList().ToList <notification>();
            NotificationDTO[] notifications = AutoMapper.Mapper.Map <notification[], NotificationDTO[]>(_notifications.ToArray());

            NotificationListDTO notificationList = new NotificationListDTO();

            notificationList.items.AddRange(notifications);
            if (notificationList.items.Count == 0)
            {
                return(Ok());
            }
            return(Ok(notificationList));
        }
        public IHttpActionResult CreateTeam([FromBody] TeamDTO _team)
        {
            LeaguesApiController leaguesApiController = new LeaguesApiController();
            int  leagueId = leaguesApiController.getLeagueIdByTeamId(_team.Id);
            team t        = new team {
                Name = _team.Name, Description = _team.Description, League = leagueId, Enabled = true, Logo = _team.Logo
            };

            using (var context = new escorcenterdbEntities())
            {
                context.teams.Add(t);
                context.SaveChanges();
            }
            return(Ok(t));
        }