コード例 #1
0
 public async Task <bool> SaveCourse(DtoCourse course)
 {
     try
     {
         using (var data = Context)
         {
             var c = await(from item in data.Courses where course.Id == item.id select item).FirstOrDefaultAsync();
             // Updating Course
             if (c != null)
             {
                 c.name      = course.Name;
                 c.startHour = course.StartHour;
                 c.day       = course.Day;
                 c.endHour   = course.EndHour;
                 c.limit     = course.Limit;
             }
             // Adding new Course
             else
             {
                 data.Courses.Add(CourseConverter.DtoToDataAccess(course));
             }
             await data.SaveChangesAsync();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #2
0
 public SectionService(IDataFacade facade)
 {
     _sectionConv = new SectionConverter();
     _crsConv     = new CourseConverter();
     _lesConv     = new LessonConverter();
     _facade      = facade;
 }
コード例 #3
0
        public async Task <DirectionDto> GetDirectionByIdAsync(Guid id)
        {
            DirectionDto direction = DirectionConverter.Convert(await _directionRepo.GetByIdAsync(id));

            direction.Administration = AdministrationConverter.Convert(await _adminRepo.GetByDirectionIdAsync(id));
            direction.Courses        = CourseConverter.Convert(await _courseRepo.GetByDirectionIdAsync(id));
            return(direction);
        }
コード例 #4
0
ファイル: CourseService.cs プロジェクト: mashtoe/elearner-api
 public CourseService(IDataFacade facade)
 {
     _crsConv      = new CourseConverter();
     _userConv     = new UserConverter();
     _secConverter = new SectionConverter();
     _catConv      = new CategoryConverter();
     _lesConv      = new LessonConverter();
     _facade       = facade;
 }
コード例 #5
0
        public async Task <CourseDto> GetCourseByIdAsync(Guid id)
        {
            CourseDto course = CourseConverter.Convert(await _courseRepo.GetByIdAsync(id));

            course.DirectionName = _directionRepo.GetByIdAsync(course.DirectionId).Result.Name;
            course.Groups        = GroupConverter.Convert(await _groupRepo.GetByCourseIdAsync(id));
            course.Pages         = PageConverter.Convert(await _pageRepo.GetByCourseIdAsync(id));
            return(course);
        }
コード例 #6
0
ファイル: CoursesController.cs プロジェクト: weedkiller/NINE
        public async Task <IHttpActionResult> GetCourse(Guid id)
        {
            if (!(await Db.Activities.FindAsync(id) is Course course))
            {
                return(NotFound());
            }

            var converter = new CourseConverter(Db);
            var dto       = converter.Convert(id);

            return(Ok(dto));
        }
コード例 #7
0
 public async Task <DtoCourse> GetCourse(int courseId)
 {
     try
     {
         using (var data = Context)
             return(CourseConverter.DataAccsessToDto(await(from item in data.Courses where item.id == courseId select item).FirstOrDefaultAsync()));
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #8
0
        public IActionResult Create(CourseModel courseModel)
        {
            if (!this._middleware.CheckUserPermission(PermissionType.Admin, HttpContext))
            {
                return(RedirectToAction("Login", "User"));
            }

            CourseConverter courseConverter = new CourseConverter();

            this._courseContainer.Save(courseConverter.ToCourse(courseModel));

            return(RedirectToAction("Index"));
        }
コード例 #9
0
ファイル: CalendarController.cs プロジェクト: weedkiller/NINE
        public IQueryable <CalendarDateDto> Day([FromBody] CalendarDayRequestModel model)
        {
            var converter   = new CourseConverter(Db);
            var userService = new UserInfoService();
            var user        = userService.GetUser(model.userid);

            var from  = model.date.Date;
            var until = from.AddDays(1);

            var list = new List <CalendarDateDto>();

            var allDates = Db.ActivityDates.Where(x =>
                                                  (x.Activity.Occurrence.Subscriptions.Any(s => !string.IsNullOrEmpty(s.UserId) && s.UserId.Equals(user.Id)) ||
                                                   x.Hosts.Any(m => !string.IsNullOrEmpty(m.UserId) && m.UserId.Equals(user.Id))
                                                  )
                                                  &&
                                                  x.Begin >= from && x.End <= until).ToList();


            foreach (var activityDate in allDates)
            {
                var calendarDate = new CalendarDateDto();

                calendarDate.Name      = activityDate.Activity.Name;
                calendarDate.ShortName = activityDate.Activity.ShortName;

                if (activityDate.Activity is Course)
                {
                    calendarDate.Type = CalendarDateType.Course;
                }
                if (activityDate.Activity is Event)
                {
                    calendarDate.Type = CalendarDateType.Event;
                }
                if (activityDate.Activity is OfficeHour)
                {
                    calendarDate.Type = CalendarDateType.OfficeHour;
                }

                calendarDate.Date = converter.ConvertDate(activityDate);

                // calendarDate.Subscription = converter.

                list.Add(calendarDate);
            }



            return(list.AsQueryable());
        }
コード例 #10
0
        public IActionResult Create()
        {
            if (!this._middleware.CheckUserPermission(PermissionType.User, HttpContext))
            {
                return(RedirectToAction("Login", "User"));
            }

            // return all sectors
            SectorConverter sectorConverter = new SectorConverter();

            ViewData["Sectors"] = sectorConverter.ToSectorModelList(this._sectorContainer.GetAll());

            // return all courses
            CourseConverter courseConverter = new CourseConverter();

            ViewData["Courses"] = courseConverter.ToCourseModelList(this._courseContainer.GetAll());

            return(View());
        }
コード例 #11
0
ファイル: CoursesController.cs プロジェクト: weedkiller/NINE
        public IQueryable <CourseDto> GetCourses(string organiser, string curriculum, string semester)
        {
            var list = new List <CourseDto>();

            var org = Db.Organisers.SingleOrDefault(x => x.ShortName.Equals(organiser));

            if (org == null)
            {
                return(list.AsQueryable());
            }

            var curr = org.Curricula.FirstOrDefault(x => x.ShortName.Equals(curriculum));

            if (curr == null)
            {
                return(list.AsQueryable());
            }

            var sem = Db.Semesters.SingleOrDefault(x => x.Name.Equals(semester));

            if (sem == null)
            {
                return(list.AsQueryable());
            }

            var allCourses = Db.Activities.OfType <Course>().Where(x =>
                                                                   x.SemesterGroups.Any(g =>
                                                                                        g.CapacityGroup.CurriculumGroup.Curriculum.Id == curr.Id &&
                                                                                        g.IsAvailable &&
                                                                                        g.Semester.Id == sem.Id)).ToList();

            var converter = new CourseConverter(Db);

            foreach (var course in allCourses)
            {
                list.Add(converter.Convert(course));
            }

            return(list.AsQueryable());
        }
コード例 #12
0
        public IActionResult Edit(int id)
        {
            if (!this._middleware.CheckUserPermission(PermissionType.User, HttpContext))
            {
                return(RedirectToAction("Login", "User"));
            }

            SectorConverter sectorConverter = new SectorConverter();

            ViewData["Sectors"] = sectorConverter.ToSectorModelList(this._sectorContainer.GetAll());

            CourseConverter courseConverter = new CourseConverter();

            ViewData["Courses"] = courseConverter.ToCourseModelList(this._courseContainer.GetAll());

            Book book = this._bookContainer.GetBookById(id);

            BookConverter bookConverter = new BookConverter();
            BookModel     bookModel     = bookConverter.ConvertBookToBookModel(book);

            return(View(bookModel));
        }
コード例 #13
0
        public async Task <ObservableCollection <DtoCourse> > GetCourses(string filter = null)
        {
            var ret = new ObservableCollection <DtoCourse>();

            using (var data = Context)
            {
                if (!string.IsNullOrWhiteSpace(filter))
                {
                    foreach (var item in await(from item in data.Courses where item.name.Contains(filter) select item).ToListAsync())
                    {
                        ret.Add(CourseConverter.DataAccsessToDto(item));
                    }
                }
                else
                {
                    foreach (var item in await(from item in data.Courses select item).ToListAsync())
                    {
                        ret.Add(CourseConverter.DataAccsessToDto(item));
                    }
                }
                return(ret);
            }
        }
コード例 #14
0
 public async Task <List <CourseDto> > GetAllCourseAsync()
 {
     return(CourseConverter.Convert(await _courseRepo.GetAllAsync()));
 }
コード例 #15
0
 public async Task <List <CourseDto> > GetCourseByDirectionIdAsync(Guid id)
 {
     return(CourseConverter.Convert(await _courseRepo.GetByDirectionIdAsync(id)));
 }
コード例 #16
0
 public async Task <CourseDto> CreateCourseAsync(CourseDto item)
 {
     return(CourseConverter.Convert(await _courseRepo.CreateAsync(CourseConverter.Convert(item))));
 }
コード例 #17
0
 public async Task <bool> UpdateCourseAsync(CourseDto item)
 {
     return(await _courseRepo.UpdateAsync(CourseConverter.Convert(item)));
 }
コード例 #18
0
 public void Setup()
 {
     _chapterConverter = new Mock <IChapterConverter>();
     _converter        = new CourseConverter(_chapterConverter.Object);
 }
コード例 #19
0
        public IQueryable <CourseSummaryDto> GetCourses(string semester)
        {
            var list = new List <CourseSummaryDto>();

            var sem = Db.Semesters.FirstOrDefault(x => x.Name.Equals(semester));

            if (sem == null)
            {
                return(list.AsQueryable());
            }

            var courses = Db.Activities.OfType <Course>().Where(x => x.SemesterGroups.Any(g =>
                                                                                          g.IsAvailable && g.Semester.Id == sem.Id && g.CapacityGroup.CurriculumGroup.Curriculum.ShortName.StartsWith("CIE"))).ToList();

            var converter = new CourseConverter(Db);

            foreach (var course in courses)
            {
                var summary = converter.ConvertSummary(course);

                converter.ConvertDates(summary, course);


                // Sonderlocken
                if (summary.IsCoterie)
                {
                    summary.Category = "Red";
                }
                else
                {
                    if (summary.HasHomeBias)
                    {
                        summary.Category = "Yellow";
                    }
                    else
                    {
                        summary.Category = "Green";
                    }
                }

                var isBachelor = course.SemesterGroups.Any(g =>
                                                           g.CapacityGroup.CurriculumGroup.Curriculum.ShortName.Equals("CIE-B"));

                var isMaster = course.SemesterGroups.Any(g =>
                                                         g.CapacityGroup.CurriculumGroup.Curriculum.ShortName.Equals("CIE-M"));

                if (isBachelor && isMaster)
                {
                    summary.Level = "Bachelor / Master";
                }
                else
                {
                    summary.Level = "none";

                    if (isBachelor)
                    {
                        summary.Level = "Bachelor";
                    }

                    if (isMaster)
                    {
                        summary.Level = "Master";
                    }
                }

                var group = course.SemesterGroups.FirstOrDefault(x =>
                                                                 x.CapacityGroup.CurriculumGroup.Curriculum.ShortName.StartsWith("CIE"));

                var org = group.CapacityGroup.CurriculumGroup.Curriculum.Organiser;

                summary.Department           = new OrganiserDto();
                summary.Department.Name      = org.Name;
                summary.Department.ShortName = org.ShortName;
                summary.Department.Color     = org.HtmlColor;


                summary.Sws       = 4;
                summary.Ects      = 5;
                summary.UsCredits = 4;


                list.Add(summary);
            }

            return(list.AsQueryable());
        }
コード例 #20
0
 public CourseBusiness(ICourseRepository courseRepository)
 {
     _courseRepository = courseRepository;
     _courseConverter  = new CourseConverter();
 }
コード例 #21
0
ファイル: UserService.cs プロジェクト: mashtoe/elearner-api
 public UserService(IDataFacade facade)
 {
     _userConv = new UserConverter();
     _crsConv  = new CourseConverter();
     _facade   = facade;
 }
コード例 #22
0
        public IQueryable <ActiveEvent> MyDay([FromBody] CalendarDayRequestModel model)
        {
            var converter   = new CourseConverter(Db);
            var userService = new UserInfoService();
            var user        = userService.GetUser(model.userid);

            var from  = model.date.Date;
            var until = from.AddDays(1);

            var list = new List <ActiveEvent>();

            var allDates = Db.ActivityDates.Where(x =>
                                                  (x.Activity.Occurrence.Subscriptions.Any(s => !string.IsNullOrEmpty(s.UserId) && s.UserId.Equals(user.Id)) ||
                                                   x.Hosts.Any(m => !string.IsNullOrEmpty(m.UserId) && m.UserId.Equals(user.Id))
                                                  )
                                                  &&
                                                  x.Begin >= from && x.End <= until).ToList();


            foreach (var activityDate in allDates)
            {
                var calendarDate = new ActiveEvent();

                calendarDate.course    = activityDate.Activity.Name;
                calendarDate.starttime = activityDate.Begin;
                calendarDate.endtime   = activityDate.End;

                var sb = new StringBuilder();
                foreach (var host in activityDate.Hosts)
                {
                    sb.Append(host.Name);
                    if (host != activityDate.Hosts.Last())
                    {
                        sb.Append(", ");
                    }
                }
                calendarDate.teacher = sb.ToString();
                sb.Clear();

                foreach (var room in activityDate.Rooms)
                {
                    sb.Append(room.Number);
                    if (room != activityDate.Rooms.Last())
                    {
                        sb.Append(", ");
                    }
                }
                calendarDate.room = sb.ToString();
                sb.Clear();

                foreach (var virtualRoom in activityDate.VirtualRooms)
                {
                    sb.Append(virtualRoom.Room.Name);
                    if (virtualRoom != activityDate.VirtualRooms.Last())
                    {
                        sb.Append(", ");
                    }
                }
                calendarDate.virtual_room = sb.ToString();
                sb.Clear();

                if (activityDate.Occurrence.IsCanceled)
                {
                    calendarDate.special = "X";
                }


                if (activityDate.Activity is Course course)
                {
                    calendarDate.moodle     = course.UrlMoodleCourse;
                    calendarDate.moodle_key = course.KeyMoodleCourse;
                }


                list.Add(calendarDate);
            }



            return(list.AsQueryable());
        }
コード例 #23
0
 public CategoryService(IDataFacade facade)
 {
     _categoryConv = new CategoryConverter();
     _crsConv      = new CourseConverter();
     _facade       = facade;
 }