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 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()); } }