public IActionResult Index() { try { ISeminarPapersLogic seminarPaperLogic = new SeminarPapersLogic(_context); SeminarPaperViewModel spvm = new SeminarPaperViewModel(); List <SeminarPaper> papers = seminarPaperLogic.GetAll(); List <SeminarPaper> papersToShow = new List <SeminarPaper>(); if (User.IsInRole("admin")) { papersToShow = papers; } else if (User.IsInRole("profesor")) { papersToShow = papers.FindAll(p => p.ProfessorSubject.ProfessorId.Equals(_userManager.GetUserId(User))); } else if (User.IsInRole("student")) { papersToShow = papers.FindAll(p => p.Student.Id.Equals(_userManager.GetUserId(User))); } spvm.AllSeminarPapers = papersToShow; return(View(spvm)); } catch (Exception ex) { //TODO: Hendlaj gresku return(View()); } }
public IActionResult DeleteStudent(string id, string returnUrl = null) { SeminarPapersLogic seminarPapersLogic = new SeminarPapersLogic(_context); //FinalPapersLogic finalPapersLogic = new FinalPapersLogic(_context); StudentLogic studentLogic = new StudentLogic(_context); Student s = studentLogic.GetById(id); studentLogic.Delete(s.Id); s.SeminarPapers.ForEach(sp => seminarPapersLogic.Delete(sp.SeminarPaperId)); //s.FinalPapers.ForEach(sp => finalPapersLogic.Delete(sp.FinalPaperId)); return(RedirectToAction("Users")); }
public IActionResult Delete(int seminarPaperId) { try { ISeminarPapersLogic seminarPaperLogic = new SeminarPapersLogic(_context); seminarPaperLogic.Delete(seminarPaperId); return(RedirectToAction("Index")); } catch (Exception ex) { return(BadRequest(ex)); } }
public IActionResult Insert(SeminarPaperViewModel seminarPaperViewModel) { ISeminarPapersLogic seminarPaperLogic = new SeminarPapersLogic(_context); IProfessorLogic professorLogic = new ProfessorLogic(_context); IStudentLogic studentLogic = new StudentLogic(_context); ISubjectLogic subjectLogic = new SubjectLogic(_context); IProfessorSubjectLogic professorSubjectLogic = new ProfessorSubjectLogic(_context); ProfessorSubject ps = professorSubjectLogic.GetOne(seminarPaperViewModel.ProfessorId, seminarPaperViewModel.SubjectId) ?? throw new Exception(); SeminarPaper s = new SeminarPaper(); s.Name = seminarPaperViewModel.Name; s.ProfessorSubject = ps; s.PublishDate = DateTime.Now; s.Student = studentLogic.GetById(_userManager.GetUserId(User)); s.PaperFile = new byte[20]; SeminarPaperViewModel spvm = new SeminarPaperViewModel(); spvm.SeminarPaper = s; try { if (!ModelState.IsValid) { spvm.AllProfessors = professorLogic.GetAll(); spvm.AllSubjects = subjectLogic.GetAll(); spvm.SeminarPaper.Name = seminarPaperViewModel.Name ?? ""; spvm.SeminarPaper.PaperFile = null; return(View("Insert", spvm)); } //using (var memoryStream = new MemoryStream()) //{ // await seminarPaperViewModel.File.CopyToAsync(memoryStream); // spvm.SeminarPaper.PaperFile = memoryStream.ToArray(); //} seminarPaperLogic.Insert(s); return(RedirectToAction("Index", "SeminarPapers")); } catch (Exception ex) { spvm.AllProfessors = professorLogic.GetAll(); spvm.AllSubjects = subjectLogic.GetAll(); spvm.SeminarPaper.Name = seminarPaperViewModel.Name ?? ""; spvm.SeminarPaper.PaperFile = null; return(View("Insert", spvm)); } }
public IActionResult Find(int id) { try { ISeminarPapersLogic seminarPaperLogic = new SeminarPapersLogic(_context); SeminarPaperViewModel spvm = new SeminarPaperViewModel(); spvm.SeminarPaper = seminarPaperLogic.GetById(id); return(View(spvm)); } catch (Exception ex) { //TODO: Hendlaj gresku return(View()); } }
public IActionResult DeleteProfessor(string id, string returnUrl = null) { SeminarPapersLogic seminarPapersLogic = new SeminarPapersLogic(_context); ProfessorSubjectLogic professorSubjectLogic = new ProfessorSubjectLogic(_context); //FinalPapersLogic finalPapersLogic = new FinalPapersLogic(_context); ProfessorLogic professorLogic = new ProfessorLogic(_context); Professor p = professorLogic.GetById(id); List <ProfessorSubject> ps = professorSubjectLogic.GetByProfessorId(id).ToList(); p.ProfessorSubjects = ps; ps.ToList().ForEach(pp => pp.SeminarPapers.ToList().ForEach(sp2 => seminarPapersLogic.Delete(sp2.SeminarPaperId))); ps.ToList().ForEach(p1 => professorSubjectLogic.Delete(p1.ProfessorId, p1.SubjectId)); professorLogic.Delete(p.Id); //p.FinalPapers.ForEach(fp => finalPapersLogic.Delete(fp.FinalPaperId)); return(RedirectToAction("Users")); }
public IActionResult Insert() { try { ISeminarPapersLogic seminarPaperLogic = new SeminarPapersLogic(_context); ISubjectLogic subjectLogic = new SubjectLogic(_context); IProfessorLogic professorLogic = new ProfessorLogic(_context); IProfessorSubjectLogic professorSubjectLogic = new ProfessorSubjectLogic(_context); SeminarPaperViewModel spvm = new SeminarPaperViewModel(); spvm.AllProfessors = professorLogic.GetAll(); spvm.AllSubjects = subjectLogic.GetAll(); return(View(spvm)); } catch (Exception ex) { //TODO: Hendlaj gresku return(View()); } }