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));
            }
        }
コード例 #2
0
        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());
     }
 }