Beispiel #1
0
        public IActionResult GetPeople(
            StudentParameters parameters,
            [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!this.studentService.StudentMappingExists(parameters))
            {
                return(this.BadRequest());
            }
            if (!this.studentService.StudentPropertiesExists(parameters))
            {
                return(this.BadRequest());
            }

            var people      = this.studentService.GetPagedList(parameters);
            var studentDtos = this.mapper.Map <List <StudentDto> >(people);

            if (mediaType == MediaType.OutputFormatterJson)
            {
                this.Response.Headers.Add(Header.XPagination, JsonConvert.SerializeObject(people.CreateBasePagination()));
                var values = studentDtos.ShapeDataCollectionWithHateoasLinks(parameters.Fields, this.CreateLinksStudent);
                var links  = this.urlHelper.CreateLinks(RouteName.GetPeople, parameters, people);
                return(this.Ok(new HateoasDto(values, links)));
            }

            this.Response.Headers.Add(Header.XPagination, JsonConvert.SerializeObject(
                                          this.urlHelper.CreateHateoasPagination(RouteName.GetPeople, parameters, people)));

            return(this.Ok(studentDtos.ShapeDataCollection(parameters.Fields)));
        }
        public object UserLive(StudentParameters obj)
        {
            try
            {
                // var status = db.tbl_user.Where(r => r.code == obj.code && r.type == obj.type).OrderByDescending(r => r.code).ToList();


                tbl_user uobj = db.tbl_user.First(r => r.code == obj.Code && r.type == obj.Type);

                if (uobj.Islive == 0)
                {
                    uobj.Islive = 1;
                }
                else
                {
                    uobj.Islive = 0;
                }


                uobj.code = obj.Code;
                db.SaveChanges();
                return(new Result
                {
                    IsSucess = true,
                    ResultData = "Status Updated!"
                });
            }
            catch (Exception E)
            {
                return(new Error()
                {
                    IsError = true, Message = E.Message
                });
            }
        }
        public PagedList <Student> GetStudents(StudentParameters pagingParameter)
        {
            var students = FindAll();

            SearchByName(ref students, pagingParameter.GradeName);

            return(PagedList <Student> .ToPagedList(students.OrderBy(on => on.StudentName),
                                                    pagingParameter.PageNumber,
                                                    pagingParameter.PageSize));
        }
        public void ThrowsExceptionOrderById(PropertyMappingService property)
        {
            var parameters = new StudentParameters
            {
                OrderBy = "Id",
            };
            var sut = new StudentService(DbContextHelper.SeedRepo(property), new TypeHelperService(), new PropertyMappingService());

            Assert.Throws <ArgumentException>(() => sut.GetPagedList(parameters));
        }
        public void ReturnsChangedPaginationWithSpecifiedPageNumber(PropertyMappingService property)
        {
            var parameters = new StudentParameters {
                PageSize = 2, PageNumber = 2
            };
            var sut = new StudentService(DbContextHelper.SeedRepo(property), new TypeHelperService(), new PropertyMappingService());

            var actual = sut.GetPagedList(parameters);

            Assert.Equal(2, actual.CurrentPage);
        }
        public void ReturnsCorrectQueryList(string searchQuery, int totalCount)
        {
            var parameters = new StudentParameters
            {
                SearchQuery = searchQuery,
            };
            var sut = new StudentService(DbContextHelper.SeedRepo(new PropertyMappingService()), new TypeHelperService(), new PropertyMappingService());

            var actual = sut.GetPagedList(parameters);

            Assert.Equal(totalCount, actual.TotalCount);
        }
        public void ReturnsCorrectOrderByTitle(PropertyMappingService property)
        {
            var parameters = new StudentParameters
            {
                OrderBy = "Name",
            };
            var sut = new StudentService(DbContextHelper.SeedRepo(property), new TypeHelperService(), new PropertyMappingService());

            var actual = sut.GetPagedList(parameters);

            Assert.Equal("Dummy", actual?[0]?.Name);
        }
        public void ReturnsCorrectTotalPages(int pageSize, int pageNumber, int totalPages, PropertyMappingService property)
        {
            var parameters = new StudentParameters
            {
                PageSize   = pageSize,
                PageNumber = pageNumber,
            };
            var sut = new StudentService(DbContextHelper.SeedRepo(property), new TypeHelperService(), new PropertyMappingService());

            var actual = sut.GetPagedList(parameters);

            Assert.Equal(totalPages, actual.TotalPages);
        }
 public object SetLiveUser([FromBody] StudentParameters objhome)
 {
     try
     {
         SetIsLiveForUser obj = new SetIsLiveForUser();
         var homemworkresult  = obj.UserLive(objhome);
         return(homemworkresult);
     }
     catch (Exception e)
     {
         return(new Error()
         {
             IsError = true, Message = e.Message
         });
     }
 }
Beispiel #10
0
        public IActionResult Get([FromQuery] StudentParameters parameters)
        {
            var students     = _studentService.GetStudents(parameters);
            var studentsList = _mapper.Map <List <StudentDetail> >(students);
            var metadata     = new
            {
                students.TotalCount,
                students.PageSize,
                students.CurrentPage,
                students.TotalPages,
                students.HasNext,
                students.HasPrevious
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));
            return(Ok(studentsList));
        }
Beispiel #11
0
        public IActionResult GetStudent(
            Guid id,
            StudentParameters parameters,
            [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!this.studentService.StudentPropertiesExists(parameters))
            {
                return(this.BadRequest());
            }

            var student = this.studentService.GetStudent(id);

            return(student == null
                ? this.NotFound()
                : (IActionResult)(mediaType == MediaType.OutputFormatterJson
                ? this.Ok(student.ShapeDataWithoutParameters(this.CreateLinksStudent))
                : this.Ok(this.mapper.Map <StudentDto>(student))));
        }
 public PagedList <Student> GetStudents(StudentParameters pagingParameter)
 {
     return(studentRepo.GetStudents(pagingParameter));
 }