public void DeleteMatch(Guid ID)
 {
     //get existing record to delete
     Models.DBObjects.SoccerMatch matchToDelete = dbContext.SoccerMatches.FirstOrDefault(x => x.IDMatch == ID);
     if (matchToDelete != null)
     {
         dbContext.SoccerMatches.DeleteOnSubmit(matchToDelete); //mark for deletion
         dbContext.SubmitChanges();
     }
 }
        public SoccerMatchModel GetMatchByID(Guid ID)
        {
            Models.DBObjects.SoccerMatch existingMatch = dbContext.SoccerMatches.FirstOrDefault(x => x.IDMatch == ID);

            if (existingMatch != null)
            {
                return(existingMatch.MapObject <SoccerMatchModel>());
            }
            else
            {
                return(null);
            }
        }
 //map Model object to ORM model – mapper method
 private Models.DBObjects.SoccerMatch MapModelToDbObject(SoccerMatchModel matchModel)
 {
     Models.DBObjects.SoccerMatch dbMatchModel = new Models.DBObjects.SoccerMatch();
     if (matchModel != null)
     {
         dbMatchModel.IDMatch   = matchModel.IDMatch;
         dbMatchModel.HomeTeam  = matchModel.HomeTeam;
         dbMatchModel.GuestTeam = matchModel.GuestTeam;
         dbMatchModel.Stadium   = matchModel.Stadium;
         dbMatchModel.City      = matchModel.City;
         dbMatchModel.IdLeague  = matchModel.IdLeague;
         return(dbMatchModel);
     }
     return(null);
 }
        //map ORM model to Model object – mapper method
        private SoccerMatchModel MapDbObjectToModel(Models.DBObjects.SoccerMatch dbMatch)
        {
            SoccerMatchModel matchModel = new SoccerMatchModel();

            if (dbMatch != null)
            {
                matchModel.IDMatch   = dbMatch.IDMatch;
                matchModel.HomeTeam  = dbMatch.HomeTeam;
                matchModel.GuestTeam = dbMatch.GuestTeam;
                matchModel.Stadium   = dbMatch.Stadium;
                matchModel.City      = dbMatch.City;
                matchModel.IdLeague  = dbMatch.IdLeague;
                return(matchModel);
            }
            return(null);
        }
        public void UpdateMatch(SoccerMatchModel matchModel)
        {
            //get existing record to update
            Models.DBObjects.SoccerMatch existingMatch = dbContext.SoccerMatches.FirstOrDefault(x => x.IDMatch == matchModel.IDMatch);
            if (existingMatch != null)
            {
                //map updated values with keeping the ORM objecte reference
                existingMatch.IDMatch   = matchModel.IDMatch;
                existingMatch.HomeTeam  = matchModel.HomeTeam;
                existingMatch.GuestTeam = matchModel.GuestTeam;
                existingMatch.Stadium   = matchModel.Stadium;
                existingMatch.City      = matchModel.City;
                existingMatch.IdLeague  = matchModel.IdLeague;
                existingMatch.UpdateObject(matchModel);

                dbContext.SubmitChanges(); //commit to db
            }
        }