Exemple #1
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Project = await _context.Project.
                      Where(p => p.ProjectID == id).
                      Include(a => a.Postulations).
                      ThenInclude(t => t.Technician).
                      AsNoTracking().FirstOrDefaultAsync(m => m.ProjectID == id);

            if (Project == null)
            {
                return(NotFound());
            }

            // Populate the list of technicians in the viewmodel with the technician of the Project.
            this.Technicians = Project.Postulations.Select(t => t.Technician);

            string roleFilter = "";

            if (this.SearchString != null)
            {
                roleFilter = this.SearchString.ToUpper();
            }
            // Populate the list of all other Technicians with all technicians not included in the project's technician and
            // included in the search filter.
            this.OtherTechnicians = await _context.Technician
                                    .Where(t => !Technicians.Contains(t)).
                                    Where(t => !string.IsNullOrEmpty(roleFilter) ? t.Name.ToUpper().
                                          Contains(roleFilter) : true).ToListAsync();

            try
            {
                Check.Precondition(OtherTechnicians != null, "Error al cargar los otros técnicos");
            }
            catch (Check.PreconditionException ex)
            {
                return(Redirect("https://localhost:5001/Exception?id=" + ex.Message));
            }

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Project = await _context.Project
                      .Where(m => m.ID == id)
                      .Include(c => c.Assignments)
                      .ThenInclude(a => a.Technician)
                      .FirstOrDefaultAsync();

            if (Project == null)
            {
                return(NotFound());
            }

            this.Technicians = Project.Assignments
                               .Select(a => a.Technician);

            string nameFilter = "";

            if (this.SearchString != null)
            {
                nameFilter = this.SearchString.ToUpper();
            }

            //Se incluyen los Technicians no incluidos
            //Se agrega filtro por Technicians

            this.AllTechnicians = await _context.Technician
                                  .Where(a => !Technicians.Contains(a))
                                  .Where(a => !string.IsNullOrEmpty(nameFilter) ? a.Name.ToUpper().Contains(nameFilter) : true)
                                  .ToListAsync();

            return(Page());
        }