public ActionResult ShowArea() { //string userId1 = User.Identity.GetUserId(); //PersonalArea area1 = db.PersonalAreas.Where(a => a.AspNetUserId.CompareTo(userId1) == 0).First(); //db.PersonalAreas.Remove(area1); //db.SaveChanges(); //return RedirectToAction("Index"); if (User.Identity.IsAuthenticated) { ViewBag.teacher = false; if (User.IsInRole("teacher")) { PersonalArea areaTeacher = new PersonalArea() { AspNetUserId = User.Identity.GetUserId(), Person = User.Identity.Name }; ViewBag.teacher = true; return(View(areaTeacher)); } string userId = User.Identity.GetUserId(); PersonalArea area = db.PersonalAreas.Where(a => a.AspNetUserId.CompareTo(userId) == 0).First(); CoursesInAreaModel coursesModel = MakeCoursesModel(area); ViewBag.coursesModel = coursesModel; List <KeyValuePair <int, int> > redGreen = new List <KeyValuePair <int, int> >(); foreach (var course in area.Courses) { StudyViewModel studyModel = GetNextParagraph(area, course.Id); redGreen.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse)); } ViewBag.RedGreen = redGreen; return(View(area)); } return(RedirectToAction("Index")); }
public ActionResult DeleteCourseFromPersonalArea(int courseId) { string userId = User.Identity.GetUserId(); PersonalArea area = db.PersonalAreas.Where(p => p.AspNetUserId.CompareTo(userId) == 0).First(); // area.Courses.Remove(db.Courses.Find(courseId)); // CourseStructure corStr = area.CourseStructures.Where(c => c.IdCourse == courseId).First(); area.CourseStructures.Remove(area.CourseStructures.Where(c => c.IdCourse == courseId).First()); db.CourseStructures.Remove(corStr); area.Courses.Remove(db.Courses.Find(courseId)); db.Entry(area).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); CoursesInAreaModel coursesModel = MakeCoursesModel(area); ViewBag.coursesModel = coursesModel; List <KeyValuePair <int, int> > redGreen = new List <KeyValuePair <int, int> >(); foreach (var course in area.Courses) { StudyViewModel studyModel = GetNextParagraph(area, course.Id); redGreen.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse)); } ViewBag.RedGreen = redGreen; return(View(area)); }
// GET: Note/Study/5 public ActionResult Study(int?id, string returnUrl) { var user = db.GetUserByID(GetUserId()); Note note = db.GetNoteByID(id); if (note == null) { return(HttpNotFound()); } var model = new StudyViewModel { Id = note.Id, Title = note.Title, IntervalInDays = note.IntervalInDays, DueDate = note.DueDate.ToLocalTime(user), FirstStudiedDate = note.FirstStudiedDate.ToLocalTime(user), Notebook = note.Notebook, TimeEstimate = note.TimeEstimate, Reviews = note.Reviews.ToList(), IntervalHard = note.IntervalHard(), IntervalGood = note.IntervalGood(), IntervalEasy = note.IntervalEasy(), ReturnUrl = returnUrl }; return(View(model)); }
public IHttpActionResult UpdateProject(StudyViewModel model, string id) { if (String.IsNullOrEmpty(id)) { return(BadRequest("Empty id")); } if (!ModelState.IsValid) { return(BadRequest("Not a valid data")); } var studyProject = StudyManager.Instance.GetStudyProject(id); if (studyProject == null) { return(NotFound()); } var study = StudyManager.Instance.GetStudy(studyProject, model.TreeId); if (study == null) { return(NotFound()); } int studyYear; string trimmedStudyYear = model.Column; trimmedStudyYear = trimmedStudyYear.Replace("class_", String.Empty); if (!int.TryParse(trimmedStudyYear, out studyYear)) { return(BadRequest("Study year is not numeric")); } int creditPoints; string creditPointsText = model.Value; creditPointsText = String.IsNullOrEmpty(creditPointsText) ? "0" : creditPointsText; if (!int.TryParse(creditPointsText, out creditPoints)) { return(BadRequest("Credit points are not numeric")); } if (studyYear >= 0 && studyYear <= 2) { study.CreditPoints[studyYear] = creditPoints; } else { return(BadRequest("Study year is invalid")); } var check = StudyRuleManager.CheckStudyProject(studyProject); return(Ok(check)); }
public ActionResult StudyOnCourse(int courseId) { string userId = User.Identity.GetUserId(); PersonalArea area = db.PersonalAreas.Where(p => p.AspNetUserId.CompareTo(userId) == 0).First(); StudyViewModel model = GetNextParagraph(area, courseId); return(View(model)); }
public ActionResult Create() { var viewModel = new StudyViewModel { Categories = GetAllCategories() }; return(View(viewModel)); }
public ActionResult AddCourseToArea(int courseId) { if (User.Identity.IsAuthenticated) { ViewBag.teacher = false; if (User.IsInRole("teacher")) { PersonalArea areaTeacher = new PersonalArea() { AspNetUserId = User.Identity.GetUserId(), Person = User.Identity.Name }; ViewBag.teacher = true; return(View(areaTeacher)); } string userId = User.Identity.GetUserId(); PersonalArea area = db.PersonalAreas.Where(a => a.AspNetUserId.CompareTo(userId) == 0).First(); bool alreadyStudy = false; foreach (var course in area.Courses) { if (course.Id == courseId) { alreadyStudy = true; } } if (alreadyStudy) { CoursesInAreaModel coursesModel1 = MakeCoursesModel(area); ViewBag.coursesModel = coursesModel1; List <KeyValuePair <int, int> > redGreen1 = new List <KeyValuePair <int, int> >(); foreach (var course in area.Courses) { StudyViewModel studyModel = GetNextParagraph(area, course.Id); redGreen1.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse)); } ViewBag.RedGreen = redGreen1; return(View(area)); } CourseStructure courseStr = CreateCourseStructure(courseId); area.CourseStructures.Add(courseStr); area.Courses.Add(db.Courses.Find(courseId)); db.SaveChanges(); CoursesInAreaModel coursesModel = MakeCoursesModel(area); ViewBag.coursesModel = coursesModel; List <KeyValuePair <int, int> > redGreen = new List <KeyValuePair <int, int> >(); foreach (var course in area.Courses) { StudyViewModel studyModel = GetNextParagraph(area, course.Id); redGreen.Add(new KeyValuePair <int, int>(course.Id, studyModel.Paragraph.NumInCourse)); } ViewBag.RedGreen = redGreen; return(View(area)); } else { return(RedirectToAction("Login", "Account")); } }
private void EditStudy(StudyViewModel study) { study.Status = (int)EntityStatusType.Current; study.UpdatedBy = Thread.CurrentPrincipal.Identity.Name; study.UpdatedOn = DateTime.UtcNow; using (var adminUow = DependencyResolver.Current.GetService <IAdminUnitOfWork>()) { adminUow.StudyRepository.Update(study.ToEntity()); adminUow.Commit(); } }
public ActionResult Edit(StudyViewModel study) { if (ModelState.IsValid) { var model = db.Studies.Find(study.ID); GlobalHelpers.Transfer <StudyViewModel, Study>(study, model); db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = model.ID })); } return(View(study)); }
public ActionResult Edit(int id = 0) { Study study = db.Studies.Find(id); if (study == null) { return(this.InvokeHttp404(HttpContext)); } StudyViewModel model = new StudyViewModel(); GlobalHelpers.Transfer <Study, StudyViewModel>(study, model); return(View(model)); }
public ActionResult Edit(StudyViewModel study) { if (study != null) { study.Categories = GetAllCategories(); } if (ModelState.IsValid) { var model = Mapper.Map <Study>(study); _studyRepository.Update(model); } return(View(study)); }
public IHttpActionResult PostStudy(StudyViewModel studyViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } #region SubjectAgeCriteria if (studyViewModel.GreaterThanEquals) { studyViewModel.SubjectMinAgeInequality = "GTOET"; } else if (studyViewModel.GreaterThan) { studyViewModel.SubjectMinAgeInequality = "GT"; } //Age Min var minMonth = (double)studyViewModel.MinMonth / 12; studyViewModel.SubjectMinAgeInYears = (double)(studyViewModel.MinYear) + minMonth; if (studyViewModel.LessThanEquals) { studyViewModel.SubjectMaxAgeInequality = "LTOET"; } else if (studyViewModel.LessThan) { studyViewModel.SubjectMaxAgeInequality = "LT"; } var maxMonth = (double)studyViewModel.MaxMonth / 12; studyViewModel.SubjectMaxAgeInYears = (double)(studyViewModel.MaxYear) + maxMonth; #endregion var studyMapper = new StudyMapper(); var study = studyMapper.GetStudy(studyViewModel); db.Studies.Add(study); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = study.StudyId }, study)); }
public void Study_Updates_Interval_And_DueDate() { // Arrange var note = new Note() { Id = 1, Title = "Note 1", IntervalInDays = 1, FirstStudiedDate = DateTime.Parse("01-01-17"), Resources = new List <Resource>() }; var context = new TestContext(); context.Users.Add(user); context.Notes.Add(note); // Arrange - create the controller NoteController target = new NoteController(context) { GetUserId = () => user.Id }; // Act var model = new StudyViewModel { Interval = 3, Id = note.Id, Title = note.Title, IntervalInDays = note.IntervalInDays, FirstStudiedDate = note.FirstStudiedDate, }; target.Study(model); // Assert - ensure interval and DueDate updated, and review created var savedNote = context.Notes.Single(); var savedReview = context.Reviews.SingleOrDefault(); Assert.AreEqual(3, savedNote.IntervalInDays); Assert.AreEqual(DateTime.Today.AddDays(3), savedNote.DueDate.Date); Assert.IsNotNull(savedReview); Assert.AreEqual(savedNote, savedReview.Note); Assert.AreEqual(DateTime.Today, savedReview.Date.Date); }
public ObservableCollection<StudyViewModel> GetAllStudies(int CurrentID) { study = new ObservableCollection<StudyViewModel>(); using (var db = new SQLite.SQLiteConnection(app.dbPath)) { var q = db.Query<Study>("select * from study where MemID = "+CurrentID+" "); foreach (var _subject in q) { var studytime = new StudyViewModel() { Id = _subject.Id, StudyName = _subject.StudyName, Duration = _subject.Duration, Date = _subject.Date, }; study.Add(studytime); } } return study; }
public StudyViewModel GetNextParagraph(PersonalArea area, int courseId) { var structure = area.CourseStructures.Where(c => c.IdCourse == courseId).First(); var parStructures = db.ParagraphStructures.Where(p => p.CourseStructureId == structure.Id); List <ParagraphStructure> sortParag = parStructures.OrderBy(p => p.NumInCourse).ToList(); foreach (var par in sortParag) { var testStructures = db.TestStructures.Where(t => t.ParagraphStructureId == par.Id); List <TestStructure> testSort = testStructures.OrderBy(t => t.NumInParagraph).ToList(); foreach (var test in testSort) { bool isTestPassed = true; var queStructures = db.QuestionStructures.Where(q => q.TestStructureId == test.Id); List <QuestionStructure> queSort = queStructures.OrderBy(q => q.NumInTest).ToList(); foreach (var que in queSort) { if (que.Passed == false) { isTestPassed = false; } } if (!isTestPassed) { List <Test> tests = db.Tests.Where(t => t.ParagraphId == par.IdParagraph).ToList(); StudyViewModel model = new StudyViewModel() { Paragraph = db.Paragraphs.Find(par.IdParagraph), Tests = tests }; return(model); } } } return(new StudyViewModel() { Paragraph = db.Paragraphs.Find(sortParag.Last().IdParagraph), Tests = new List <Test>() }); }
public async Task <IActionResult> Create([Bind("ID,Code,Name,TheoreticalHour,PracticalHour,TheoreticalCount,PracticalCount,LessonType,LessonTypeCode,GradeId")] StudyViewModel study) { if (ModelState.IsValid) { Study newRecore = new Study() { ID = study.ID, Code = study.Code, GradeId = study.GradeId, LessonType = study.LessonType, LessonTypeCode = study.LessonTypeCode, Name = study.Name, PracticalCount = study.PracticalCount, PracticalHour = study.PracticalHour, TheoreticalCount = study.TheoreticalCount, TheoreticalHour = study.TheoreticalHour }; _studyRepository.InsertStudy(newRecore); _studyRepository.Save(); return(RedirectToAction(nameof(Index))); } return(View(study)); }
public ActionResult Study(StudyViewModel model) { Note note = db.GetNoteByID(model.Id); if (model.Interval == null || model.Interval <= 0) { TempData["errorMsg"] = "Invalid interval."; return(View(note)); } note.UpdateInterval((int)model.Interval); var review = new Review { Date = DateTime.UtcNow, Note = note }; db.InsertReview(review); db.SaveChanges(); if (model.ReturnUrl == null) { return(RedirectToAction("StudyList")); } return(Redirect(model.ReturnUrl)); }
public JsonResult NewStudy(StudyViewModel study) { if (ModelState.IsValid) { if (study.Id > 0) { EditStudy(study); //return RedirectToAction("Index"); return(Json("success", JsonRequestBehavior.AllowGet)); } study.CreatedBy = Thread.CurrentPrincipal.Identity.Name; study.CreatedOn = DateTime.UtcNow; study.Status = (int)EntityStatusType.Current; using (var adminUow = DependencyResolver.Current.GetService <IAdminUnitOfWork>()) { adminUow.StudyRepository.Insert(study.ToEntity()); adminUow.Commit(); } } //return RedirectToAction("Index"); return(Json("success", JsonRequestBehavior.AllowGet)); }
private void Button_Click(object sender, RoutedEventArgs e) { var studyStartTime = tmpStart.Time; var studyEndTime = studyStartTime + TimeSpan.FromSeconds(10); var studyStartTime1 = tmpEnd.Time; var studyEndTime1 = studyStartTime1 + TimeSpan.FromSeconds(10); time = studyEndTime1 - studyEndTime; var objStudy = new StudyViewModel(); string studyName = string.Empty; var objSubject = new SubjectViewModel(); string status = string.Empty; studyName = (string)cmbSubjects.SelectedItem; try { studyName = (string)cmbSubjects.SelectedItem; var confirm = objSubject.getSubject(studyName,GetID); if (confirm != null) { if (FutureTime()) { if (GreaterEndTime()) { objStudy.SetStudy(studyName, time.ToString(),GetID); timer.Start(); } else { status = "End time must be greater than the start time"; } } else { status = "Start time must be greater than the current time"; } } else { status = "Please select a subject to study"; } } catch (Exception ex) { messageBox("error " + ex.Message); } if (status != string.Empty) messageBox(status); }
private void btnClear_Click(object sender, RoutedEventArgs e) { var objSubject = new SubjectViewModel(); var objReminder = new ReminderViewModel(); var objStudy = new StudyViewModel(); string output = (string)cmbOutput.SelectedItem; string table = string.Empty; try { if (output == "Progress") { lsvOutput.Items.Clear(); objSubject.RemoveSubject(GetID); } else if (output == "Reminders") { lsvOutput.Items.Clear(); objReminder.RemoveReminder(GetID); } else if (output == "StudyTime") { lsvOutput.Items.Clear(); objStudy.RemoveStudy(GetID); } btnClear.Visibility = Visibility.Collapsed; } catch (Exception ex) { if (output == "Progress") table = "Subjects"; else if (output == "Reminders") table = "Reminders"; else if (output == "StudyTime") table = "StudyTimes"; messageBox("error " + ex.Message + "\nPlease add " + table); } }
public IHttpActionResult PutStudy(int id, StudyViewModel studyViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != studyViewModel.StudyId) { return(BadRequest()); } #region SubjectAgeCriteria if (studyViewModel.GreaterThanEquals) { studyViewModel.SubjectMinAgeInequality = "GTOET"; } else if (studyViewModel.GreaterThan) { studyViewModel.SubjectMinAgeInequality = "GT"; } //Age Min var minMonth = (double)studyViewModel.MinMonth / 12; studyViewModel.SubjectMinAgeInYears = (double)(studyViewModel.MinYear) + minMonth; if (studyViewModel.LessThanEquals) { studyViewModel.SubjectMaxAgeInequality = "LTOET"; } else if (studyViewModel.LessThan) { studyViewModel.SubjectMaxAgeInequality = "LT"; } var maxMonth = (double)studyViewModel.MaxMonth / 12; studyViewModel.SubjectMaxAgeInYears = (double)(studyViewModel.MaxYear) + maxMonth; #endregion var studyMapper = new StudyMapper(); var study = studyMapper.GetStudy(studyViewModel); db.Entry(study).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }