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); } }
public SectionService(IDataFacade facade) { _sectionConv = new SectionConverter(); _crsConv = new CourseConverter(); _lesConv = new LessonConverter(); _facade = facade; }
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); }
public CourseService(IDataFacade facade) { _crsConv = new CourseConverter(); _userConv = new UserConverter(); _secConverter = new SectionConverter(); _catConv = new CategoryConverter(); _lesConv = new LessonConverter(); _facade = facade; }
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); }
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)); }
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); } }
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")); }
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()); }
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()); }
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()); }
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)); }
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); } }
public async Task <List <CourseDto> > GetAllCourseAsync() { return(CourseConverter.Convert(await _courseRepo.GetAllAsync())); }
public async Task <List <CourseDto> > GetCourseByDirectionIdAsync(Guid id) { return(CourseConverter.Convert(await _courseRepo.GetByDirectionIdAsync(id))); }
public async Task <CourseDto> CreateCourseAsync(CourseDto item) { return(CourseConverter.Convert(await _courseRepo.CreateAsync(CourseConverter.Convert(item)))); }
public async Task <bool> UpdateCourseAsync(CourseDto item) { return(await _courseRepo.UpdateAsync(CourseConverter.Convert(item))); }
public void Setup() { _chapterConverter = new Mock <IChapterConverter>(); _converter = new CourseConverter(_chapterConverter.Object); }
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()); }
public CourseBusiness(ICourseRepository courseRepository) { _courseRepository = courseRepository; _courseConverter = new CourseConverter(); }
public UserService(IDataFacade facade) { _userConv = new UserConverter(); _crsConv = new CourseConverter(); _facade = facade; }
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()); }
public CategoryService(IDataFacade facade) { _categoryConv = new CategoryConverter(); _crsConv = new CourseConverter(); _facade = facade; }