Пример #1
0
        public async Task <ActionResult> Settings(SettingsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // TODO: Setup/move validation to EF model?
            // TODO: Support ajax submit?
            // TODO: Wrap in a try/catch

            var repository = DataContext.Repositories.Where(model.RepoOwner, model.RepoName);

            if (repository != null)
            {
                repository.AccessToken = model.AccessToken;
                repository.RequireCla  = model.RequireCla;
                repository.LicenseText = model.LicenseText;
            }
            else
            {
                repository = new Repository(
                    owner: model.RepoOwner,
                    name: model.RepoName,
                    requireCla: model.RequireCla,
                    accessToken: model.AccessToken,
                    licenseText: model.LicenseText);
                DataContext.Repositories.Add(repository);
            }

            DataContext.SaveChanges();

            await GitHubService.EnableWebHook(repository);

            TempData["settingsChanged"] = new SettingsChangedNotification(repository.RequireCla ? "success" : "warning", repository);
            return(Redirect(string.Format("/{0}/{1}/", model.RepoOwner, model.RepoName)));
        }