public async Task <IActionResult> Create([Bind("EnrollmentID,CourseID,StudentID,Semester,Grade,Year,SeminalUrl,ProjectUrl,ExamPoints,SeminalPoints,ProjectPoints,AdditionalPoints,FinishDate")] Enrollment enrollment) { if (ModelState.IsValid) { _context.Add(enrollment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourseID"] = new SelectList(_context.Courses, "CourseID", "Title", enrollment.CourseID); ViewData["StudentID"] = new SelectList(_context.Students, "ID", "FullName", enrollment.StudentID); return(View(enrollment)); }
public async Task <IActionResult> Create([Bind("InstructorID,CourseID")] CourseAssignment courseAssignment) { if (ModelState.IsValid) { _context.Add(courseAssignment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourseID"] = new SelectList(_context.Courses, "CourseID", "CourseID", courseAssignment.CourseID); ViewData["InstructorID"] = new SelectList(_context.Instructors, "ID", "FirstMidName", courseAssignment.InstructorID); return(View(courseAssignment)); }
public async Task <IActionResult> Create([Bind("Id,Title,Credits,Semester,Programme,EducationLevel,FirstTeacherId,SecondTeacherId")] Course course) { if (ModelState.IsValid) { _context.Add(course); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FirstTeacherId"] = new SelectList(_context.Set <Teacher>(), "Id", "FullName", course.FirstTeacherId); ViewData["SecondTeacherId"] = new SelectList(_context.Set <Teacher>(), "Id", "FullName", course.SecondTeacherId); return(View(course)); }
public async Task <IActionResult> Create([Bind("ID,title,credits,semester,programme,educationLevel,firstTeacherID,secondTeacherID")] Course course) { if (ModelState.IsValid) { _context.Add(course); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["firstTeacherID"] = new SelectList(_context.Teacher, "ID", "fullName", course.firstTeacherID); ViewData["secondTeacherID"] = new SelectList(_context.Teacher, "ID", "fullName", course.secondTeacherID); return(View(course)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,AverageScore,GroupId")] Student student) { if (ModelState.IsValid) { student.Id = Guid.NewGuid(); _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["GroupId"] = new SelectList(_context.Groups, "Id", "Id", student.GroupId); return(View(student)); }
public async Task <IActionResult> Create([Bind("DisciplineID,NameDiscipline,NumberOfHoursOfLectures,NumberOfHoursOfPractice,TypeOfRporting,TeacherID,TypeOfDisciplineID,SpecialtyID")] Discipline discipline) { if (ModelState.IsValid) { _context.Add(discipline); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SpecialtyID"] = new SelectList(_context.Speciaties, "SpecialtyID", "NameSpecialty", discipline.SpecialtyID); ViewData["TeacherID"] = new SelectList(_context.Teachers, "TeacherID", "FullName", discipline.TeacherID); ViewData["TypeOfDisciplineID"] = new SelectList(_context.TypeOfDisciplins, "TypeOfDisciplineID", "NameTypeOfDiscipline", discipline.TypeOfDisciplineID); return(View(discipline)); }
public async Task <IActionResult> Create( [Bind("Id,Name,Budget,StartDate,InstructorId")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["InstructorId"] = new SelectList( _context.Instructors, "Id", "FullName", department.InstructorId); return(View(department)); }
public async Task <IActionResult> Create([Bind("Id,Name,AverageScore,CourseId,SpecialtyId")] Group @group) { if (ModelState.IsValid) { @group.Id = Guid.NewGuid(); _context.Add(@group); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_context.Courses, "Id", "Id", @group.CourseId); ViewData["SpecialtyId"] = new SelectList(_context.Specialties, "Id", "Id", @group.SpecialtyId); return(View(@group)); }
public async Task <IActionResult> Create([Bind("CourseID, Title, Credits, Semester, Programme, EducationLevel, FirstTeacherId, SecondTeacherId")] Course course) { if (ModelState.IsValid) { _context.Add(course); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } PopulateTeachersDropDownList1(course.FirstTeacherId); PopulateTeachersDropDownList2(course.SecondTeacherId); return(View(course)); }
public async Task <IActionResult> Create(long?groupId, [Bind("Id,DayId")] Shedule shedule) { shedule.GroupId = groupId; if (ModelState.IsValid) { _context.Add(shedule); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { id = groupId, name = _context.Groups.Where(g => g.Id == groupId).FirstOrDefault().Name })); // return RedirectToAction(nameof(Index)); } ViewData["DayId"] = new SelectList(_context.Days, "Id", "Name", shedule.DayId); return(RedirectToAction("Index", new { id = groupId, name = _context.Groups.Where(g => g.Id == groupId).FirstOrDefault().Name })); }
public async Task <IActionResult> Create([Bind("Id,Value,SubjectId,StudentId,CourseId")] Score score) { if (ModelState.IsValid) { score.Id = Guid.NewGuid(); _context.Add(score); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_context.Courses, "Id", "Id", score.CourseId); ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Id", score.StudentId); ViewData["SubjectId"] = new SelectList(_context.Subjects, "Id", "Id", score.SubjectId); return(View(score)); }
public IActionResult Create(CreateUpdateStudent model) { var student = new Student() { UniqueIdentifier = model.UniqueIdentifier, FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName, Sex = model.Sex }; db.Add(student); db.SaveChanges(); return(Ok(student)); }
public async Task <IActionResult> Create(TeacherForm model, string[] selectedCourses, Teacher teacher) { if (selectedCourses != null) { teacher.Course1 = new List <Course>(); foreach (var course in selectedCourses) { var courseToAdd = new Course { FirstTeacherId = teacher.TeacherId, CourseID = int.Parse(course) }; teacher.Course1.Add(courseToAdd); } teacher.Course2 = new List <Course>(); foreach (var course in selectedCourses) { var courseToAdd = new Course { SecondTeacherId = teacher.TeacherId, CourseID = int.Parse(course) }; teacher.Course2.Add(courseToAdd); } } if (ModelState.IsValid) { string uniqueFileName = UploadedFile(model); teacher = new Teacher { FirstName = model.FirstName, LastName = model.LastName, Degree = model.Degree, AcademicRank = model.AcademicRank, OfficeNumber = model.OfficeNumber, HireDate = model.HireDate, ProfilePicture = uniqueFileName, Course1 = model.Courses_first, Course2 = model.Courses_second }; _context.Add(teacher); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task InvokeAsync(HttpContext context, UniversityContext db) { var keyValue = context.Request.Query["Key"]; if (!string.IsNullOrWhiteSpace(keyValue)) { db.Add(new Request() { DT = DateTime.Now, MiddlewareActivation = "ConventionalMiddleware", Value = keyValue }); await db.SaveChangesAsync(); } await _next(context); }
public async Task <IActionResult> Create([Bind("LastName,FirstMidName,EnrollmentDate")] Student student) { try { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. Try again,and if the problem persists,see your system administrator."); } return(View(student)); }
public async Task InvokeAsync(HttpContext context, RequestDelegate next) { var keyValue = context.Request.Query["Key"]; if (!string.IsNullOrWhiteSpace(keyValue)) { ctx.Add(new Request() { DT = DateTime.Now, MiddlewareActivation = "IMiddlewareMiddleware", Value = keyValue }); await ctx.SaveChangesAsync(); } await next(context); }
public async Task <IActionResult> Create([Bind("Id,Name")] Lessons lessons) { var l_names = from l in _context.Lessons select l.Name; if (l_names.Contains(lessons.Name)) { ModelState.AddModelError("Name", "This name is already exist"); return(View(lessons)); } if (ModelState.IsValid && !l_names.Contains(lessons.Name)) { _context.Add(lessons); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Index", new { error = "Не створено" })); }
public async Task <IActionResult> Create([Bind("Id,Name")] Deparments deparments) { var dep_name = from d in _context.Deparments select d.Name; if (dep_name.Contains(deparments.Name)) { ModelState.AddModelError("Name", "This name is already exist"); return(View(deparments)); } if (ModelState.IsValid && !dep_name.Contains(deparments.Name)) { _context.Add(deparments); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Index", new { error = "Не створено" })); }
public async Task <IActionResult> Create(int?groupId, [Bind("Id,Name,Surname,Gender,Birthday")] Students students) { students.GroupId = groupId; ViewBag.GroupId = groupId; if (ModelState.IsValid) { _context.Add(students); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Students", new { id = groupId, name = _context.Groups.Where(g => g.Id == groupId).FirstOrDefault().Name })); } //ViewData["GroupId"] = new SelectList(_context.Groups, "Id", "Name", student.GroupId); //return View(student); var Genders = new List <string> { "Male", "Female" }; ViewData["Gender"] = new SelectList(Genders); return(RedirectToAction("Index", "Students", new { id = groupId, name = _context.Groups.Where(g => g.Id == groupId).FirstOrDefault().Name })); }
public async Task <IActionResult> Create( [Bind("Name,Adress")] University university) { try { if (ModelState.IsValid) { _context.Add(university); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(university)); }
public async Task <IActionResult> Create([Bind("FirstMidName,HireDate,LastName,OfficeAssignment")] Instructor instructor, string[] selectedCourses) { if (selectedCourses != null) { instructor.CourseAssignments = new List <CourseAssignment>(); foreach (var course in selectedCourses) { var courseToAdd = new CourseAssignment { InstructorID = instructor.ID, CourseID = int.Parse(course) }; instructor.CourseAssignments.Add(courseToAdd); } } if (ModelState.IsValid) { _context.Add(instructor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } PopulateAssignedCourseData(instructor); return(View(instructor)); }
public async Task <IActionResult> Create( [Bind("EnrollmentDate,FirstMidName,LastName,DepartmentID")] Student student) { try { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } PopulateDepartmentsDropDownList(student.DepartmentID); return(View(student)); }
public IActionResult EnrollStudent(EnrollStudentRequest request) { /* * { * "Studies": "Maths", * "firstname": "Jan", * "lastname": "Kowalski", * "birthdate": "1990-01-01T00:00:00", * "indexnumber": "10021" * } */ Studies study = (from studies in dbContext.Studies where studies.Name == request.Studies select studies).FirstOrDefault(); if (study == null) { return(BadRequest("Studia nie znalezione")); } Enrollment lastEnrollment = (from enrollments in dbContext.Enrollment orderby enrollments.IdEnrollment descending select enrollments).FirstOrDefault(); int idEnrollment; if (lastEnrollment == null) { idEnrollment = 1; } else { idEnrollment = lastEnrollment.IdEnrollment + 1; } Enrollment en = new Enrollment { IdEnrollment = idEnrollment, IdStudy = study.IdStudy, StartDate = DateTime.Now }; var studentExists = (from students in dbContext.Student where students.IndexNumber == request.IndexNumber select students).Any(); if (studentExists) { return(BadRequest($"Student z indeksem {request.IndexNumber} istnieje w bazie")); } Student st = new Student { IndexNumber = request.IndexNumber, FirstName = request.FirstName, LastName = request.LastName, BirthDate = request.Birthdate, Password = BCrypt.Net.BCrypt.HashPassword(request.Password), IdEnrollment = en.IdEnrollment }; dbContext.Add(en); dbContext.Add(st); dbContext.SaveChanges(); return(Created($"/enrollments/{en.IdEnrollment}", new { en.IdEnrollment, st.IndexNumber })); }