public IHttpActionResult PostTeacherSubject(string teacherUsername, int subjectId) { Teacher teacherIn = teacherService.GetTeacherByUserName(teacherUsername); if (teacherIn == null) { logger.Warn("This search does not exist"); return(NotFound()); } SubjectModel subjectIn = subjectService.GetSubject(subjectId); if (subjectIn == null) { logger.Warn("This search does not exist"); return(NotFound()); } TeacherSubject ts = teacherIn.TeachersSubjects.FirstOrDefault(); if (ts.SubjectId == subjectIn.Id) { logger.Warn("This combination already exist"); return(BadRequest("This combination already exist")); } return(Created("PostTeacherSubject", teacherSubjectService.PostTeacherSubject(teacherUsername, subjectId))); }
public TeacherSubjectDTO PostTeacherSubject(string teacherUsername, int subjectId) { Teacher teacherIn = db.TeacherRepository.Get().FirstOrDefault(x => x.UserName == teacherUsername); SubjectModel subjectIn = db.SubjectRepository.GetByID(subjectId); TeacherSubject newTS = new TeacherSubject() { Teacher = teacherIn, TeacherId = teacherIn.Id, Subject = subjectIn, SubjectId = subjectIn.Id }; TeacherSubjectDTO newDTo = new TeacherSubjectDTO() { TeacherFirstName = teacherIn.FirstName, TeacherLastName = teacherIn.LastName, SubjectName = subjectIn.Name }; db.TeacherSubjectRepository.Insert(newTS); db.Save(); logger.Info("New teacher-subject with id {0} is created", newTS.Id); return(newDTo); }
public async Task <IActionResult> PutTeacherSubject(Guid id, TeacherSubject teacherSubject) { if (id != teacherSubject.Id) { return(BadRequest()); } _context.Entry(teacherSubject).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeacherSubjectExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("TeacherSubjectId,TeacherId,SubjectId")] TeacherSubject teacherSubject) { if (id != teacherSubject.TeacherSubjectId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(teacherSubject); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeacherSubjectExists(teacherSubject.TeacherSubjectId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["SubjectId"] = new SelectList(_context.Subjects, "SubjectId", "SubjectId", teacherSubject.SubjectId); ViewData["TeacherId"] = new SelectList(_context.Teachers, "TeacherId", "Name", teacherSubject.TeacherId); return(View(teacherSubject)); }
public static void RemoveFromDb(TeacherSubject teacherSubjects) { if (db.TeacherSubjects.Contains(teacherSubjects)) { db.TeacherSubjects.Remove(teacherSubjects); } }
public async Task <ActionResult <TeacherSubject> > PostTeacherSubject(TeacherSubject teacherSubject) { _context.TeacherSubjects.Add(teacherSubject); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTeacherSubject", new { id = teacherSubject.Id }, teacherSubject)); }
//Chapter Control of subject public ActionResult ChapterDisplay(int?id) { if (!LoginStatus()) { return(RedirectToAction("Login", "Admins", null)); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TeacherChapterViewModel model = new TeacherChapterViewModel() { teacher = new Teacher(), subject = new Subject(), Chapters = new List <Chapter>() }; TeacherSubject teacherSubject = _db.TeacherSubjects.Find(id); model.subject = _db.Subjects.Find(teacherSubject.SubjectId); model.teacher = _db.Teachers.Find(teacherSubject.TeacherId); model.Chapters = _db.Chapters.Where(d => d.SubjectId == teacherSubject.SubjectId && d.EduYearId == GetEduYearId).OrderBy(d => d.ChapterId); return(View(model)); }
public STSDTO PostSTS(string studentUsername, int teacherSubjectId) { Student student = db.StudentRepository.Get().FirstOrDefault(x => x.UserName == studentUsername); TeacherSubject ts = db.TeacherSubjectRepository.GetByID(teacherSubjectId); StudentTeacherSubject newSTS = new StudentTeacherSubject() { StudentId = student.Id, Student = student, TeacherSubjectId = ts.Id, TeacherSubject = ts, }; STSDTO newDTo = new STSDTO() { Student = string.Format("{0} {1}", student.FirstName, student.LastName), Teacher = string.Format("{0} {1}", ts.Teacher.FirstName, ts.Teacher.LastName), Subject = ts.Subject.Name.ToString() }; db.STSRepository.Insert(newSTS); db.Save(); logger.Info("New Student-Teacher-Subejct with id {0} is created", newSTS.Id); return(newDTo); }
public async Task <ActionResult> Create( TeacherCreateViewModel viewModel) { try { if (ModelState.IsValid) { teacherRepository.Add(viewModel.Teacher); await teacherRepository.SaveAsync(); foreach (var selectedSubject in viewModel.Subjects.Where(c => c.IsSelected)) { var teacherSubject = new TeacherSubject { SubjectId = selectedSubject.Subject.Id, TeacherId = viewModel.Teacher.Id }; TeacherSubjectRepository.Add(teacherSubject); await TeacherSubjectRepository.SaveAsync(); } return(RedirectToAction("List", new { id = viewModel.SchoolId })); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name after DataException and add a line here to write a log. ModelState.AddModelError(string.Empty, "Unable to save changes. Try again, and if the problem persists contact your system administrator."); } return(View(viewModel)); }
public async Task <IActionResult> AssignTeacherSubject(TeacherSubjectViewModel objVM) { if (ModelState.IsValid) { List <string> lstSubject = Request.Form["lstSubject"].ToList(); var ClassSection = await _TeacherSubjectRepository.GetClassSectionById(objVM.Class_Id, objVM.Section_Id); if (ClassSection != null) { int result = 0; if (lstSubject.Count > 0) { foreach (var objSubject in lstSubject) { var ClassSubject = await _TeacherSubjectRepository.GetClassSubjectById(ClassSection.ClassSection_id, Convert.ToInt32(objSubject)); if (ClassSubject != null) { var TeacherSubject = new TeacherSubject { Teacher_Id = objVM.Teacher_Id, ClassSubject_Id = ClassSubject.ClassSubject_Id }; result = await _TeacherSubjectRepository.AddTeacherSubject(TeacherSubject); } else { TempData["Error"] = "Please Assign Subject To Class"; return(RedirectToAction("teacherSubjectDetail", "teacher", new { area = "admin" })); } } if (result > 0) { TempData["Success"] = "Subject Assign To Teacher Successfully"; return(RedirectToAction("teacherSubjectDetail", "teacher", new { area = "admin" })); } else { TempData["Error"] = "Failed To Assign Subject To Teacher"; return(RedirectToAction("teacherSubjectDetail", "teacher", new { area = "admin" })); } } //return RedirectToAction("teacherSubjectDetail", "teacher", new { area = "admin" }); } else { TempData["Error"] = "Class Section Didn't Find"; return(RedirectToAction("teacherSubjectDetail", "teacher", new { area = "admin" })); } } return(View()); }
public TeacherSubject DeleteTS(int id) { TeacherSubject ts = db.TeacherSubjectRepository.GetByID(id); db.TeacherSubjectRepository.Delete(ts); db.Save(); logger.Warn("Teacher-subject with id {0} is deleted", ts.Id); return(ts); }
public static void Serialize(string fileName, TeacherSubject teacherSubject) { XmlSerializer serializer = new XmlSerializer(typeof(TeacherSubject)); using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate)) { serializer.Serialize(fs, teacherSubject); } }
public static void UpdateTeacherSubject(TeacherSubject teacherSubject, long TeacherSubjectId = 0, long TeacherSubjectTeacherId = 0, long TeacherSubjectSubjectId = 0, long TeacherSubjectCount = 0) { teacherSubject.Id = TeacherSubjectId == 0 ? teacherSubject.Id : TeacherSubjectId; teacherSubject.TeacherId = TeacherSubjectTeacherId == 0 ? teacherSubject.TeacherId : TeacherSubjectTeacherId; teacherSubject.SubjectId = TeacherSubjectSubjectId == 0 ? teacherSubject.SubjectId : TeacherSubjectSubjectId; teacherSubject.Count = TeacherSubjectCount == 0 ? teacherSubject.Count : TeacherSubjectCount; }
public static void UpdateInDb(TeacherSubject teacherSubject) { var teacherSubjectToUpdate = db.TeacherSubjects.Where(s => s.Id == teacherSubject.Id).FirstOrDefault(); if (teacherSubjectToUpdate != null) { db.TeacherSubjects.Update(teacherSubject); } }
public bool Create(TeacherSubject entity) { using (var context = this.contextFactory.CreateDbContext()) { context.TeacherSubjects.Add(entity); var createdResult = context.SaveChanges(); return(createdResult > 0); } }
public void DeleteTeacherFromSubject(int subjectId, int teacherId) { TeacherSubject ts = dbContext.TeacherSubject.Where(x => x.SubjectId == subjectId && x.TeacherId == teacherId).FirstOrDefault(); if (ts != null) { dbContext.TeacherSubject.Remove(ts); dbContext.SaveChanges(); } }
public IActionResult IsTeacherSubjectsUnique(TeacherSubject tsub) { if (_context.TeacherSubject.Any(ts => ts.TeacherId == tsub.TeacherId && ts.SubjectId == tsub.SubjectId && ts.TeacherSubjectId != tsub.TeacherSubjectId)) { return(Json(false)); } return(Json(true)); }
private static TeacherSubject ConvertRecordToTeacherSubject(IDataRecord record) { var entity = new TeacherSubject(); foreach (var(propertyInfo, index) in typeof(TeacherSubject).GetProperties().WithIndex()) { var dbValue = record[index]; propertyInfo.SetValue(entity, dbValue == DBNull.Value ? null : dbValue); } return(entity); }
public static void SerializeDb(string filename) { var teacherSubjectsFromDb = db.TeacherSubjects.ToArray(); var teacherSubjectsToSerialize = new TeacherSubject[teacherSubjectsFromDb.Length]; for (int i = 0; i < teacherSubjectsToSerialize.Length; i++) { teacherSubjectsToSerialize[i] = CreateTeacherSubject(teacherSubjectsFromDb[i].Id, teacherSubjectsFromDb[i].TeacherId, teacherSubjectsFromDb[i].SubjectId, teacherSubjectsFromDb[i].Count); } SerializeArray(filename, teacherSubjectsToSerialize); }
private List <double> CalculateAvgRaitingValuation(int id, TeacherSubject teach) { var avgValuationList = new List <double>(); for (int index = 0; index < 19; index++) { avgValuationList.Add(0); } var listId = db.Votings.Where(x => x.TeacherSubjectId == id).ToList(); var teachId = db.TeacherSubject.Where(x => x.TeacherId == teach.TeacherId); var listS = new List <int>(); foreach (var s in teachId) { listS.Add(s.Id); } int count = 0; var listIdRaiting = db.RaitingTeacherSubject.Where(x => x.TeacherSubject.TeacherId == teach.TeacherId && x.AvgRating != 0).ToList(); foreach (var voit in listIdRaiting) { avgValuationList[0] += voit.ActivityInClass; avgValuationList[1] += voit.AvailabilityTeacherOutsideLessons; avgValuationList[2] += voit.ClarityAndAccessibility; avgValuationList[3] += voit.CommentsTheWork; avgValuationList[4] += voit.DepthPossessionOf; avgValuationList[5] += voit.HowWellTheProcedurePerformedGrading; avgValuationList[6] += voit.InterestInTheSubject; avgValuationList[7] += voit.NumberOfAttendance; avgValuationList[8] += voit.OverallSubject; avgValuationList[9] += voit.PreparationTime; avgValuationList[10] += voit.ProcedureGrading; avgValuationList[11] += voit.QualityMasteringTheSubject; avgValuationList[12] += voit.QualityTeachingMaterials; avgValuationList[13] += voit.RelevantToStudents; avgValuationList[14] += voit.SomethingNew; avgValuationList[15] += voit.TheDifficultyOfTheCourse; avgValuationList[16] += voit.ThePracticalValue; avgValuationList[17] += voit.RelevantToStudents; avgValuationList[18] += voit.CountVoting; count++; } for (int index = 0; index < avgValuationList.Count - 1; index++) { avgValuationList[index] /= count; } return(avgValuationList); }
private void btnOK_Click(object sender, EventArgs e) { if (Subject == null) { Subject = new TeacherSubject(); } Subject.Subject = comboBox1.SelectedItem as Subject; Subject.Hours = (int)numericUpDown1.Value; DialogResult = DialogResult.OK; }
public void TestMethod1() { var subject = new TeacherSubject(); subject.Attach(new StudentObserver("wawa0210").Sign); subject.Attach(new MomObserver("wawa0210 Mom").Received); subject.Attach(new StudentObserver("tom").Sign); subject.Attach(new MomObserver("tom Mom").Received); subject.Detach(new MomObserver("tom Mom").Received); subject.Notify(); }
public TeacherSubject CreatePP(TeacherSubjectDTO pp) { TeacherSubject pp1 = new TeacherSubject { TeacherSubjectID = pp.TeacherSubjectID, SubjectID = pp.SubjectID, }; context.TeacherSubjectRepository.Insert(pp1); context.Save(); return(pp1); }
public ResponseResult AssignTeacherWithSubject(TeacherSubjectVM teacherSubjectVM) { int muskingId; ResponseResult responseResult = new ResponseResult(); //System.Data.Entity.Core.Objects.ObjectParameter MSG_Code = // new System.Data.Entity.Core.Objects.ObjectParameter("MSG_Code", typeof(string)); //System.Data.Entity.Core.Objects.ObjectParameter MSG = // new System.Data.Entity.Core.Objects.ObjectParameter("MSG", typeof(string)); try { if (IsTeacherAlreadyAssignedToSubject(teacherSubjectVM) == true) { responseResult.MessageCode = "Y"; responseResult.SystemMessage = "Value Already Assigned!"; responseResult.Content = null; return(responseResult); } if (IsSubjectmuskingIdAlredyExists(teacherSubjectVM.SubjectId) == true) { muskingId = AddSubjectMuskingId(teacherSubjectVM.SubjectId);//Adding new muskingId to existing subject TeacherSubject teacherSubjectObj = new TeacherSubject() { MaskingSubjectId = muskingId, TeacherId = teacherSubjectVM.UserId }; _dbContext.TeacherSubjects.Add(teacherSubjectObj); } else { TeacherSubject teacherSubjectObj = new TeacherSubject() { MaskingSubjectId = GetSubjectMaskingIdBySubjactid(teacherSubjectVM.SubjectId), TeacherId = teacherSubjectVM.UserId }; _dbContext.TeacherSubjects.Add(teacherSubjectObj); } _dbContext.SaveChanges(); responseResult.MessageCode = "Y"; responseResult.SystemMessage = "Data seved succesfully"; responseResult.Content = null; } catch (Exception ex) { responseResult.MessageCode = "N"; responseResult.SystemMessage = ex.Message; responseResult.Content = null; } return(responseResult); }
public IHttpActionResult GetTSbyId(int id) { TeacherSubject ts = teacherSubjectService.GetTeacherSubject(id); if (ts == null) { logger.Warn("This search does not exist"); return(NotFound()); } return(Ok(ts)); }
public IActionResult OnPost() { if (ModelState.IsValid) { Teacher teacher = new Teacher(); foreach (var item in Teachers) { if (int.Parse(TeacherID) == item.IdTeacher) { teacher = item; } } Subject subject = new Subject(); foreach (var item in db.Subjects) { if (int.Parse(SubjectID) == item.IdSubject) { subject = item; } } if (teacher.FirstName == null || subject.Name == null) { return(RedirectToPage("add_teacher_subject")); } bool flag = true; foreach (var teacherSubject in TeacherSubjects) { if (teacherSubject.IdSubject == subject.IdSubject && teacher.IdTeacher == teacherSubject.IdTeacher) { flag = false; break; } } //If flag then is a new teacher subject row if (flag) { TeacherSubject teacherSubject = new TeacherSubject() { IdSubject = subject.IdSubject, IdTeacher = teacher.IdTeacher }; db.TeacherSubjects.Add(teacherSubject); db.SaveChanges(); } } return(RedirectToPage("add_teacher_subject")); }
public async Task <IActionResult> CreateAsync(int subjectId, int teacherId) { var teacherSubject = new TeacherSubject() { SubjectId = subjectId, TeacherId = teacherId }; context.TeacherSubject.Add(teacherSubject); await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("TeacherSubjectId,TeacherId,SubjectId")] TeacherSubject teacherSubject) { if (ModelState.IsValid) { _context.Add(teacherSubject); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SubjectId"] = new SelectList(_context.Subjects, "SubjectId", "SubjectId", teacherSubject.SubjectId); ViewData["TeacherId"] = new SelectList(_context.Teachers, "TeacherId", "Name", teacherSubject.TeacherId); return(View(teacherSubject)); }
public IEnumerable <TeacherSubject> GetTSBySubject(int id) { SubjectModel subject = db.SubjectRepository.GetByID(id); TeacherSubject findBySubject = db.TeacherSubjectRepository.Get().FirstOrDefault(x => x.Subject.Id == id); List <TeacherSubject> TSList = new List <TeacherSubject>(); foreach (var s in findBySubject.Subject.TeachersSubjects) { TSList.Add(s); } return(TSList); }
public IHttpActionResult PostTeachSubject(TeacherSubjectDTO pp, string teacherID, int subjectid) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Teacher teacher = teacherService.GetById(teacherID); SubjectDTO subject = subjectService.GetById(subjectid); Subject subject1 = subject.ToSubject(); TeacherSubject teacherSubject = pnoService.CreatePP(pp); return(Ok()); }