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 async Task <bool> AddProfessorToSubject(string professorId, int subjectId) { try { ProfessorSubject professorSubject = new ProfessorSubject { ProfessorId = professorId, SubjectId = subjectId }; _context.Attach(new FacultyProfessor { Id = professorId }); _context.Attach(new Subject { Id = subjectId }); _context.ProfessorSubjects.Add(professorSubject); await _context.SaveChangesAsync(); return(true); } catch (Exception ex) { return(false); } }
private static void seedData(out List <Professor> professors, out List <Subject> subjects, out List <ProfessorSubject> professorSubjects, out List <Student> students, out List <SeminarPaper> seminarPapers) { professors = new List <Professor>(); subjects = new List <Subject>(); professorSubjects = new List <ProfessorSubject>(); students = new List <Student>(); seminarPapers = new List <SeminarPaper>(); //sifra za profesora Admin.123. Professor p1 = new Professor() { FirstName = "Душан", LastName = "Бараћ", Email = "*****@*****.**", Id = "21", AccessFailedCount = 0, ConcurrencyStamp = "976d6c23-12e5-4acb-8130-601e73a0f77b", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEHBL8bFd9GJAYlw8zQiyUsq4Qg+7/1XOo3XBQwUwx50VIlJcoqi8GgrMwGF5DzHFiw==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "ac1d41a1-6a1b-43d5-83d0-1eb64223e354", TwoFactorEnabled = false, UserName = "******" }; Professor p2 = new Professor() { FirstName = "Марко", LastName = "Петровић", Email = "*****@*****.**", Id = "22", AccessFailedCount = 0, ConcurrencyStamp = "976d6c23-12e5-4acb-8130-601e73a0f77b", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEHBL8bFd9GJAYlw8zQiyUsq4Qg+7/1XOo3XBQwUwx50VIlJcoqi8GgrMwGF5DzHFiw==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "ac1d41a1-6a1b-43d5-83d0-1eb64223e354", TwoFactorEnabled = false, UserName = "******" }; Professor p3 = new Professor() { FirstName = "Оливера", LastName = "Михић", Email = "*****@*****.**", Id = "23", AccessFailedCount = 0, ConcurrencyStamp = "976d6c23-12e5-4acb-8130-601e73a0f77b", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEHBL8bFd9GJAYlw8zQiyUsq4Qg+7/1XOo3XBQwUwx50VIlJcoqi8GgrMwGF5DzHFiw==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "ac1d41a1-6a1b-43d5-83d0-1eb64223e354", TwoFactorEnabled = false, UserName = "******" }; Professor p4 = new Professor() { FirstName = "Владан", LastName = "Девеџић", Email = "*****@*****.**", Id = "24", AccessFailedCount = 0, ConcurrencyStamp = "976d6c23-12e5-4acb-8130-601e73a0f77b", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEHBL8bFd9GJAYlw8zQiyUsq4Qg+7/1XOo3XBQwUwx50VIlJcoqi8GgrMwGF5DzHFiw==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "ac1d41a1-6a1b-43d5-83d0-1eb64223e354", TwoFactorEnabled = false, UserName = "******" }; Professor p5 = new Professor() { FirstName = "Зоран", LastName = "Радојичић", Email = "*****@*****.**", Id = "25", AccessFailedCount = 0, ConcurrencyStamp = "976d6c23-12e5-4acb-8130-601e73a0f77b", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEHBL8bFd9GJAYlw8zQiyUsq4Qg+7/1XOo3XBQwUwx50VIlJcoqi8GgrMwGF5DzHFiw==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "ac1d41a1-6a1b-43d5-83d0-1eb64223e354", TwoFactorEnabled = false, UserName = "******" }; professors.Add(p1); professors.Add(p2); professors.Add(p3); professors.Add(p4); professors.Add(p5); Subject s1 = new Subject() { Name = "Интернет технологије" }; Subject s2 = new Subject() { Name = "Електронско пословање" }; Subject s3 = new Subject() { Name = "Програмски језици" }; Subject s4 = new Subject() { Name = "Математика 1" }; Subject s5 = new Subject() { Name = "Математика 2" }; Subject s6 = new Subject() { Name = "Програмирање 2" }; Subject s7 = new Subject() { Name = "Интелигентни системи" }; Subject s8 = new Subject() { Name = "Статистика" }; subjects.Add(s1); subjects.Add(s2); subjects.Add(s3); subjects.Add(s4); subjects.Add(s5); subjects.Add(s6); subjects.Add(s7); subjects.Add(s8); ProfessorSubject ps1 = new ProfessorSubject() { Professor = p1, Subject = s1 }; ProfessorSubject ps2 = new ProfessorSubject() { Professor = p1, Subject = s2 }; ProfessorSubject ps3 = new ProfessorSubject() { Professor = p2, Subject = s3 }; ProfessorSubject ps4 = new ProfessorSubject() { Professor = p3, Subject = s4 }; ProfessorSubject ps5 = new ProfessorSubject() { Professor = p3, Subject = s5 }; ProfessorSubject ps6 = new ProfessorSubject() { Professor = p4, Subject = s6 }; ProfessorSubject ps7 = new ProfessorSubject() { Professor = p4, Subject = s7 }; ProfessorSubject ps8 = new ProfessorSubject() { Professor = p5, Subject = s8 }; professorSubjects.Add(ps1); professorSubjects.Add(ps2); professorSubjects.Add(ps3); professorSubjects.Add(ps4); professorSubjects.Add(ps5); professorSubjects.Add(ps6); professorSubjects.Add(ps7); professorSubjects.Add(ps8); //sifra za studenta Korisnik.123. Student st1 = new Student() { FirstName = "Валентина", LastName = "Љубисављевић", IndexNumber = "0095/2014", Email = "*****@*****.**", Id = "31", AccessFailedCount = 0, ConcurrencyStamp = "b2c6c314-d80d-43ff-9b45-51124a38ba49", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEOkysDm1lWmQrKSFzGPFZvK60m9dfY3isNrvazCEw9+cPg3ynBUK8tPH9hnK4hAYjg==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "95f456ec-7b11-4549-a193-9cca49ef4a38", TwoFactorEnabled = false, UserName = "******" }; Student st2 = new Student() { FirstName = "Ђорђе", LastName = "Несторовић", IndexNumber = "0182/2014", Email = "*****@*****.**", Id = "32", AccessFailedCount = 0, ConcurrencyStamp = "b2c6c314-d80d-43ff-9b45-51124a38ba49", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEOkysDm1lWmQrKSFzGPFZvK60m9dfY3isNrvazCEw9+cPg3ynBUK8tPH9hnK4hAYjg==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "95f456ec-7b11-4549-a193-9cca49ef4a38", TwoFactorEnabled = false, UserName = "******" }; Student st3 = new Student() { FirstName = "Филип", LastName = "Фуртула", IndexNumber = "0155/2014", Email = "*****@*****.**", Id = "33", AccessFailedCount = 0, ConcurrencyStamp = "b2c6c314-d80d-43ff-9b45-51124a38ba49", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEOkysDm1lWmQrKSFzGPFZvK60m9dfY3isNrvazCEw9+cPg3ynBUK8tPH9hnK4hAYjg==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "95f456ec-7b11-4549-a193-9cca49ef4a38", TwoFactorEnabled = false, UserName = "******" }; Student st4 = new Student() { FirstName = "Филип", LastName = "Филиповић", IndexNumber = "094/2014", Email = "*****@*****.**", Id = "34", AccessFailedCount = 0, ConcurrencyStamp = "b2c6c314-d80d-43ff-9b45-51124a38ba49", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEOkysDm1lWmQrKSFzGPFZvK60m9dfY3isNrvazCEw9+cPg3ynBUK8tPH9hnK4hAYjg==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "95f456ec-7b11-4549-a193-9cca49ef4a38", TwoFactorEnabled = false, UserName = "******" }; Student st5 = new Student() { FirstName = "Марко", LastName = "Стевић", IndexNumber = "0024/2014", Email = "*****@*****.**", Id = "35", AccessFailedCount = 0, ConcurrencyStamp = "b2c6c314-d80d-43ff-9b45-51124a38ba49", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEOkysDm1lWmQrKSFzGPFZvK60m9dfY3isNrvazCEw9+cPg3ynBUK8tPH9hnK4hAYjg==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "95f456ec-7b11-4549-a193-9cca49ef4a38", TwoFactorEnabled = false, UserName = "******" }; Student st6 = new Student() { FirstName = "Јелена", LastName = "Марјановић", IndexNumber = "0092/2014", Email = "*****@*****.**", Id = "36", AccessFailedCount = 0, ConcurrencyStamp = "b2c6c314-d80d-43ff-9b45-51124a38ba49", EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEOkysDm1lWmQrKSFzGPFZvK60m9dfY3isNrvazCEw9+cPg3ynBUK8tPH9hnK4hAYjg==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "95f456ec-7b11-4549-a193-9cca49ef4a38", TwoFactorEnabled = false, UserName = "******" }; students.Add(st1); students.Add(st2); students.Add(st3); students.Add(st4); students.Add(st5); students.Add(st6); SeminarPaper sp1 = new SeminarPaper() { Name = "Семинарски 1 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps1, Student = st1, PaperFile = new byte[20] }; SeminarPaper sp2 = new SeminarPaper() { Name = "Семинарски 2 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps1, Student = st2, PaperFile = new byte[20] }; SeminarPaper sp3 = new SeminarPaper() { Name = "Семинарски 3 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps2, Student = st2, PaperFile = new byte[20] }; SeminarPaper sp4 = new SeminarPaper() { Name = "Семинарски 4 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps4, Student = st2, PaperFile = new byte[20] }; SeminarPaper sp5 = new SeminarPaper() { Name = "Семинарски 5 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps3, Student = st3, PaperFile = new byte[20] }; SeminarPaper sp6 = new SeminarPaper() { Name = "Семинарски 6 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps4, Student = st4, PaperFile = new byte[20] }; SeminarPaper sp7 = new SeminarPaper() { Name = "Семинарски 7 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps5, Student = st4, PaperFile = new byte[20] }; SeminarPaper sp8 = new SeminarPaper() { Name = "Семинарски 8 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps6, Student = st4, PaperFile = new byte[20] }; SeminarPaper sp9 = new SeminarPaper() { Name = "Семинарски 9 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps6, Student = st5, PaperFile = new byte[20] }; SeminarPaper sp10 = new SeminarPaper() { Name = "Семинарски 10 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps7, Student = st5, PaperFile = new byte[20] }; SeminarPaper sp11 = new SeminarPaper() { Name = "Семинарски 11 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps7, Student = st6, PaperFile = new byte[20] }; SeminarPaper sp12 = new SeminarPaper() { Name = "Семинарски 12 - тест", PublishDate = DateTime.Now, ProfessorSubject = ps8, Student = st6, PaperFile = new byte[20] }; seminarPapers.Add(sp1); seminarPapers.Add(sp2); seminarPapers.Add(sp3); seminarPapers.Add(sp4); seminarPapers.Add(sp5); seminarPapers.Add(sp6); seminarPapers.Add(sp7); seminarPapers.Add(sp8); seminarPapers.Add(sp9); seminarPapers.Add(sp10); seminarPapers.Add(sp11); seminarPapers.Add(sp12); }