/// <summary>
        /// 命令执行
        /// </summary>
        /// <param name="context"></param>
        public override void Execute(DataContext context)
        {
            byte[] cmdData = context.CmdData;
            if (cmdData.Length == 0)
            {
                context.Flush(RespondCode.CmdDataLack);
                return;
            }

            CourseQuery query = cmdData.ProtoBufDeserialize <CourseQuery>();

            if (Compiled.Debug)
            {
                query.Debug("=== School.QueryCourses 请求数据 ===");
            }

            UserCacheInfo userCache = UserBiz.ReadUserCacheInfo(context.UserId);

            if (userCache.UserSite > 0)
            {
                PageResult <CourseBase> pageResult = SchoolBiz.GetSchoolCoursePageList(userCache.UserSite, query.QueryIndex, query.QuerySize);
                CourseList result = new CourseList
                {
                    RecordCount = pageResult.RecordCount,
                    QueryIndex  = pageResult.PageIndex,
                    QuerySize   = pageResult.PageSize,
                    IndexCount  = pageResult.PageCount,
                    DataList    = pageResult.Data.Select(c => c.ToCourseInfo()).ToList()
                };
                context.Flush <CourseList>(result);
                return;
            }

            context.Flush(RespondCode.DataInvalid);
        }
Beispiel #2
0
        public QueryResponse DoSearch(CourseQuery query)
        {
            //create response
            QueryResponse queryResponse = new QueryResponse();

            //save query
            queryResponse.OriginalQuery = query;

            //get solr
            ISolrOperations <Course> solr = _connection.GetSolrInstance();

            //query
            QueryOptions options = new QueryOptions()
            {
                Rows          = query.Rows,
                StartOrCursor = new StartOrCursor.Start(query.Start),
                Highlight     = Highlights.BuildParameters()
            };

            //execute the query
            ISolrQuery solrQuery = new SolrQuery(query.Query);
            SolrQueryResults <Course> solrResult = solr.Query(solrQuery, options);

            //Set response
            ResponseExtraction responseExtractions = new ResponseExtraction();

            responseExtractions.SetHeader(queryResponse, solrResult);
            responseExtractions.SetBody(queryResponse, solrResult);

            return(queryResponse);
        }
 public IPagedList <CourseInfo> GetCourseList(CourseQuery query)
 {
     if (query.SearchDate.HasValue)
     {
         var searchDate  = Convert.ToDateTime(query.SearchDate.Value.Date.ToString());
         var lsearchDate = searchDate.AddDays(1).AddSeconds(-1);
         return(_courseInfoRep.GetMany(x => (x.CourseBeginTime >= searchDate && x.CourseBeginTime <= lsearchDate)).AsPagedList(query));
     }
     return(_courseInfoRep.GetAllList().AsPagedList(query));
 }
        public async Task Handle_WhenCourseDoesNotExistsReturnNull()
        {
            var courseQuery = new CourseQuery(Guid.NewGuid());

            CourseRepository.Setup(ur => ur.GetByCourseIdAsync(courseQuery.CourseId)).Returns(Task.FromResult <Course>(null));

            var course = await CourseQueryHandler.Handle(courseQuery, CancellationToken.None);

            course.Should().BeNull();
        }
Beispiel #5
0
        public async Task GetByCourseId_WhenCourseDoesNotExists_ReturnNotFound()
        {
            var courseQuery = new CourseQuery(Guid.NewGuid());

            Mediator.Setup(m => m.Send(courseQuery, CancellationToken.None))
            .Returns(Task.FromResult <Course>(null));

            var result = await CoursesController.GetByCourseIdAsync(courseQuery.CourseId);

            result.Should().BeOfType <NotFoundResult>();
        }
Beispiel #6
0
        public Message RegisterStudentToCourse(StudentIdCourseId studentIdCourseId)
        {
            Message msg = new Message();

            CourseQuery courseQuery = new CourseQuery();
            StudentCourseCollegeQuery studentCourseCollegeQuery = new StudentCourseCollegeQuery();
            StudentQuery studentQuery = new StudentQuery();


            if (query.IsStudentRegisteredtoCourse(context, studentIdCourseId.StudentId, studentIdCourseId.CourseId))
            {
                msg.status  = false;
                msg.message = "Student is already registered to the course";
            }
            else if (!query.StudentExists(context, studentIdCourseId.StudentId) ||
                     !courseQuery.courseExistsOnId(context, studentIdCourseId.CourseId))
            {
                msg.status  = false;
                msg.message = "The Student/Course is not registered";
            }


            var college = AllotCollege(studentIdCourseId);

            if (college == null)
            {
                msg.status  = false;
                msg.message = "No colleges currently offer this course";
            }

            StudentCourseCollege studentCourseCollege = new StudentCourseCollege()
            {
                CollegeId = college.Id,
                StudentId = studentIdCourseId.StudentId,
                CourseId  = studentIdCourseId.CourseId,
            };

            try
            {
                studentCourseCollegeQuery.RegisterStudentToCourseAndCollege(context, studentCourseCollege);
                var course = courseQuery.GetCourseById(context, studentIdCourseId.CourseId);
                msg.status  = true;
                msg.message = $"Alloted College: {college.Name} (Id : {college.Id})\n for Course : {course.courseName} (id : {course.Id})";
            }
            catch (Exception e)
            {
                msg.status  = false;
                msg.message = $"Internal Error : {e.Message}";
            }

            return(msg);
        }
Beispiel #7
0
        public async Task <QueryResult <Course> > GetCourses(CourseQuery queryObj)
        {
            var result = new QueryResult <Course>();
            var query  = SchedulingDbContext.Courses
                         .Include(c => c.Curriculum)
                         .AsQueryable();

            query = query.ApplyCourseFiltering(queryObj);

            result.TotalItems = await query.CountAsync();

            result.Items = await query.ToListAsync();

            return(result);
        }
Beispiel #8
0
        public IEnumerable <CourseDTO> GetAll(CourseQuery dto)
        {
            IEnumerable <string> tags = dto.Tags != null && dto.Tags.Length > 0
                ? dto.Tags.Split(",")
                : new List <string>(0).AsEnumerable();

            IQueryable <Course> courses = GetAll()
                                          .GetByName(dto.Name)
                                          .GetByDatesRange(dto.StartDate, dto.EndDate)
                                          .GetByCreditsRange(dto.CreditsFrom, dto.CreditsEnd)
                                          .GetByTags(tags)
                                          .Pagination(dto.Page, dto.PageSize);

            return(_Mapper.Map <IEnumerable <Course>, IEnumerable <CourseDTO> >(courses.ToList()));
        }
Beispiel #9
0
        public ActionResult Index(string searchText)
        {
            //SolrHelper.ReIndexAllCourses();
            ViewBag.SearchText = searchText;


            CourseSearch search = new CourseSearch();

            CourseQuery query = new CourseQuery();

            query.Query = searchText;

            var model = search.DoSearch(query);

            return(View(model));
        }
        public IActionResult GetAllCourses([FromQuery] CourseQuery filtersDto)
        {
            return(this.Ok(() =>
            {
                IEnumerable <CourseDTO> data = _CourseRepo.GetAll(filtersDto);
                filtersDto.PageSize = filtersDto.PageSize <= 0 ? 50 : filtersDto.PageSize;
                filtersDto.Page = filtersDto.Page <= 0 ? 1 : filtersDto.Page;
                JObject json = new JObject()
                {
                    ["filters"] = filtersDto.ToJson(),
                    ["results"] = data.ToJsonArray(),
                };

                return json;
            }, _Logger));
        }
Beispiel #11
0
        public async Task GetByCourseId_WhenCourseExists_ReturnCourse()
        {
            var course = new Course(Guid.NewGuid(), "Mathematics");

            var courseQuery = new CourseQuery(course.Id);

            Mediator.Setup(m => m.Send(courseQuery, CancellationToken.None))
            .Returns(Task.FromResult(course));

            var result = await CoursesController.GetByCourseIdAsync(course.Id);

            result.Should().BeOfType <OkObjectResult>();

            var courseDto = (result as OkObjectResult).Value as CourseDto;

            courseDto.Id.Should().Be(course.Id.ToString());
            courseDto.Name.Should().Be(course.Name.ToString());
        }
Beispiel #12
0
        public async Task <List <CourseQueryModel> > HandleAsync(CourseQuery query)
        {
            var courses = await _context
                          .Course
                          .Include(t => t.UserCoursePrivilege)
                          .Where(query.Specification.Predicate)
                          .Select(t => new CourseQueryModel
            {
                Id               = t.Id,
                Name             = t.Name,
                Ects             = t.Ects,
                Subscribed       = t.Subscription.Any(x => x.UserId == query.Specification.UserId),
                SpecializationId = t.SpecializationId,
                IsInvolved       = t.UserCoursePrivilege.Any(x => x.UserId == query.Specification.UserId && x.PrivilegeId == (int)PrivilegeEnum.IsInvolvedWithCourse)
            })
                          .ToListAsync();

            return(courses);
        }
Beispiel #13
0
        // GET: Course
        public ActionResult Index(CourseQuery query)
        {
            var items = _courseSrv.GetCourseList(query);

            return(View(items));
        }
Beispiel #14
0
 public CourseService(AppDbContext _context)
 {
     context = _context;
     query   = new CourseQuery();
 }
        public List <CourseQuery> GetAllCourse()
        {
            try
            {
                string connectionString = ("Server=127.0.0.1;uid=root;Database=doulingo_stories;pwd=123456");
                string commandText      = @"SELECT course.id, course.name, l1.short AS fromLanguage, l1.name AS fromLanguageName, l2.short AS learningLanguage, l2.name AS learningLanguageName, COUNT(story.id) count, course.public, course.official FROM course
LEFT JOIN language l1 ON l1.id = course.fromLanguage
LEFT JOIN language l2 ON l2.id = course.learningLanguage
LEFT JOIN story ON(story.lang = course.learningLanguage AND story.lang_base = course.fromLanguage)
GROUP BY course.id";
                using (MySqlConnection conn = new MySqlConnection(connectionString))
                {
                    //using (SqlCommand cmd = new  SqlCommand(commandText, conn))
                    //{
                    conn.Open();
                    MySqlCommand cmd = new MySqlCommand(commandText, conn);
                    cmd.ExecuteNonQuery();
                    using (var result = cmd.ExecuteReader())
                    {
                        // do something with result
                    }
                    List <List <object> > items = new List <List <object> >();
                    List <CourseQuery>    li    = new List <CourseQuery>();
                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var item = new List <object>();

                        items.Add(item);

                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            item.Add(reader[i]);
                        }
                        CourseQuery l = new CourseQuery()
                        {
                            id                   = (int)item[0],
                            name                 = item[1].ToString(),
                            fromLanguage         = item[2].ToString(),
                            fromLanguageName     = item[3].ToString(),
                            learningLanguage     = item[4].ToString(),
                            learningLanguageName = item[5].ToString(),
                            count                = (long)item[6],
                            Public               = (int)item[7],
                            official             = (int)item[8],
                        };
                        li.Add(l);
                    }


                    conn.Close();
                    // }
                    return(li);
                }


                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(null);
        }
        public static IQueryable <Course> ApplyCourseFiltering(this IQueryable <Course> query, CourseQuery queryObj)
        {
            if (queryObj.DepartmentId.HasValue)
            {
                query = query.Where(c => c.Curriculum.DepartmentId == queryObj.DepartmentId);
            }

            return(query);
        }