Beispiel #1
0
 public void Add_comment(SingleTeamModel model, string username)
 {
     using (var ctx = new Context())
     {
         Team_comment commentDB = new Team_comment();
         commentDB.Comment = model.Comment;
         commentDB.Active  = true;
         commentDB.Date    = DateTime.UtcNow;
         commentDB.Team    = ctx.Teams.Include("Sport").Include("User").FirstOrDefault(t => t.ID == model.Team.ID);
         commentDB.User    = ctx.Users.FirstOrDefault(u => u.Username == username);
         ctx.Team_comments.Add(commentDB);
         ctx.SaveChanges();
     }
 }
Beispiel #2
0
        public void New_Team(SingleTeamModel model, string username)
        {
            using (var ctx = new Context())
            {
                Team team = new Team();
                team.Name      = model.Team.Name;
                team.Country   = model.Team.Country;
                team.Fans_Name = model.Team.Fans_Name;
                team.Founded   = model.Team.Founded;
                team.Emblem    = model.Team.Emblem;
                team.Webpage   = model.Team.Webpage;
                team.Sport     = ctx.Sports.FirstOrDefault(u => u.ID == model.Team.Sport.ID);
                team.User      = ctx.Users.FirstOrDefault(u => u.Username == username);
                ctx.Teams.Add(team);
                ctx.SaveChanges();

                if (model.Comment != null)
                {
                    Team_comment commentDB = new Team_comment();
                    commentDB.Comment = model.Comment;
                    commentDB.Active  = true;
                    commentDB.Date    = DateTime.UtcNow;
                    commentDB.Team    = team;
                    commentDB.User    = ctx.Users.FirstOrDefault(u => u.Username == username);
                    ctx.Team_comments.Add(commentDB);
                    ctx.SaveChanges();
                }

                if (model.Stadiums != null)
                {
                    foreach (var one in model.Stadiums)
                    {
                        Stadium stadium = ctx.Stadiums.FirstOrDefault(m => m.ID == one);
                        stadium.Team = team;
                        ctx.SaveChanges();
                    }
                }
            }
        }