public async Task <IActionResult> Create([Bind("Id,Voornaam,Achternaam,Adres,Woonplaats")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        [ValidateAntiForgeryToken] // 跨站请求验证 很重要
        public async Task <IActionResult> Create(StudentDto dto)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var entity = new Student
                    {
                        RealName       = dto.RealName,
                        EnrollmentDate = dto.EnrollmentDate
                    };
                    _context.Add(entity);
                    await _context.SaveChangesAsync();

                    //return View(student);
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException)  // 这种异常DbUpdateException 是指数据有问题
            {
                ModelState.AddModelError("", "无法进行数据保存,请检查数据是否异常");
            }

            return(View(dto));
        }
        public async Task <IActionResult> Create([Bind("RealName,HireDate,OfficeAssignment")] Instructor instructor, string [] selectedCourses)
        {
            if (selectedCourses != null)
            {
                instructor.CourseAssignments = new List <CourseAssignment>();
                foreach (var courseId in selectedCourses)
                {
                    var course = new CourseAssignment
                    {
                        CourseId     = Convert.ToInt32(courseId),
                        InstructorId = instructor.Id
                    };
                    instructor.CourseAssignments.Add(course);
                }
            }

            if (ModelState.IsValid)
            {
                _context.Add(instructor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateAssignedCourseData(instructor);
            return(View(instructor));
        }
        public async Task <IActionResult> Create(StudentDto dto)
        {
            //CSRF参考资料:   http://www.freebuf.com/articles/web/55965.html


            try
            {
                if (ModelState.IsValid)
                {
                    var entity = new Student
                    {
                        RealName       = dto.RealName,
                        EnrollmentDate = dto.EnrollmentDate
                    };


                    _context.Add(entity);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException ex)
            {
                ModelState.AddModelError("", "无法进行数据的保存,请仔细检查你的数据,是否异常。");
            }

            return(View(dto));
        }
Beispiel #5
0
        public async Task <IdentityResult> CreateAsync(Users user, CancellationToken cancellationToken)
        {
            db.Add(user);

            await db.SaveChangesAsync(cancellationToken);

            return(await Task.FromResult(IdentityResult.Success));
        }
Beispiel #6
0
        public void CreateNotification(string type, Users notifier, Users notifiee)
        {
            Notification note = new Notification();

            note.IsRead    = 0;
            note.Type      = type;
            note.Notifiee  = notifiee;
            note.Timestamp = DateTime.Now;
            note.Notifier  = notifier;

            switch (type)
            {
            case "FriendRequest":
                if (notifier.FirstName == null || notifier.FirstName == "")
                {
                    note.Value = "" + notifier.Email + " has sent you a friend request.";
                }
                else
                {
                    note.Value = "" + notifier.FirstName + " has sent you a friend request.";
                }
                break;

            case "FriendAccepted":
                if (notifier.FirstName == null)
                {
                    note.Value = "" + notifier.Email + " has accepted your friend request.";
                }
                else
                {
                    note.Value = "" + notifier.FirstName + " has accepted your friend request.";
                }

                break;

            case "ReceiveMessage":
                if (notifier.FirstName == null)
                {
                    note.Value = "" + notifier.Email + " has sent you a message.";
                }
                else
                {
                    note.Value = "" + notifier.FirstName + " has sent you a message.";
                }

                break;

            default:
                note.Value = "Invalid notification type ";
                break;
            }

            _dbContext.Add(note);
            _dbContext.SaveChanges();
        }
        public async Task <IActionResult> Create([Bind("AdminId,Name,ExamDate,MarksSubmitDate,ResultPublishDate")] tblAdmin tblAdmin)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tblAdmin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tblAdmin));
        }
Beispiel #8
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,PhonePrimary,PhoneAlt,Fax,Email,Logo")] School school)
        {
            if (ModelState.IsValid)
            {
                _context.Add(school);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(school));
        }
        public async Task <IActionResult> Create([Bind("EnrollmentId,StudentId,CourseId,Grade")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(enrollment));
        }
Beispiel #10
0
        public async Task <IActionResult> Create([Bind("Id,UserName,UserType,Password")] tblLogin tblLogin)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tblLogin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tblLogin));
        }
Beispiel #11
0
        public async Task <IActionResult> Create([Bind("Id,Naam")] Cursus cursus)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cursus);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cursus));
        }
        public async Task <IActionResult> Create([Bind("ID,LastName,FirstMidName,EnrollmentDate")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Beispiel #13
0
        public async Task <IActionResult> Create([Bind("Student_Id,Name,address,PhoneNum,Avatar_Path")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("ExamId,Name")] tblExam tblExam)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tblExam);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tblExam));
        }
        public async Task <IActionResult> Create([Bind("Id,RealName,HireDate")] Instructor instructor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(instructor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(instructor));
        }
Beispiel #16
0
        public async Task <IActionResult> Create([Bind("ID,CourseCode,Technology,Price")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
        public async Task <IActionResult> Create(Cursist cursist)
        {
            if (ModelState.IsValid)
            {
                context.Add(cursist);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cursist));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,Credits")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Budget,StartDate,InstructorId,RowVersion")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.InstructorId = new SelectList(_context.Instructors, "Id", "RealName", department.InstructorId);
            return(View(department));
        }
Beispiel #20
0
        public async Task <IActionResult> Create([Bind("ClassId,Name,TeacherId")] Classes classes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(classes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TeacherId"] = new SelectList(_context.Teachers, "TeacherId", "TeacherId", classes.TeacherId);
            return(View(classes));
        }
Beispiel #21
0
        public async Task <IActionResult> Create([Bind("ParentId,PersonalDataId")] Parents parents)
        {
            if (ModelState.IsValid)
            {
                _context.Add(parents);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonalDataId"] = new SelectList(_context.PersonalDatas, "PersonalDataId", "FirstName", parents.PersonalDataId);
            return(View(parents));
        }
        public async Task <IActionResult> Create([Bind("CourseId,Title,Credits,Grade,DepartmentId")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "Id", course.DepartmentId);
            return(View(course));
        }
 public string UpdateStudent(Student student)
 {
     if (student.StudentId == 0)
     {
         schoolDbContext.Add <Student>(student);
     }
     else
     {
         schoolDbContext.Update <Student>(student);
     }
     schoolDbContext.SaveChanges();
     return("Operation Successful!");
 }
        public async Task <IActionResult> Create([Bind("Id,CursusId,CursistId,punten")] Inschrijving inschrijving)
        {
            if (ModelState.IsValid)
            {
                _context.Add(inschrijving);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.CursistId = new SelectList(_context.Cursisten, "Id", "Voornaam", inschrijving.CursistId);
            ViewBag.CursusId  = new SelectList(_context.Cursussen, "Id", "Naam", inschrijving.CursusId);
            return(View(inschrijving));
        }
 public IActionResult Create(Classe s)
 {
     if (ModelState.IsValid)
     {
         if (!_db.Classes.Any(p => p.id == s.id))
         {
             _db.Add(s);
             _db.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
     }
     return(View(s));
 }
Beispiel #26
0
        public async Task <IActionResult> Create([Bind("CourseID,StudentID")] Enrollments enrollments)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollments);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Courses, "ID", "ID", enrollments.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "ID", enrollments.StudentID);
            return(View(enrollments));
        }
        public async Task <IActionResult> Create([Bind("ID,StudentID,CourseID,Grade,Passed")] Transcripts transcripts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(transcripts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Courses, "ID", "ID", transcripts.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "ID", transcripts.StudentID);
            return(View(transcripts));
        }
Beispiel #28
0
        public async Task <int> CreateInstructorAndSaveAsync(InstructorAddEditDto dto)
        {
            int result;

            try
            {
                OfficeAssignment officeAssignment = null;
                if (!string.IsNullOrWhiteSpace(dto.OfficeLocation))
                {
                    officeAssignment = new OfficeAssignment
                    {
                        InstructorId = dto.InstructorId,
                        Location     = dto.OfficeLocation
                    };
                }

                List <CourseAssignment> courseAssignments = null;
                if (dto.CoursesAssigned != null)
                {
                    courseAssignments = new List <CourseAssignment>();
                    foreach (var courseId in dto.CoursesAssigned)
                    {
                        courseAssignments.Add(
                            new CourseAssignment
                        {
                            InstructorId = dto.InstructorId,
                            CourseId     = courseId
                        });
                    }
                }

                _context.Add(new Instructor
                {
                    InstructorId      = dto.InstructorId,
                    LastName          = dto.LastName,
                    FirstMidName      = dto.FirstMidName,
                    HireDate          = dto.HireDate,
                    OfficeAssignment  = officeAssignment,
                    CourseAssignments = courseAssignments
                });

                result = await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Failed to create new Instructor: {dto}");
                throw ex;
            }

            return(result);
        }
        public async Task <IActionResult> Create([Bind("CourseId,Title,Credits,DepartmentId")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateDepartmentsDropDownList();


            return(View(course));
        }
Beispiel #30
0
        public async Task <IActionResult> Create([Bind("ID,Name,Level,EnrollmentTerm,Course,CourseID")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            // model injection available in the create page; below is the old alternative to carrying course list
            //ViewData["Courses"] = await _context.Courses.Select(c => c).ToListAsync();

            return(View(student));
        }