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

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

            return true;
        }
Example #2
0
        public ActionResult CreateTeam(TeamModel model)
        {
            if (ModelState.IsValid)
            {
                if (Session["user"] != null)
                {
                    MemberCreateStatus createStatus;
                    createStatus = TeamManager.CreateTeam(model, db);
                    if (createStatus == MemberCreateStatus.Success)
                    {
                        MemberCreateStatus linkStatus;
                        Trace.WriteLine((((Member)Session["user"]).ID));
                        linkStatus = TeamManager.LinkChief(model, (Member)Session["user"], db);
                        if (linkStatus == MemberCreateStatus.Success)
                        {
                            var _model = from u in db.teams
                                         where u.name == model.TeamName
                                         select u;
                            Trace.WriteLine("Team has been created.");

                            return RedirectToAction("TeamProfile", "Team", new { id = _model.First().ID });
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                        Trace.WriteLine("Team has not been created.");
                    }
                }
                else {
                    return RedirectToAction("LogOn", "Account");
                }
            }
            return RedirectToAction("Index", "Home");
        }
Example #3
0
        public static MemberCreateStatus CreateTeam(TeamModel model, OnGameContext _db)
        {
            MemberCreateStatus success = MemberCreateStatus.UserRejected;

            try
            {
                var modelExist = from m in _db.teams
                                 where m.name == model.TeamName
                                 select m;
                if (modelExist.Count() == 0)
                {
                    modelExist = from m in _db.teams
                                 where m.tag == model.TeamTag
                                 select m;
                    if (modelExist.Count() == 0)
                    {
                        _db.teams.Add(new Team
                        {
                            name = model.TeamName,
                            tag = model.TeamTag,
                            description = model.Description,
                            photo = "Unknown.jpg"
                        });
                        _db.SaveChanges();
                        success = MemberCreateStatus.Success;
                    }
                    else
                    {
                        success = MemberCreateStatus.UserExist;
                    }
                }
                else
                {
                    success = MemberCreateStatus.EmailExist;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            return success;
        }
        public TeamModel CreateTeam(TeamModel model)
        {
            // Into ConvertToTeamsModel, pass TeamFile and PersonFile to return a List of TeamModels.
            List <TeamModel> teams = TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(PersonFile);

            // find the id
            int currentId = 1;

            if (teams.Count > 0)
            {
                currentId = teams.OrderByDescending(x => x.Id).First().Id + 1;
            }

            // add the new record with the new Id (max + 1)
            model.Id = currentId;

            teams.Add(model);

            teams.SaveToTeamsFile(TeamFile);

            return(model);
        }
Example #5
0
        public async Task CreateTeam(TeamModel team)
        {
            var p = new DynamicParameters();

            p.Add("@TeamName", team.TeamName);
            p.Add("@id", DbType.Int32, direction: ParameterDirection.Output);

            await _dataAccess.SaveData("dbo.spTeams_Insert",
                                       p, _connectionString.SqlConnectionName);

            team.Id = p.Get <int>("@id");

            foreach (PersonModel tm in team.TeamMembers)
            {
                p = new DynamicParameters();
                p.Add("@TeamId", team.Id);
                p.Add("@PersonId", tm.Id);

                await _dataAccess.SaveData("dbo.spTeamMembers_Insert",
                                           p, _connectionString.SqlConnectionName);
            }
        }
Example #6
0
        /// <summary>
        /// Gets the impediments list.
        /// </summary>
        /// <param name="team">The team.</param>
        /// <returns></returns>
        public async Task <ActiveSpirntIssuesModel> GetActiveSpintIssuesModel(TeamModel team)
        {
            var activeSprintIssues = await GetAllTeamIssuesInCurrentSprint(team.TeamMembersNames, team.ProjectName, team.ProjectAgileBoardName);

            // Selecting only impeded issues
            var impedimentIssues = activeSprintIssues
                                   .Where(i => _impededIssueTypes.Contains(i.Fields.Status.Name))
                                   .ToList();

            // Selecting not impeded issues
            var notImpedimentIssues = activeSprintIssues
                                      .Where(i => !_impededIssueTypes.Contains(i.Fields.Status.Name))
                                      .ToList();

            var activeSpirntIssuesModel = new ActiveSpirntIssuesModel()
            {
                ImpedimentIssues    = impedimentIssues,
                NotImpedimentIssues = notImpedimentIssues
            };

            return(activeSpirntIssuesModel);
        }
Example #7
0
        public static List <TeamModel> ConvertToTeamModels(this List <string> lines, string peopleFileName)
        {
            //id,teamName,set of ids seperated by pipe
            //1,Class of 92, 1|2|3|4|5
            List <TeamModel>   output = new List <TeamModel>();
            List <PersonModel> people = peopleFileName.FullFilePath().LoadFile().ConvertToPersonModels();

            foreach (string line in lines)
            {
                string[]  cols = line.Split(',');
                TeamModel t    = new TeamModel();
                t.Id       = int.Parse(cols[0]);
                t.TeamName = cols[1];
                string[] personIds = cols[2].Split('|');
                foreach (string id in personIds)
                {
                    t.TeamMembers.Add(people.Where(x => x.Id == int.Parse(id)).First());
                }
                output.Add(t);
            }
            return(output);
        }
Example #8
0
        private void UpdateTeams()
        {
            foreach (var team in Teams.Select(x => new { x.Id, Name = x.Name }).Where(x => !ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys.Contains(x.Name, StringComparer.OrdinalIgnoreCase)))
            {
                Teams.Remove(team.Id);
            }

            if (MembershipService == null)
            {
                MembershipService = new ADMembershipService();
            }

            foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys)
            {
                string groupName = ActiveDirectorySettings.TeamNameToGroupNameMapping[teamName];

                Log.Verbose("AD: Updating team {TeamName} (groupName {GroupName})", teamName, groupName);
                try
                {
                    GroupPrincipal group;
                    using (var pc = ADHelper.GetPrincipalGroup(groupName, out group))
                    {
                        TeamModel teamModel = new TeamModel()
                        {
                            Id          = group.Guid.Value,
                            Description = group.Description,
                            Name        = teamName,
                            Members     = group.GetMembers(true).Select(x => MembershipService.GetUserModel(x.Guid.Value)).Where(o => o != null).ToArray()
                        };
                        Teams.AddOrUpdate(teamModel);
                        Log.Verbose("AD: Updated team {TeamName} OK", teamName);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "AD: Failed to update team {TeamName}", teamName);
                }
            }
        }
Example #9
0
        private void RemoveSelectedPlayerButton_Click(object sender, EventArgs e)
        {
            //PersonModel p = (PersonModel)teamMembersListBox.SelectedItem;

            //if (p != null)
            //{
            //    selectedTeamMembers.Remove(p);
            //    availableTeamMembers.Add(p);

            //    WireUpLists();
            //}

            TeamModel t = (TeamModel)tournamentTeamsListBox.SelectedItem;

            if (t != null)
            {
                selectedTeams.Remove(t);
                availableTeams.Add(t);

                WireUpLists();
            }
        }
        public void CreateTeam(TeamModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spTeams_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");

                foreach (PersonModel tm in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", tm.Id);

                    connection.Execute("dbo.spTeamMembers_Insert", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Example #11
0
        public void CreateTeam(TeamModel model)
        {
            using (IDbConnection connection = new SqlConnection(CM.ConnectionStrings["Tournaments"].ConnectionString))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);
                p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spTeams_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@Id");

                foreach (PersonModel teamMember in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", teamMember.Id);

                    connection.Execute("dbo.spTeamMembers_Insert", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
        /// <summary>
        /// to add data into the TeamModels.csv
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public void CreateTeam(TeamModel model)
        {
            List <TeamModel> teams = GlobalConfig.TeamFile.FullFilePath().LoadFile().ConvertToTeamModels();

            int currentId = 1;

            if (teams.Count > 0)
            {
                currentId = teams.OrderByDescending(x => x.Id).First().Id + 1;
            }

            model.Id = currentId;


            //Add the new record with the new ID(max +1)
            teams.Add(model);


            // Convert the prizes to list<strings>
            //Save the list<string> to the text file
            teams.SaveToTeamFile();
        }
Example #13
0
        private void addTeamButton_Click(object sender, EventArgs e)
        {
            if (availableTeams.Count == 0)
            {
                MessageBox.Show("The list is already empty!");
                return;
            }

            if (selectTeamDropDown.SelectedValue == null)
            {
                MessageBox.Show("Pleas, select some Team.");
                return;
            }


            TeamModel t = (TeamModel)selectTeamDropDown.SelectedItem;

            availableTeams.Remove(t);
            selectedTeams.Add(t);

            InitializeLists();
        }
Example #14
0
        public TeamModel CreateTeam(TeamModel model)
        {
            List <TeamModel> teams = TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(PeopleFile);

            int currentId = 1;

            // If count is 0 then there are no records and skip finding max value.
            if (teams.Count > 0)
            {
                // Find the max ID
                currentId = teams.OrderByDescending(x => x.Id).First().Id + 1;
            }

            model.Id = currentId;

            // Add the new record with the new ID (max + 1)
            teams.Add(model);

            teams.SaveToTeamsFile(TeamFile);

            return(model);
        }
Example #15
0
        private void removeSelectedPlayerButton_Click(object sender, EventArgs e)
        {
            /*PersonModel p = (PersonModel)teamMembersListBox.SelectedItem;
             *
             * if (p != null)
             * {
             *   selectedTeamMembers.Remove(p);
             *   availableTeamMembers.Add(p);
             *
             *   WireUpLists();
             * }*/

            TeamModel t = (TeamModel)tournamentTeamsListBox.SelectedItem;

            if (t != null)
            {
                selectedTeams.Remove(t);
                availableTeams.Add(t);

                WireUpLists();
            }
        }
Example #16
0
        public static List <TeamModel> ConvertToTeamModels(this List <string> lines)
        {
            List <TeamModel>   output = new List <TeamModel>();
            List <PersonModel> people = GlobalConfig.PeopleFile.FullFilePath().LoadFile().ConvertToPersonModels();

            foreach (string line in lines)
            {
                string[]  cols = line.Split(',');
                TeamModel t    = new TeamModel();
                t.Id       = int.Parse(cols[0]);
                t.TeamName = cols[1];

                string[] personIds = cols[2].Split('|');

                foreach (string Id in personIds)
                {
                    t.TeamMembers.Add(people.Where(x => x.Id == int.Parse(Id)).First());
                }
                output.Add(t);
            }
            return(output);
        }
Example #17
0
        public async Task <IActionResult> RemoveFromProject(int?projectId, int?teamId)
        {
            if (await extractUser())
            {
                if (user.role.name == "CEO")
                {
                    if (projectId == null || teamId == null)
                    {
                        return(NotFound());
                    }

                    TeamModel teamForRemoval = await _context.Teams.FirstAsync(t => t.id == teamId);

                    ProjectModel projectModel = await _context.Projects.Include(p => p.workingTeams).ThenInclude(t => t.teamLeader)
                                                .FirstOrDefaultAsync(m => m.id == projectId);

                    if (projectModel == null)
                    {
                        return(NotFound());
                    }

                    projectModel.workingTeams.Remove(teamForRemoval);
                    teamForRemoval.project = null;
                    await _context.SaveChangesAsync();

                    //TODO: Refaactor
                    return(await ProjectDetailsView(projectModel));
                }
                else
                {
                    return(View("NoPermission"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "LogIn"));
            }
        }
Example #18
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(TeamModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into CORE.dbo.Team (");
            strSql.Append("TeamName,TeamPlaces");
            strSql.Append(") values (");
            strSql.Append("@TeamName,@TeamPlaces");
            strSql.Append(") ");
            strSql.Append(";");
            SqlParameter[] parameters =
            {
                new SqlParameter("@TeamName",   SqlDbType.VarChar, 150),
                new SqlParameter("@TeamPlaces", SqlDbType.Int, 4)
            };

            parameters[0].Value = model.TeamName;
            parameters[1].Value = model.TeamPlaces;

            bool result = false;

            try
            {
                model.TeamId = decimal.Parse(helper.ExecuteNonQueryBackId(strSql.ToString(), "TeamId", parameters));


                result = true;
            }
            catch (Exception ex)
            {
                this.helper.Close();
                throw ex;
            }
            finally
            {
            }
            return(result);
        }
Example #19
0
        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);
                }
            }

            return(true);
        }
Example #20
0
        public void CreateTeam(TeamModel team)
        {
            using (IDbConnection connection = new MySqlConnection(GlobalConfig.GetConnectionString(db)))
            {
                var parameters = new DynamicParameters();
                parameters.Add("argTeamName", team.Name);
                parameters.Add("id", 0, DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("tournaments.spTeams_Insert", parameters, commandType: CommandType.StoredProcedure);

                team.Id = parameters.Get <int>("id");

                foreach (PersonModel person in team.Members)
                {
                    parameters = new DynamicParameters();
                    parameters.Add("argTeamId", team.Id);
                    parameters.Add("argPersonId", person.Id);
                    parameters.Add("id", 0, DbType.Int32, direction: ParameterDirection.Output);

                    connection.Execute("tournaments.spTeamMembers_Insert", parameters, commandType: CommandType.StoredProcedure);
                }
            }
        }
Example #21
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();
            }
        }
Example #22
0
        public TeamModel CreateTeam(TeamModel model)
        {
            List <TeamModel> teams = TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(PeopleFile);

            //find the max ID
            int currentId = 1;

            if (teams.Count > 0)
            {
                currentId = teams.OrderByDescending(x => x.Id).First().Id + 1;
            }

            model.Id = currentId;

            //add the new record with the new ID(max +1)
            teams.Add(model);

            //convert the prizes to list<string>
            //save the list<string> to the text file
            teams.SaveToTeamFile(TeamFile);

            return(model);
        }
Example #23
0
        public void createTeam(TeamModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(DB)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spTeams_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");

                //Insert everyone of those people into our table
                foreach (PersonModel tm in model.TeamMembers)
                {
                    p = new DynamicParameters(); //this is dynamicparameters which you want to use therefore we can change it
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", tm.Id);

                    connection.Execute("dbo.spTeamMembers_Insert", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Example #24
0
        private void removeSelectedTeamButton_Click(object sender, EventArgs e)
        {
            if (selectedTeams.Count == 0)
            {
                MessageBox.Show("The list is already empty!");
                return;
            }

            if (tournamentTeamsListBox.SelectedValue == null)
            {
                MessageBox.Show("Select some team.");
                return;
            }



            TeamModel t = (TeamModel)tournamentTeamsListBox.SelectedItem;

            selectedTeams.Remove(t);
            availableTeams.Add(t);

            InitializeLists();
        }
        public IEnumerable <TeamModel> CreateTeams(int count = 1, int start = 0, [CallerMemberName] string baseTeamname = "")
        {
            baseTeamname = MakeName(baseTeamname);
            var testteams = new List <TeamModel>();

            foreach (int i in start.To(start + count - 1))
            {
                var team = new TeamModel {
                    Name = baseTeamname + i, Description = "Some team " + i
                };
                _app.NavigateTo <TeamController>(c => c.Create());
                _app.FindFormFor <TeamEditModel>()
                .Field(f => f.Name).SetValueTo(team.Name)
                .Field(f => f.Description).SetValueTo(team.Description)
                .Submit();
                AssertThatNoValidationErrorOccurred();
                var item = _app.WaitForElementToBeVisible(By.XPath("//div[@class='summary-success']/p"), TimeSpan.FromSeconds(1));
                _app.UrlShouldMapTo <TeamController>(c => c.Index());
                team.Id = new Guid(item.GetAttribute("id"));
                testteams.Add(team);
            }
            return(testteams);
        }
        public void CreateTeam(TeamModel model)
        {
            //Тут мы заполняем две таблицы Teams и TeamMembers
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);                                          //Заносим в базу имя команды
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); //ID - вытаскиваем из базы

                connection.Execute("dbo.spTeam_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");

                foreach (PersonModel tm in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", tm.Id);

                    connection.Execute("dbo.spTeamMembers_Insert", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Example #27
0
        public TeamModel CreateTeam(TeamModel team)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var t = new DynamicParameters();
                t.Add("@TeamName", team.TeamName);
                t.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spTeams_Insert", t, commandType: CommandType.StoredProcedure);

                team.Id = t.Get <int>("@id");

                foreach (PersonModel p in team.TeamMembers)
                {
                    t = new DynamicParameters();
                    t.Add("@TeamId", team.Id);
                    t.Add("@PersonId", p.Id);

                    connection.Execute("dbo.spTeamMembers_Insert", t, commandType: CommandType.StoredProcedure);
                }
                return(team);
            }
        }
        public ActionResult Edit(TeamModel model)
        {
            var team = _teamRepository.GetById(model.Id);

            if (ModelState.IsValid)
            {
                team = model.ToEntity(team);
                //always set IsNew to false when saving
                team.IsNew = false;
                _teamRepository.Update(team);

                //commit all changes
                this._dbContext.SaveChanges();

                //notification
                SuccessNotification(_localizationService.GetResource("Record.Saved"));
                return(new NullJsonResult());
            }
            else
            {
                return(Json(new { Errors = ModelState.SerializeErrors() }));
            }
        }
Example #29
0
        public void EditTeam(TeamModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfiguration.ConnectionString(Db)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);
                p.Add("@Id", model.Id);
                connection.Execute("dbo.spTeams_Update", p, commandType: CommandType.StoredProcedure);

                p = new DynamicParameters();
                p.Add("@TeamId", model.Id);
                connection.Execute("dbo.spTeamMembers_Delete", p, commandType: CommandType.StoredProcedure);

                foreach (ApplicationUser t in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamID", model.Id);
                    p.Add("@PlayerID", t.Id);

                    connection.Execute("dbo.spTeamMembers_Update", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Example #30
0
        public static List <TeamModel> ConvertToTeamModels(this List <string> lines, string peopleFileName)
        {
            List <TeamModel>   output    = new List <TeamModel>();
            List <PersonModel> allPeople = peopleFileName.GenerateFullPath().GetListFromFile().ConvertToPersonModels();

            foreach (string line in lines)
            {
                string[] cols = line.Split(',');

                var team = new TeamModel
                {
                    Id       = int.Parse(cols[0]),
                    TeamName = cols[1]
                };

                HashSet <int> teamMemberIds = cols[2].Split('|').Select(x => int.Parse(x)).ToHashSet();
                team.TeamMembers = allPeople.Where(x => teamMemberIds.Contains(x.Id)).ToList();

                output.Add(team);
            }

            return(output);
        }
        public static List <TeamModel> ConvertToTeamModels(this List <string> lines, string personModelsFile)
        {
            List <TeamModel>   output  = new List <TeamModel>();
            List <PersonModel> persons = personModelsFile.FullFilePath().LoadFile().ConvertToPersonModels();

            foreach (string line in lines)
            {
                string[]  cols = line.Split(',');
                TeamModel team = new TeamModel();
                team.Id   = int.Parse(cols[0]);
                team.Name = cols[1];

                string[] personIds = cols[2].Split('|');
                foreach (string personId in personIds)
                {
                    team.Members.Add(persons.Where(x => x.Id == int.Parse(personId)).First());
                }

                output.Add(team);
            }

            return(output);
        }
Example #32
0
 /// <summary>
 /// Put API/Team/{id}
 /// </summary>
 /// <param name="Team">CharactersConfiguration à insérer</param>
 /// <param name="id">Id de la CharactersConfiguration à Updateier</param>
 public IHttpActionResult Put(int id, TeamModel Team)
 {
     if ((new[] { "Admin", "User" }).Contains(ValidateTokenAndRole.ValidateAndGetRole(Request), StringComparer.OrdinalIgnoreCase))
     {
         if (repo.GetOne(id) == null)
         {
             return(NotFound());
         }
         else if (Team == null || Team.CharactersConfiguration.Id == 0 || Team.Zone.Id == 0 || Team.User.Id == 0 || Team.TeamName == null)
         {
             return(BadRequest());
         }
         else
         {
             repo.Update(id, Team.ToEntity());
             return(Ok());
         }
     }
     else
     {
         return(Unauthorized());
     }
 }
        public void CreateTeam(TeamModel model)
        {
            // by using a 'using statement, we ensure that the database connection is properly closed by the closing bracket. Otherwise, data leaks can happen.
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spTeams_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");

                foreach (PersonModel tm in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", tm.Id);

                    connection.Execute("dbo.spTeamMembers_Insert", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Example #34
0
        private void UpdateTeams()
        {
            foreach (string team in Teams.Select(x => x.Name).Where(x => !ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys.Contains(x, StringComparer.OrdinalIgnoreCase)))
            {
                Teams.Remove(team);
            }

            using (PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, ActiveDirectorySettings.DefaultDomain))
            {
                foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys)
                {
                    try
                    {
                        using (GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, IdentityType.Name, ActiveDirectorySettings.TeamNameToGroupNameMapping[teamName]))
                        {
                            TeamModel teamModel = new TeamModel() { Description = group.Description, Name = teamName, Members = group.GetMembers(true).Select(x => x.UserPrincipalName).ToArray() };
                            if (teamModel != null)
                            {
                                Teams.AddOrUpdate(teamModel);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
        public void Update(TeamModel model)
        {
            if (model == null) throw new ArgumentException("team");
            if (model.Name == null) throw new ArgumentException("name");

            using (var db = new BonoboGitServerContext())
            {
                var team = db.Teams.FirstOrDefault(i => i.Name == model.Name);
                if (team != null)
                {
                    team.Description = model.Description;
                    team.Users.Clear();
                    if (model.Members != null)
                    {
                        AddMembers(model.Members, team, db);
                    }
                    db.SaveChanges();
                }
            }
        }
 public bool Create(TeamModel team)
 {
     throw new NotImplementedException();
 }
 public void Update(TeamModel team)
 {
     throw new NotImplementedException();
 }
 private TeamDetailModel ConvertTeamModel(TeamModel model)
 {
     return model == null ? null : new TeamDetailModel
     {
         Name = model.Name,
         Description = model.Description,
         Members = model.Members,
         Repositories = RepositoryRepository.GetPermittedRepositories(null, new[] { model.Name }).Select(x => x.Name).ToArray(),
         IsReadOnly = MembershipService.IsReadOnly()
     };
 }
Example #39
0
        public static MemberCreateStatus LinkChief(TeamModel model, Member creator, OnGameContext _db)
        {
            MemberCreateStatus success = MemberCreateStatus.UserRejected;

            try
            {
                Trace.WriteLine(creator.ID);

                var teamModel = from t in _db.teams
                                where t.name == model.TeamName
                                select t;

                _db.teamPlayers.Add(new TeamPlayer
                {
                    teamID = teamModel.First(),
                    memberID = _db.members.Find(creator.ID),
                    status = 3
                });
                _db.SaveChanges();
                success = MemberCreateStatus.Success;
            }
            catch (Exception ex)
            {
                success = MemberCreateStatus.EmailExist;
                Trace.WriteLine(ex.Message);
            }

            return success;
        }