Ejemplo n.º 1
0
        public async Task <IActionResult> ViewAgency(string agencyId)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (!await _context.ManagesAgency(userId, agencyId))
            {
                return(Forbid());
            }

            var agency = await _context.Agencies
                         .Include(i => i.AdminContact)
                         .Include(i => i.TechnicalContact)
                         .Include(i => i.Creator)
                         .Include(i => i.Assignments)
                         .ThenInclude(i => i.Services)
                         .Include(i => i.Assignments)
                         .ThenInclude(i => i.Delegations)
                         .Include(i => i.Assignments)
                         .ThenInclude(i => i.HttpResolvers)
                         .FirstOrDefaultAsync(x => x.AgencyId == agencyId);

            AgencyOverviewModel model = new AgencyOverviewModel();

            model.Agency           = agency;
            model.AdminContact     = agency.AdminContact;
            model.TechnicalContact = agency.TechnicalContact;
            model.Assignments      = agency.Assignments;

            foreach (Assignment a in model.Assignments)
            {
                model.Services[a.AssignmentId]      = a.Services;
                model.Delegations[a.AssignmentId]   = a.Delegations;
                model.HttpResolvers[a.AssignmentId] = a.HttpResolvers;
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(string agencyName)
        {
            //RegistryProvider provider = new RegistryProvider();

            if (string.IsNullOrEmpty(agencyName))
            {
                //Collection<Agency> agencies = provider.GetAgencies(state: ApprovalState.Approved);
                List <Agency> agencies = await _context.Agencies.Where(x => x.ApprovalState == ApprovalState.Approved).ToListAsync();

                return(View("AgencyList", agencies));
            }

            AgencyOverviewModel model = new AgencyOverviewModel();



            //Agency agency = provider.GetAgency(agencyName);
            var agency = await _context.Agencies.SingleOrDefaultAsync(x =>
                                                                      x.AgencyId == agencyName &&
                                                                      x.ApprovalState == ApprovalState.Approved);

            if (agency == null || agency.ApprovalState != ApprovalState.Approved)
            {
                UnknownAgencyModel unknownModel = new UnknownAgencyModel()
                {
                    AgencyName = agencyName
                };
                return(View("UnknownAgency", unknownModel));
            }



            await _context.Entry(agency)
            .Reference(x => x.AdminContact)
            .LoadAsync();

            await _context.Entry(agency)
            .Reference(x => x.TechnicalContact)
            .LoadAsync();

            await _context.Entry(agency)
            .Reference(x => x.Creator)
            .LoadAsync();

            await _context.Entry(agency)
            .Collection(x => x.Assignments)
            .LoadAsync();

            model.Agency           = agency;
            model.AdminContact     = agency.AdminContact;
            model.TechnicalContact = agency.TechnicalContact;
            model.Assignments      = agency.Assignments;

            foreach (Assignment a in model.Assignments)
            {
                await _context.Entry(a)
                .Collection(x => x.Services)
                .LoadAsync();

                await _context.Entry(a)
                .Collection(x => x.Delegations)
                .LoadAsync();

                await _context.Entry(a)
                .Collection(x => x.HttpResolvers)
                .LoadAsync();

                model.Services[a.AssignmentId]      = a.Services;
                model.Delegations[a.AssignmentId]   = a.Delegations;
                model.HttpResolvers[a.AssignmentId] = a.HttpResolvers;
            }

            return(View(model));
        }