Exemplo n.º 1
0
        public ActionResult Edit(string name, TeamModel model)
        {
            if (ModelState.IsValid)
                if (!MembershipService.UpdateTeam(model))
                    throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult Create(TeamModel model)
        {
            if (ModelState.IsValid)
            {
                bool badName;
                var team = MembershipService.CreateTeam(model.Name, model.Description, Token.UserID, out badName);
                if (team != null)
                {
                    return RedirectToAction("Detail", "Team", new { team.Name });
                }
                if (badName)
                    ModelState.AddModelError("Name", SR.Team_AlreadyExists);
            }

            return View(model);
        }
Exemplo n.º 3
0
        public TeamModel GetTeamModel(string name, bool withMembers = false, string viewUser = null)
        {
            using (var ctx = new GitCandyContext())
            {
                var team = ctx.Teams.FirstOrDefault(s => s.Name == name);
                if (team == null)
                    return null;

                var model = new TeamModel
                {
                    Name = team.Name,
                    Description = team.Description,
                };
                if (withMembers)
                {
                    model.MembersRole = ctx.UserTeamRoles
                        .Where(s => s.TeamID == team.ID)
                        .Select(s => new TeamModel.UserRole
                        {
                            Name = s.User.Name,
                            IsAdministrator = s.IsAdministrator
                        })
                        .AsEnumerable()
                        .OrderBy(s => s.Name, new StringLogicalComparer())
                        .ToArray();
                    model.Members = model.MembersRole
                        .Select(s => s.Name)
                        .ToArray();

                    model.RepositoriesRole = ctx.TeamRepositoryRoles
                        // belong team
                        .Where(s => s.TeamID == team.ID)
                        // can view for viewUser
                        .Where(s => !s.Repository.IsPrivate
                            || viewUser != null &&
                                (ctx.Users.Any(t => t.Name == viewUser && t.IsSystemAdministrator)
                                || ctx.UserRepositoryRoles.Any(t => t.RepositoryID == s.RepositoryID
                                    && t.User.Name == viewUser
                                    && t.AllowRead)
                                || ctx.TeamRepositoryRoles.Any(t => t.RepositoryID == s.RepositoryID
                                    && t.Team.UserTeamRoles.Any(r => r.User.Name == viewUser)
                                    && t.AllowRead)))
                        .Select(s => new TeamModel.RepositoryRole
                        {
                            Name = s.Repository.Name,
                            AllowRead = s.AllowRead,
                            AllowWrite = s.AllowWrite,
                        })
                        .AsEnumerable()
                        .OrderBy(s => s.Name, new StringLogicalComparer())
                        .ToArray();
                    model.Repositories = model.RepositoriesRole
                        .Select(s => s.Name)
                        .ToArray();
                }
                return model;
            }
        }
Exemplo n.º 4
0
 public bool UpdateTeam(TeamModel model)
 {
     using (var ctx = new GitCandyContext())
     {
         var team = ctx.Teams.FirstOrDefault(s => s.Name == model.Name);
         if (team != null)
         {
             team.Description = model.Description;
             ctx.SaveChanges();
             return true;
         }
         return false;
     }
 }