// POST: api/CourseRegistration public IHttpActionResult Post([FromBody] CourseRegistrationModel value) { IEnumerable <dynamic> sections = db.Query("CourseSectionDetails").Where(new { CourseOfferedID = value.courseOfferedID }).Get(); dynamic section = sections.ToArray()[value.sectionID]; int fsID = (int)section.FSID; OfferedCourse course = db.Query("coursedetails").Where("CourseOfferedID", value.courseOfferedID) .First <OfferedCourse>(); IEnumerable <dynamic> records = db.Query("courseSectionsNum").Where("FSID", fsID).Get(); if (records.ToArray().Length >= course.maxStdPerSection) { return(BadRequest("Sections are full!")); } value.fsID = fsID; value.courseStatus = "ENROLLED"; int affected = db.Query("CourseEnrollment").Insert(new { courseStatus = value.courseStatus, fsID = value.fsID, courseID = value.courseOfferedID, studentID = value.studentID }); return(Ok(affected)); }
private void CreateNode(OfferedCourse item, Node rootNode) { //var rootNode = TreeView.FindNodeByName("Root"); var nodeCourse = rootNode.Nodes.Find(item.CourseClass.CourseCode, true)?.FirstOrDefault(); if (nodeCourse == null) { nodeCourse = new Node(string.Format("{0} [{1}]", item.CourseClass.Description, item.CourseClass.CourseCode)); //nodeCourse.Image = Properties.Resources.Briefcase_30; nodeCourse.Name = item.CourseClass.CourseCode; //if (UseSmallIcons) // nodeCourse.Image = Properties.Resources.Briefcase_16; nodeCourse.Expanded = true; rootNode.Nodes.Add(nodeCourse); } var node = new Node { Text = "Year " + item.YearLevel }; node.Name = item.Id.ToString(); node.Tag = item; UpdateNode(node); nodeCourse.Nodes.Add(node); }
public void LoadItems(OfferedCourse item) { OfferedCourseItem = item; OfferedCourseItem.Sections.LoadItemsFromDb(); ShowItems(); }
private async void btnAllRowsRed_Click(object sender, RoutedEventArgs e) { if (!allowUserInteraction) return; allowUserInteraction = false; int offeredCoursesId = int.Parse(selectedButton.Name.Substring(3)); OfferedCourse offeredCourse = offeredCourses[offeredCoursesId]; //validation bool output = await IsValidAsync(offeredCourse, ReductionStepAction.RED_ALL_COURSES_ROWS); if (!output) { allowUserInteraction = true; return; } foreach (var row in offeredCourse.OfferedCourseRows) { if (row.Color != ReductionStep2ColorStatus.RED) { SetCardBackgroundColor(cards[row.RowId], ReductionStep2ColorStatus.RED); row.Color = ReductionStep2ColorStatus.RED; } } allowUserInteraction = true; }
public ActionResult OfferACourse([Bind(Include = "CourseCategoryID,OfferedByID,CourseCode,CourseTitle,CreditHours,StartingDate,FinishDate")] OfferedCourse offeredCourse) { if (ModelState.IsValid) { object username = Session["username"]; if (username != null) { var user = _db.Users.Where(x => x.Username == username.ToString()).FirstOrDefault(); if (user != null) { var cr = Request.Form["Course.CourseCode"]; var course = _db.OfferedCourses.Where(s => s.OfferdBy.Username == user.Username && s.FinishDate >= DateTime.Now && s.Course.CourseCode.Equals(cr, StringComparison.CurrentCultureIgnoreCase)).Select(s => s.Course).FirstOrDefault(); var c = _db.Courses.Where(s => s.CourseCode.Equals(cr, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); var cc = int.Parse(Request.Form["Course.CourseCategoryID"]); var category = _db.CourseCategories.Where(x => x.CourseCategoryID == cc).FirstOrDefault(); //if new course if (course == null) { if (c == null) { course = new Course { CourseCategory = category, CourseCategoryID = category.CourseCategoryID, CourseCode = cr, CourseTitle = Request.Form["Course.CourseTitle"] }; c = course; _db.Courses.Add(course); } offeredCourse.Course = c; offeredCourse.OfferdBy = user; offeredCourse.OfferedByID = user.Username; offeredCourse.LearnerCount = 0; _db.OfferedCourses.Add(offeredCourse); _db.SaveChanges(); ViewBag.courseCategories = new SelectList(_db.CourseCategories, "CourseCategoryID", "CategoryName"); ViewBag.instructor = _db.Users.Where(x => x.Type == "instructor").Select(y => y.Username).FirstOrDefault(); ViewBag.msg = "Successfully Offered said course"; return(OfferACourse()); } ViewBag.msg = "You have already Offered said course"; ViewBag.courseCategories = new SelectList(_db.CourseCategories, "CourseCategoryID", "CategoryName"); ViewBag.instructor = _db.Users.Where(x => x.Type == "instructor").Select(y => y.Username).FirstOrDefault(); return(View()); } return(RedirectToAction("Index")); } } //write something in temp message "please login first." return(RedirectToAction("Index", "Default")); }
public List <OfferedCourse> GetSuggestedCourses(String Username) { List <OfferedCourse> SuggestedCourses = new List <OfferedCourse>(); List <LearnerEnroll> enrolls = _db.LearnerEnrollments.Where(s => s.EnrolledLearnerID == Username.ToString()).ToList(); List <int> enrolledCourses = new List <int>(); foreach (LearnerEnroll le in enrolls) { enrolledCourses.Add(le.EnrolledCourseID); } var rules = _db.Rules.OrderByDescending(s => s.Confidence).ToList(); foreach (Rule r in rules) { List <int> Drivers = JsonConvert.DeserializeObject <List <int> >(r.Drivers); var firstNotSecond = enrolledCourses.Except(Drivers).ToList(); var secondNotFirst = Drivers.Except(enrolledCourses).ToList(); if (!firstNotSecond.Any() && !secondNotFirst.Any()) { List <int> Indicates = JsonConvert.DeserializeObject <List <int> >(r.Indicates); foreach (int i in Indicates) { OfferedCourse oc = _db.OfferedCourses.Where(s => s.OfferedCourseID == i).FirstOrDefault(); if (oc.FinishDate >= DateTime.Now) { SuggestedCourses.Add(oc); } } } } //if (SuggestedCourses.Count < count) //{ // int remaining = count - SuggestedCourses.Count; // var allOfferedCourses = _db.OfferedCourses.Where(s => s.FinishDate >= DateTime.Now).OrderByDescending(d => d.LearnerCount).ToList(); // int total = allOfferedCourses.Count; // int i = 0; // while(remaining>0 && i<total) // { // OfferedCourse ocTemp = allOfferedCourses.ElementAt(i); // if(SuggestedCourses.Where(c=>c.OfferedCourseID == ocTemp.OfferedCourseID).FirstOrDefault()==null && !enrolledCourses.Contains(ocTemp.OfferedCourseID)) // { // remaining--; // SuggestedCourses.Add(ocTemp); // } // i++; // } //} return(SuggestedCourses); }
private void OfferedCourseViewer_ItemSelected(object sender, OfferedCourse e) { Cursor.Current = Cursors.WaitCursor; SectionViewer.Clear(); if (e == null) { return; } SectionViewer.LoadItems(e); }
private void btnSearch_Click(object sender, EventArgs e) { DAL.OfferedCourse ofc = new OfferedCourse(); if (txtSearch.Text.Trim() == "") { MessageBox.Show("Search by Id"); return; } //ofc.Id = Convert.ToInt32(txtSearch.Text); dgbOfferedCourse.DataSource = ofc.SelectById(); }
public static Box CreateBoxForOfferedCourse(OfferedCourse offeredCourse) { Box box = new Box(); offeredCourse.OfferedCourseRows.ForEach(r => { if (r.Color == ReductionStep2ColorStatus.WHITE) { Row row = new Row(); row.Columns.Add(r); box.Rows.Add(row); } }); return(box); }
private void btnDelete_Click(object sender, EventArgs e) { // MessageBox.Show("Are you sure you want to delete ?","",) // want to pop up message before delete DAL.OfferedCourse ofc = new OfferedCourse(); //ofc.Id = selectedRowId; if (ofc.Delete()) { MessageBox.Show("Recored successfully deleted !"); } else { MessageBox.Show(ofc.Error); } }
private async Task FillRowsOfCourseGraphicallyAsync(StackPanel uiElement, OfferedCourse offeredCourse) { uiElement.Children.Clear(); await Task.Run(async () => { foreach (var row in offeredCourse.OfferedCourseRows) { await Dispatcher.InvokeAsync(() => { cards[row.RowId] = AddNewRowToStackPanel(uiElement, row.RowId.ToString(), row.ProfessorName, row.RemainedCapacity.ToString(), row.TimeAndSiteAndExamRawString, row.Description, offeredCourse.CourseId.ToString(), row.Color); }); } }); }
private OfferedCourse OnAdd() { var newItem = new OfferedCourse(); newItem.BatchId = SelectedBatch.Id; newItem.BatchClass = SelectedBatch; using (var frm = new frmOfferedCourse_Add()) { frm.ItemData = newItem; if (frm.ShowDialog() != DialogResult.OK) { return(null); } } return(newItem); }
private void OnDelete(OfferedCourse item, out string deleteMessage, ref Action <OfferedCourse> afterConfirm) { deleteMessage = item.CourseClass.CourseCode + " - " + item.YearLevel.ToString(); afterConfirm = currentItem => { try { currentItem.RowStatus = RecordStatus.DeletedRecord; //Save to Database var dataWriter = new OfferedCourseDataWriter(App.CurrentUser.User.Username, currentItem); dataWriter.SaveChanges(); } catch (Exception ex) { MessageDialog.ShowError(ex, this); } }; }
//navigate to another course private async void btnCourseNavigation_Click(object sender, RoutedEventArgs e) { if (!allowUserInteraction) return; allowUserInteraction = false; Button btn = (Button)sender; selectedButton.Background = Brushes.White; selectedButton = btn; selectedButton.SetResourceReference(Button.BackgroundProperty, "PrimaryHueMidBrush"); int offeredCoursesId = int.Parse(btn.Name.Substring(3)); OfferedCourse offeredCourse = offeredCourses[offeredCoursesId]; SetButtonBackgroundColor(btnMustBeTake, offeredCourse.Color); await FillRowsOfCourseGraphicallyAsync(stackPanelCenterContent, offeredCourse); allowUserInteraction = true; }
public void btnLoad_Click(object sender, EventArgs e) { OfferedCourse offeredcourse = new OfferedCourse(); dgbOfferedCourse.DataSource = offeredcourse.Select().Tables[0]; }
private Task<bool> IsValidAsync(OfferedCourse offeredCourse, ReductionStepAction action, OfferedCourseRow offeredCourseRow = null) { return Task.Run<bool>(() => IsValid(offeredCourse, action, offeredCourseRow)); }
private bool IsValid(OfferedCourse offeredCourse, ReductionStepAction action, OfferedCourseRow offeredCourseRow = null) { if (action == ReductionStepAction.WHITE_ONE_RED_ROW) { return true; } else if (action == ReductionStepAction.WHITE_ALL_COURSES_ROWS) { return true; } else if (action == ReductionStepAction.RED_ALL_COURSES_ROWS) { if (offeredCourse.Color == ReductionStep2ColorStatus.Green) { return false; } else if (offeredCourse.Color == ReductionStep2ColorStatus.WHITE) { return true; } else throw new Exception(); } else if (action == ReductionStepAction.UNCHECK_COURSE_MUST_BE_TAKE) { List<int> lst = new List<int>(); foreach (var o in greenCourses) if (o != offeredCourse) lst.Add(o.Course.Id); //is valid state must be checked return MainCurriculumSateValidator.IsValidState(mainCurriculum, lst); } else if (action == ReductionStepAction.RED_ONE_WHITE_ROW) { if (offeredCourse.Color == ReductionStep2ColorStatus.WHITE) { return true; } else if (offeredCourse.Color == ReductionStep2ColorStatus.Green) { //temorary change the actual current value offeredCourseRow.Color = ReductionStep2ColorStatus.RED; List<Box> boxes = new List<Box> { ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(offeredCourse) }; //restore actual value offeredCourseRow.Color = ReductionStep2ColorStatus.WHITE; foreach (var item in greenCourses) { if (item != offeredCourse) boxes.Add(ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(item)); } List<Box> res = null; var task = Task.Run(() => ReductionStep2ServiceProvider.Validate(boxes, exampCollideChecking)); if (task.Wait(TimeSpan.FromMilliseconds(timeoutMs))) res = task.Result; else { res = null; } if (res == null) return false; return true; } else throw new Exception(); } else if (action == ReductionStepAction.CHECK_COURSE_MUST_BE_TAKE) { if (offeredCourse.Course.Units + currentMustUnits > maxUnits) { return false; } List<int> lst = new List<int>(); foreach (var o in greenCourses) lst.Add(o.Course.Id); lst.Add(offeredCourse.Course.Id); //is valid state must be checked bool output = MainCurriculumSateValidator.IsValidState(mainCurriculum, lst); if (!output) return false; output = false; for (int a = 0; a < offeredCourse.OfferedCourseRows.Count; a++) { if (offeredCourse.OfferedCourseRows[a].Color == ReductionStep2ColorStatus.WHITE) { output = true; break; } } if (!output) return false; Box b1 = ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(offeredCourse); List<Box> boxes = new List<Box> { b1 }; foreach (var item in greenCourses) { boxes.Add(ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(item)); } List<Box> res = null; var task = Task.Run(() => ReductionStep2ServiceProvider.Validate(boxes, exampCollideChecking)); if (task.Wait(TimeSpan.FromMilliseconds(timeoutMs))) res = task.Result; else { res = null; } if (res == null) return false; return true; } throw new Exception(); //return false; }
// GET: api/Course/5 public IHttpActionResult Get(int id) { OfferedCourse course = db.Query("coursedetails").Where("CourseOfferedID", id).First <OfferedCourse>(); return(Ok(course)); }
protected virtual void OnItemSelected(OfferedCourse item) { ItemSelected?.Invoke(this, item); }
public async Task RunAfterCreatedAsync() { try { await Task.Run(async () => { await Dispatcher.InvokeAsync(() => { InitializeComponent(); }); //settings if (Properties.Settings.Default.CurrentTermNumber > 0) termNumber = Properties.Settings.Default.CurrentTermNumber; gender = Properties.Settings.Default.Gender == 'm' ? Tataiee.Harif.Infrastructures.GeneralEnums.Gender.MALE : Tataiee.Harif.Infrastructures.GeneralEnums.Gender.FEMALE; if (Properties.Settings.Default.MinUnits > 0) minUnits = Properties.Settings.Default.MinUnits; if (Properties.Settings.Default.MinUnits <= Properties.Settings.Default.MaxUnits && Properties.Settings.Default.MaxUnits > 0) maxUnits = Properties.Settings.Default.MaxUnits; if (Properties.Settings.Default.TimeoutForReductionStep2ms >= 120) timeoutMs = Properties.Settings.Default.TimeoutForReductionStep2ms; if (Properties.Settings.Default.MaxNumberOfSuggestedWeeklyProgram >= 1 && Properties.Settings.Default.MaxNumberOfSuggestedWeeklyProgram <= 50) maxCntSuggestion = Properties.Settings.Default.MaxNumberOfSuggestedWeeklyProgram; capacityFiltering = Properties.Settings.Default.CapacityFiltering; exampCollideChecking = Properties.Settings.Default.ExamCollideChecking; //end settings mainCurriculum = StudentHistoryServiceProvider.CreateNewCurriculmWithSpecificCreditAndFilledBySpecificCourseInforamtion(DirectoryManager.EssentialInforamtion1Directory + DirectoryManager.CreditDeterminerSavedName, DirectoryManager.EssentialInforamtion1Directory + DirectoryManager.CourseInformationSavedName); int CODE_LEN = 7; //load offered course row in memory FileServiceProvider.DeserializeFromXmlFile(DirectoryManager.GoalVersionOfferedCoursesRowDirectory + DirectoryManager.GoalVersionOfferedCoursesRowSavedName, out List<GoalVersionOfferedCoursesRow> goalVersionOfferedCourseRows); //perform reduction step 1 and get courses list after reduced var coursesListAfterReductionStep1 = ReductionStep1.Reduce(DirectoryManager.EssentialInforamtion1Directory + DirectoryManager.CreditDeterminerSavedName, DirectoryManager.EssentialInforamtion1Directory + DirectoryManager.CourseInformationSavedName , termNumber); //assign offeredCourseRows to the output of ReductionStep2 courses List if (capacityFiltering) { goalVersionOfferedCourseRows = ReductionStep2.Reduce(coursesListAfterReductionStep1, goalVersionOfferedCourseRows, gender) .Where(r => r.Capacity - r.Registered > 0).ToList(); } else { goalVersionOfferedCourseRows = ReductionStep2.Reduce(coursesListAfterReductionStep1, goalVersionOfferedCourseRows, gender); } CODE_LEN = coursesListAfterReductionStep1[0].CodeInDesUni.Length; //again group reduced offered course rows var coursesGroups = (from c in goalVersionOfferedCourseRows group c by c.Id.Substring(0, CODE_LEN)).ToList(); //-------- //we can add another reduction step to reduce more if possible but not now. //--------- //fill main offeredCourses and offeredCourseRows lists int i = 0; int j = 0; foreach (var course in coursesGroups) { var c = coursesListAfterReductionStep1.FirstOrDefault(c1 => c1.CodeInDesUni == course.Key); if (c != null) { OfferedCourse oc = new OfferedCourse(c, i++, ReductionStep2ColorStatus.WHITE); foreach (var row in course) { OfferedCourseRow ocr = new OfferedCourseRow(row, ReductionStep2ColorStatus.WHITE, j++, oc); oc.OfferedCourseRows.Add(ocr); cards.Add(null); offeredCourseRows.Add(ocr); } offeredCourses.Add(oc); } } if (Properties.Settings.Default.ReductionStep2MustBeLoad) { FileServiceProvider.DeserializeFromXmlFile(DirectoryManager.ReductionStep2SavedStatus + DirectoryManager.SaveColorOfferedCourses, out List<SaveColorObjectModel> saveColorOfferedCourses); FileServiceProvider.DeserializeFromXmlFile(DirectoryManager.ReductionStep2SavedStatus + DirectoryManager.SaveColorOfferedCourseRows, out List<SaveColorObjectModel> saveColorOfferedCourseRows); saveColorOfferedCourses.ForEach(scoc => { offeredCourses[scoc.CorrespondingIdInSourceList].Color = scoc.Color; }); saveColorOfferedCourseRows.ForEach(scocr => { offeredCourseRows[scocr.CorrespondingIdInSourceList].Color = scocr.Color; }); } //create and fill courses navigation buttons in the right side await Dispatcher.InvokeAsync(() => { stackPanelRightSide.Children.Clear(); Button button1 = null; for (int m = 0; m < offeredCourses.Count; m++) { Badged badged = new Badged { Badge = offeredCourses[m].OfferedCourseCode, Margin = new Thickness(5), Name = "bdg" + offeredCourses[m].CourseId }; Button button = new Button { Content = new TextBlock() { Text = offeredCourses[m].OfferedCourseName, TextAlignment = TextAlignment.Center, TextWrapping = TextWrapping.Wrap }, Name = "btn" + m.ToString(), Width = 250, Height = Double.NaN, Padding = new Thickness(5), Background = Brushes.Transparent }; button.Click += btnCourseNavigation_Click; badged.Content = button; if (m == 0) { button1 = button; } stackPanelRightSide.Children.Add(badged); } selectedButton = button1; allowUserInteraction = true; btnCourseNavigation_Click(button1, null); }); }); } catch { } }