Exemplo n.º 1
0
        public IHttpActionResult GetAllTeachers()
        {
            string role = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == ClaimTypes.Role).Value;

            try
            {
                switch (role)
                {
                case "admin":
                    var retVal1 = service.GetAll();
                    logger.Info("Returning all teachers.");
                    return(Ok(retVal1));

                case "teacher":
                    string teacherId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;
                    var    retVal2   = service.GetById(teacherId);
                    logger.Info("Returning teacher with id {0} to self.", teacherId);
                    return(Ok(retVal2));

                default:
                    logger.Warn("BadRequest. There is no method for this role! {0}", role);
                    return(BadRequest());
                }
            }
            catch (Exception e)
            {
                logger.Warn("Caught exception with message {0}", e.Message);
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }
Exemplo n.º 2
0
        public IActionResult List()
        {
            ViewBagMethod();
            var list = _teachersService.GetAll("PersonU");

            return(View(list));
        }
Exemplo n.º 3
0
        private void fillLists()
        {
            var asigs  = SubjectsService.GetAll(true).Result;
            var teachs = TeachersService.GetAll(true).Result;
            var trimes = TrimestresService.GetAll(true).Result;

            asigs.Insert(0, new Subjects {
                SubjectId = -1, SubjectName = "Seleccione ---"
            });
            teachs.Insert(0, new Teachers {
                TeacherId = -1, DisplayName = "Seleccione ---"
            });
            trimes.Insert(0, new Trimestres {
                TrimestreId = -1, Name = "Seleccione ---"
            });

            ListTrimestres.BeginInvoke(new Action(() => {
                ListTrimestres.DisplayMember = "Name";
            }));
            ListTrimestres.BeginInvoke(new Action(() => {
                ListTrimestres.ValueMember = "TrimestreID";
            }));
            ListTrimestres.BeginInvoke(new Action(() => {
                ListTrimestres.DataSource = trimes;
            }));

            ListTeachers.BeginInvoke(new Action(() => {
                ListTeachers.DisplayMember = "DisplayName";
            }));
            ListTeachers.BeginInvoke(new Action(() => {
                ListTeachers.ValueMember = "TeacherID";
            }));
            ListTeachers.BeginInvoke(new Action(() => {
                ListTeachers.DataSource = teachs;
            }));

            ListSubjects.BeginInvoke(new Action(() => {
                ListSubjects.DisplayMember = "SubjectName";
            }));
            ListSubjects.BeginInvoke(new Action(() => {
                ListSubjects.ValueMember = "SubjectID";
            }));
            ListSubjects.BeginInvoke(new Action(() => {
                ListSubjects.DataSource = asigs;
            }));

            this.Invoke(new MethodInvoker(() => {
                HaveFilledLists = true;
            }));
            // HaveFilledLists = true;
        }
        public IActionResult GetTeachers([FromQuery] TeachersResourceParameters resourceParameters)
        {
            ThrowHelper.ThrowIfNull(resourceParameters, nameof(resourceParameters));

            var teachers = teachersService
                           .GetAll(resourceParameters);

            if (teachers == null)
            {
                return(NoContent());
            }

            var previousPageLink = teachers.HasPrevious
                ?CreateTeachersResourceUri(resourceParameters,
                                           ResourceUriType.PreviousPage).LowerCaseLink()
                : null;

            var nextPageLink = teachers.HasNext
                ? CreateTeachersResourceUri(resourceParameters,
                                            ResourceUriType.NextPage).LowerCaseLink()
                : null;

            var paginationData = new
            {
                totalCount  = teachers.TotalCount,
                pageSize    = teachers.PageSize,
                currentPage = teachers.CurrentPage,
                totalPages  = teachers.TotalPages,
                previousPageLink,
                nextPageLink
            };

            Response.Headers.Add("X-Pagination",
                                 JsonSerializer.Serialize(paginationData));

            return(Ok(teachers.ShapeData(resourceParameters.Fields)));
        }
 public ActionResult All()
 {
     return(View(_teachersService.GetAll()));
 }
 public IEnumerable <TeachersModel> GetTeachers()
 {
     return(TeachersService.GetAll());
 }