public async Task OnGetAsync(long?Id) { var configuration = new DataAccess.Models.Configuration(); if (Id != null) { configuration = await dbContext.Configurations.Where(o => o.Id == Id).Include(x => x.ConfigurationDict).FirstOrDefaultAsync(); if (configuration == null) { Message = "There is no such configuration"; } await SetPageModel(configuration); } else { Configuration = new ConfigurationVM(); var userId = User.GetLoggedInUserId <int>(); var organization = await layoutService.GetOrganizationByUserId(userId); if (organization != null) { Input = new InputModel() { OrganizationId = organization.Id }; } Organizations = new SelectList(await dbContext.Organizations.Select(x => x).ToListAsync(), nameof(DataAccess.Models.Organization.Id), nameof(DataAccess.Models.Organization.DisplayName)); } }
private async Task SetPageModel(DataAccess.Models.Configuration configuration) { Organizations = new SelectList(await dbContext.Organizations.Select(x => x).ToListAsync(), nameof(DataAccess.Models.Organization.Id), nameof(DataAccess.Models.Organization.DisplayName)); Configuration = new ConfigurationVM() { Id = configuration.Id, Key = configuration.ConfigurationDict.Key, Value = configuration.Value, Notes = configuration.Notes, ConfigurationDictId = configuration.ConfigurationDictId, OrganizationId = configuration.OrganizationId }; Input = new InputModel() { Id = configuration.Id, Key = configuration.ConfigurationDict.Key, Value = configuration.Value, Notes = configuration.Notes, ConfigurationDictId = configuration.ConfigurationDictId, OrganizationId = configuration.OrganizationId }; }