private RepositoryModel SanitizeModel(RepositoryModel model)
        {
            if (model.Administrators == null)
            {
                model.Administrators = new string[0];
            }

            if (model.Users == null)
            {
                model.Users = new string[0];
            }

            if (model.Teams == null)
            {
                model.Teams = new string[0];
            }

            return model;
        }
        private void CheckForNewRepositories()
        {
            IEnumerable<string> directories = Directory.EnumerateDirectories(UserConfiguration.Current.Repositories);
            foreach (string directory in directories)
            {
                string name = Path.GetFileName(directory);

                RepositoryModel repository = _repositoryRepository.GetRepository(name);
                if (repository == null)
                {
                    if (LibGit2Sharp.Repository.IsValid(directory))
                    {
                        repository = new RepositoryModel();
                        repository.Description = "Discovered in file system.";
                        repository.Name = name;
                        repository.AnonymousAccess = false;
                        _repositoryRepository.Create(repository);
                    }
                }
            }
        }
        public bool Create(RepositoryModel model)
        {
            if (model == null) throw new ArgumentException("model");
            if (model.Name == null) throw new ArgumentException("name");

            using (var database = new BonoboGitServerContext())
            {
                var repository = new Repository
                {
                    Name = model.Name,
                    Logo = model.Logo,
                    Group = model.Group,
                    Description = model.Description,
                    Anonymous = model.AnonymousAccess,
                    AuditPushUser = model.AuditPushUser,
                };
                database.Repositories.Add(repository);
                AddMembers(model.Users, model.Administrators, model.Teams, repository, database);
                try
                {
                    database.SaveChanges();
                }
                catch (UpdateException)
                {
                    return false;
                }
            }

            return true;
        }
        public void Update(RepositoryModel model)
        {
            if (model == null) throw new ArgumentException("model");
            if (model.Name == null) throw new ArgumentException("name");

            using (var db = new BonoboGitServerContext())
            {
                var repo = db.Repositories.FirstOrDefault(i => i.Name == model.Name);
                if (repo != null)
                {
                    repo.Group = model.Group;
                    repo.Description = model.Description;
                    repo.Anonymous = model.AnonymousAccess;
                    repo.AuditPushUser = model.AuditPushUser;

                    if (model.Logo != null)
                        repo.Logo = model.Logo;

                    if (model.RemoveLogo)
                        repo.Logo = null;

                    repo.Users.Clear();
                    repo.Teams.Clear();
                    repo.Administrators.Clear();

                    AddMembers(model.Users, model.Administrators, model.Teams, repo, db);

                    db.SaveChanges();
                }
            }
        }
 public void Update(RepositoryModel repository)
 {
     ADBackend.Instance.Repositories.Update(SanitizeModel(repository));
 }
 public bool Create(RepositoryModel repository)
 {            
     return ADBackend.Instance.Repositories.Add(SanitizeModel(repository));
 }
 private RepositoryDetailStatus GetRepositoryStatus(RepositoryModel model)
 {
     string path = Path.Combine(UserConfiguration.Current.Repositories, model.Name);
     if (!Directory.Exists(path))
     {
         return RepositoryDetailStatus.Missing;
     }
     else
     {
         return RepositoryDetailStatus.Valid;
     }
 }
 private RepositoryDetailModel ConvertRepositoryModel(RepositoryModel model)
 {
     return model == null ? null : new RepositoryDetailModel
     {
         Name = model.Name,
         Group = model.Group,
         Description = model.Description,
         Users = model.Users,
         Administrators = model.Administrators,
         Teams = model.Teams,
         IsCurrentUserAdministrator = model.Administrators.Contains(User.Id(), StringComparer.OrdinalIgnoreCase),
         AllowAnonymous = model.AnonymousAccess,
         Status = GetRepositoryStatus(model),
         AuditPushUser = model.AuditPushUser,
         Logo = new RepositoryLogoDetailModel(model.Logo)
     };
 }