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);
 }
 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);
 }
 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);
 }
 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);
 }
 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 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 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 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);
 }
 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 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 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 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);
 }
 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 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 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 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();
 }
 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);
 }
 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 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);
 }