public bool Create(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

            using (var database = new DataEntities())
            {
                var team = new Team
                {
                    Name = model.Name,
                    Description = model.Description
                };
                database.AddToTeam(team);
                if (model.Members != null)
                {
                    AddMembers(model.Members, team, database);
                }
                try
                {
                    database.SaveChanges();
                }
                catch (UpdateException)
                {
                    return false;
                }
            }

            return true;
        }
 private TeamModel GetTeamModel(Team team)
 {
         return team == null ? null : new TeamModel
         {
             Id = team.Id,
             Name = team.Name,
             Description = team.Description,
             Members = team.Users.Select(user => user.ToModel()).ToArray(),
         };
 }
        public bool Create(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

            using (var database = CreateContext())
            {
                // Write this into the model so that the caller knows the ID of the new itel
                model.Id = Guid.NewGuid();
                var team = new Team
                {
                    Id = model.Id,
                    Name = model.Name,
                    Description = model.Description
                };
                database.Teams.Add(team);
                if (model.Members != null)
                {
                    AddMembers(model.Members.Select(x => x.Id), team, database);
                }
                try
                {
                    database.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    return false;
                }
                catch (UpdateException)
                {
                    // Not sure when this exception happens - DbUpdateException is what you get for adding a duplicate teamname
                    return false;
                }
            }

            return true;
        }
 private void AddMembers(string[] members, Team team, DataEntities database)
 {
     var users = database.User.Where(i => members.Contains(i.Username));
     foreach (var item in users)
     {
         team.Members.Add(item);
     }
 }
 private void AddMembers(IEnumerable<Guid> members, Team team, BonoboGitServerContext database)
 {
     var users = database.Users.Where(user => members.Contains(user.Id));
     foreach (var item in users)
     {
         team.Users.Add(item);
     }
 }
 private TeamModel TeamToTeamModel(Team t)
 {
     return new TeamModel
     {
         Id = t.Id,
         Name = t.Name,
         Description = t.Description,
         Members = t.Users.Select(user => user.ToModel()).ToArray()
     };
 }
 /// <summary>
 /// Create a new Team object.
 /// </summary>
 /// <param name="name">Initial value of the Name property.</param>
 public static Team CreateTeam(global::System.String name)
 {
     Team team = new Team();
     team.Name = name;
     return team;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Team EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTeam(Team team)
 {
     base.AddObject("Team", team);
 }
 private void AddMembers(IEnumerable<string> members, Team team, BonoboGitServerContext database)
 {
     var users = database.Users.Where(i => members.Contains(i.Username));
     foreach (var item in users)
     {
         team.Users.Add(item);
     }
 }
示例#10
0
 private TeamModel CreateViewModel(Team team)
 {
     return new TeamModel
     {
         Name = team.Name,
         Description = team.Description,
         Members = team.Members.Select(member => member.Username).ToArray(),
         Repositories = team.Repositories.Select(repo => repo.Name).ToArray(),
     };
 }