示例#1
0
        public void DeleteTeam(int id)
        {
            using (var dbContext = new RosterManagerDataContext())
            {
                var unwantedTeam = (from team in dbContext.Teams
                                    where team.teamId == id
                                    select team).First();

                var unwantedImage = unwantedTeam.Image;
                if (unwantedImage != null)
                {
                    dbContext.Images.DeleteOnSubmit(unwantedImage);
                }

                foreach (var player in unwantedTeam.Players)
                {
                    dbContext.Players.DeleteOnSubmit(player);
                }

                foreach (var stat in unwantedTeam.Stats)
                {
                    dbContext.Stats.DeleteOnSubmit(stat);
                }

                dbContext.Teams.DeleteOnSubmit(unwantedTeam);


                dbContext.SubmitChanges();
            }
        }
示例#2
0
        public void EditPlayer(PlayerModel player)
        {
            using (var dbContext = new RosterManagerDataContext())
            {
                var dbPlayer = (from p in dbContext.Players
                                where p.playerId == player.PlayerId
                                select p).First();

                if (player.AvatarImageFile != null)
                {
                    var unwantedImage = dbPlayer.Image;
                    if (unwantedImage != null)
                    {
                        dbContext.Images.DeleteOnSubmit(unwantedImage);
                    }
                    dbPlayer.Image = new Image()
                    {
                        imageFileName    = player.AvatarImageFile.FileName,
                        imageContent     = ImageController.ConvertToBytes(player.AvatarImageFile),
                        imageContentType = player.AvatarImageFile.ContentType,
                    };
                }

                dbPlayer.playerFirstName  = player.FirstName;
                dbPlayer.playerLastName   = player.LastName;
                dbPlayer.playerScreenName = player.ScreenName;
                dbPlayer.teamId           = player.TeamId;

                dbContext.SubmitChanges();
            }
        }
示例#3
0
 public void AddStat(Stat stat)
 {
     using (var dbContext = new RosterManagerDataContext())
     {
         dbContext.Stats.InsertOnSubmit(stat);
         dbContext.SubmitChanges();
     }
 }
示例#4
0
 public void AddPlayer(Player player)
 {
     using (var dbContext = new RosterManagerDataContext())
     {
         dbContext.Players.InsertOnSubmit(player);
         dbContext.SubmitChanges();
     }
 }
示例#5
0
        public void AddTeam(Team team)
        {
            using (var dbContext = new RosterManagerDataContext())
            {
                dbContext.Teams.InsertOnSubmit(team);

                dbContext.SubmitChanges();
            }
        }
示例#6
0
        public void DeleteStat(int statId)
        {
            using (var dbContext = new RosterManagerDataContext())
            {
                var dbStat = (from s in dbContext.Stats
                              where s.statId == statId
                              select s).First();

                dbContext.Stats.DeleteOnSubmit(dbStat);
                dbContext.SubmitChanges();
            }
        }
示例#7
0
        public void DeleteImage(int imageId)
        {
            using (var dbContext = new RosterManagerDataContext())
            {
                var unwantedImage = (from image in dbContext.Images
                                     where image.imageId == imageId
                                     select image).First();

                dbContext.Images.DeleteOnSubmit(unwantedImage);
                dbContext.SubmitChanges();
            }
        }
示例#8
0
        public void EditStat(StatModel stat)
        {
            using (var dbContext = new RosterManagerDataContext())
            {
                var dbStat = (from s in dbContext.Stats
                              where s.statId == stat.StatId
                              select s).First();

                dbStat.statName  = stat.Name;
                dbStat.statValue = stat.Value;

                dbContext.SubmitChanges();
            }
        }
示例#9
0
        public void EditTeam(TeamModel team)
        {
            using (var dbContext = new RosterManagerDataContext())
            {
                var dbTeam = dbContext.Teams.Single(t => t.teamId == team.TeamId);

                if (team.BannerImageFile != null)
                {
                    var unwantedImage = dbTeam.Image;
                    dbContext.Images.DeleteOnSubmit(unwantedImage);
                    dbTeam.Image = new Image()
                    {
                        imageFileName    = team.BannerImageFile.FileName,
                        imageContent     = ImageController.ConvertToBytes(team.BannerImageFile),
                        imageContentType = team.BannerImageFile.ContentType,
                    };
                }

                dbTeam.teamName = team.Name;

                dbContext.SubmitChanges();
            }
        }
示例#10
0
        public void DeletePlayer(int playerId)
        {
            using (var dbContext = new RosterManagerDataContext())
            {
                var unwantedPlayer = (from player in dbContext.Players
                                      where player.playerId == playerId
                                      select player).First();

                var unwantedImage = unwantedPlayer.Image;
                if (unwantedImage != null)
                {
                    dbContext.Images.DeleteOnSubmit(unwantedImage);
                }

                foreach (var stat in unwantedPlayer.Stats)
                {
                    dbContext.Stats.DeleteOnSubmit(stat);
                }

                dbContext.Players.DeleteOnSubmit(unwantedPlayer);
                dbContext.SubmitChanges();
            }
        }