public async Task <IActionResult> Edit(string id, [Bind("C_ID,C_Department,C_ClassTeacher")] Schoolclass schoolclass) { if (id != schoolclass.C_ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(schoolclass); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SchoolclassExists(schoolclass.C_ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["C_ClassTeacher"] = new SelectList(_context.Teacher, "T_ID", "T_ID", schoolclass.C_ClassTeacher); return(View(schoolclass)); }
public async Task <IActionResult> Post(string id, [FromBody] Schoolclass schoolclass) { if (id != schoolclass.C_ID) { return(Conflict()); } if (ModelState.IsValid) { try { await _schoolclassService.EditAsync(id, schoolclass); } catch (KeyNotFoundException) { return(NotFound()); } catch (ServiceLayerException) { return(StatusCode(500)); } return(RedirectToAction(nameof(Index))); } ViewData["C_ClassTeacher"] = new SelectList(await _techerService.GetAllAsync(), "T_ID", "T_ID", schoolclass.C_ClassTeacher); return(View(schoolclass)); }
public async Task <Schoolclass> CreateAsync(Schoolclass newModel) { _context.Add(newModel); await _context.SaveChangesAsync(); return(newModel); }
public async Task <IActionResult> Edit(string id, [FromForm()] Schoolclass schoolclass) { if (id != schoolclass.C_ID) { return(NotFound()); } if (ModelState.IsValid) { try { await _schoolclassService.EditAsync(id, schoolclass); } catch (KeyNotFoundException) { return(NotFound()); } catch (DbUpdateConcurrencyException) { throw; } return(RedirectToAction(nameof(Index))); } ViewData["C_ClassTeacher"] = new SelectList(await _techerService.GetAllAsync(), "T_ID", "T_ID", schoolclass.C_ClassTeacher); return(View(schoolclass)); }
public async Task <Schoolclass> EditAsync(string id, Schoolclass newModel) { try { return(await _repository.EditAsync(newModel, c => !EntityExists(newModel.C_ID), c => { return new Schoolclass() { C_ID = newModel.C_ID, C_ClassTeacher = newModel.C_ClassTeacher, C_Department = newModel.C_Department, }; })); } catch (KeyNotFoundException ex) { throw new ServiceLayerException("Methode EditAsync(long, Lesson) ist fehlgeschlagen!", ex); } catch (DbUpdateConcurrencyException ex) { throw new ServiceLayerException("Methode EditAsync(long, Lesson) ist fehlgeschlagen!", ex); } catch (InvalidOperationException ex) { throw new ServiceLayerException("Methode EditAsync(long, Lesson) ist fehlgeschlagen!", ex); } }
public async Task <IActionResult> Create([FromForm()] Schoolclass schoolclass) { if (ModelState.IsValid) { await _schoolclassService.CreateAsync(schoolclass); return(RedirectToAction(nameof(Index))); } ViewData["C_ClassTeacher"] = new SelectList(await _techerService.GetAllAsync(), "T_ID", "T_ID", schoolclass.C_ClassTeacher); return(View(schoolclass)); }
public async Task <IActionResult> Create([Bind("C_ID,C_Department,C_ClassTeacher")] Schoolclass schoolclass) { if (ModelState.IsValid) { _context.Add(schoolclass); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["C_ClassTeacher"] = new SelectList(_context.Teacher, "T_ID", "T_ID", schoolclass.C_ClassTeacher); return(View(schoolclass)); }
public async Task <Schoolclass> CreateAsync(Schoolclass newModel) { try { _context.Add(newModel); await _context.SaveChangesAsync(); } catch (InvalidOperationException ex) { _logger.LogError(ex, "Methode CreateAsync(Schoolclass) ist fehlgeschlagen!"); throw new ServiceLayerException("Methode CreateAsync(Schoolclass) ist fehlgeschlagen!", ex); } return(newModel); }
public SendingDataToDatabase(Schoolclass schoolclass) { int i = 0; using (SqlConnection conn = new SqlConnection("Data Source = LAPTOP-0D53CULI\\SQLEXPRESS;Initial Catalog = School;Integrated Security = True")) { conn.Open(); //sending course data using (SqlCommand command = new SqlCommand($"INSERT INTO Courses (Stream, TypeOfCourse, StartDate, EndDate) VALUES ('{schoolclass.Course.Stream}', '{schoolclass.Course.Type}', '{schoolclass.Course.StartDate}', '{schoolclass.Course.EndDate}')", conn)) { command.ExecuteNonQuery(); } //sending trainers data for (i = 0; i < schoolclass.Trainer.Count; i++) { using (SqlCommand command = new SqlCommand($"INSERT INTO Trainers (FirstName, LastName, CourseID) VALUES ('{schoolclass.Trainer[i].FirstName}', '{schoolclass.Trainer[i].LastName}', (SELECT TOP 1 CourseID FROM Courses ORDER BY CourseID DESC))", conn)) { command.ExecuteNonQuery(); } } //sending students data for (i = 0; i < schoolclass.Students.Count; i++) { using (SqlCommand command = new SqlCommand($"INSERT INTO Students (FirstName, LastName, TutionFees, DateOfBirth) VALUES ('{schoolclass.Students[i].FirstName}','{schoolclass.Students[i].LastName}', '{schoolclass.Students[i].TuitionFees}', '{schoolclass.Students[i].DateOfBirth}')", conn)) { command.ExecuteNonQuery(); } } //sending assignment data for (i = 0; i < schoolclass.Assignment.Count; i++) { using (SqlCommand command = new SqlCommand($"INSERT INTO Assignments (Title, DescriptionOfAssignment, SubmissionDate, OralMark, TotalMark, CourseID) VALUES ('{schoolclass.Assignment[i].Title}', '{schoolclass.Assignment[i].Description}', '{schoolclass.Assignment[i].SubDateTime}','{schoolclass.Assignment[i].OralMark}', '{schoolclass.Assignment[i].TotalMark}', (SELECT TOP 1 CourseID FROM Courses ORDER BY CourseID DESC))", conn)) { command.ExecuteNonQuery(); } } //sending data to the junction table using (SqlCommand command1 = new SqlCommand($"SELECT TOP 1 StudentID FROM Students ORDER BY StudentID DESC ", conn)) { int studentsNum = Convert.ToInt32(command1.ExecuteNonQuery()); for (i = 0; i < schoolclass.Students.Count; i++) { using (SqlCommand command = new SqlCommand($"INSERT INTO Student_Course (CourseID, StudentID) VALUES ((SELECT TOP 1 CourseID FROM Courses ORDER BY CourseID DESC), (SELECT StudentID FROM Students WHERE Students.StudentID = '{studentsNum - i}'))", conn)) { command.ExecuteNonQuery(); } } } } }
private void StartRecording() { Schoolclass schoolclass = new Schoolclass(); do { schoolclass.Course = GetCourseInfo(); schoolclass.Trainer = GetTrainers(schoolclass.Course.Title); schoolclass.Students = GetStudents(); schoolclass.Assignment = GetAssignments(); SendingDataToDatabase sendingDataToDatabase = new SendingDataToDatabase(schoolclass); } while (AskUserToExitRecording()); }
public async Task <Schoolclass> CreateAsync(Schoolclass newModel) { try { return(await _repository.CreateAsync(newModel)); } catch (KeyNotFoundException ex) { throw new ServiceLayerException("Methode EditAsync(long, Lesson) ist fehlgeschlagen!", ex); } catch (InvalidOperationException ex) { throw new ServiceLayerException("Methode EditAsync(long, Lesson) ist fehlgeschlagen!", ex); } }
public async Task <Schoolclass> EditAsync(Guid id, Schoolclass newModel) { try { _context.Update(newModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EntityExists(newModel.C_ID)) { throw new KeyNotFoundException("Datensatz wurde nicht gefunden!"); } throw; } return(newModel); }
public async Task <IActionResult> Create([Bind("C_ID,C_Department,C_ClassTeacher")] Schoolclass schoolclass) { if (ModelState.IsValid) { try { await _schoolclassService.CreateAsync(schoolclass); return(RedirectToAction(nameof(Index))); } catch (ServiceLayerException) { return(StatusCode(500)); } } ViewData["C_ClassTeacher"] = new SelectList(await _techerService.GetAllAsync(), "T_ID", "T_ID", schoolclass.C_ClassTeacher); return(View(schoolclass)); }
public async Task <Schoolclass> EditAsync(string id, Schoolclass newModel) { _logger.LogInformation("EditAsync(string id, Schoolclass newModel)"); if (id != newModel.C_ID) { throw new KeyNotFoundException("Datensatz wurde nicht gefunden!"); } try { Schoolclass existingSchoolclass = _context.Schoolclass.Find(id); if (existingSchoolclass == null) { throw new KeyNotFoundException("Datensatz wurde nicht gefunden!"); } else { existingSchoolclass.C_ClassTeacher = newModel.C_ClassTeacher; existingSchoolclass.C_Department = newModel.C_Department; _context.Update(existingSchoolclass); await _context.SaveChangesAsync(); } } catch (InvalidOperationException ex) { _logger.LogError(ex, "Methode EditAsync(long, Schoolclass) ist fehlgeschlagen!"); throw new ServiceLayerException("Methode EditAsync(long, Schoolclass) ist fehlgeschlagen!", ex); } catch (DbUpdateConcurrencyException) { if (!EntityExists(newModel.C_ID)) { throw new ServiceLayerException("Datensatz wurde nicht gefunden!"); } throw; } return(newModel); }