Ejemplo n.º 1
0
        public async Task <IActionResult> IndexAsync()
        {
            try
            {
                // TODO make this middleware for relevant actions.
                if (!_credentialsRepository.IsUserSetted())
                {
                    return(RedirectToAction("Index", "Home"));
                }

                var organisationModels = new List <OrganisationModel>();

                // TODO rename the class to some that cover this use case.
                organisationModels.Add(new OrganisationModel
                {
                    Name         = _credentialsRepository.User.Username,
                    Repositories = (await _repositoryRepository.GetAllForCurrentAsync()).ConvertToModel()
                });

                var organisations = await _organisationRepository.GetOrganisationsAsync();

                foreach (var organisation in organisations)
                {
                    var organisationModel = new OrganisationModel
                    {
                        Name         = organisation.Name,
                        Repositories = (await _repositoryRepository.GetAllAsync(organisation)).ConvertToModel()
                    };
                    organisationModels.Add(organisationModel);
                }

                return(View(new OrganisationRepositoriesViewModel(organisationModels,
                                                                  await _repositoryPersistence.GetAllAsync())));
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, exception.Message);
                throw;
            }
        }