コード例 #1
0
        public IActionResult Create()
        {
            var student = new StudentCreateVM();

            student.Colleges = dbContext.Colleges.ToList();
            return(View(student));
        }
コード例 #2
0
        // GET: Student/Create
        public ActionResult Create()
        {
            StudentCreateVM ViewModel = new StudentCreateVM();

            ViewModel.Schools    = ServiceSchool.GetSchools();
            ViewModel.Classrooms = ServiceClassroom.GetClassrooms();

            var a = ServiceSchool.GetSchools();

            return(View(ViewModel));
        }
コード例 #3
0
        public ActionResult Create()
        {
            Student         student        = new Student();
            StudentDetails  studentDetails = new StudentDetails();
            List <Grade>    grade          = mySqlContext.Grade.ToList();
            StudentCreateVM dynamicModel   = new StudentCreateVM();

            dynamicModel.Student        = student;
            dynamicModel.Grades         = grade;
            dynamicModel.StudentDetails = studentDetails;

            return(View(dynamicModel));
        }
コード例 #4
0
 public ActionResult Create(StudentCreateVM ViewModel)
 {
     if (ModelState.IsValid)
     {
         //We Need To Set Instance of School and Classroom at Student To be Created!
         ViewModel.Student.ClassroomFK = ViewModel.SelectedClassroomID;
         //Create User
         StudentServ.CreateStudent(ViewModel.Student);
         return(RedirectToAction("Index"));
     }
     //Refill Lists
     ViewModel.Schools    = ServiceSchool.GetSchools();
     ViewModel.Classrooms = ServiceClassroom.GetClassrooms();
     return(View(ViewModel));
 }
コード例 #5
0
ファイル: StudentService.cs プロジェクト: youlin1210/MySample
        public async Task <bool> AddStudentAsync(StudentCreateVM student)
        {
            var pairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("No", student.No),
                new KeyValuePair <string, string>("Name", student.Name),
                new KeyValuePair <string, string>("Gender", student.Gender),
            };

            var content = new FormUrlEncodedContent(pairs);

            var res = await _client.PostAsync("", content);

            return(res.IsSuccessStatusCode);
        }
コード例 #6
0
        public IActionResult Edit([FromForm] StudentCreateVM vm, int id)
        {
            var student = dbContext.Students
                          .Include(s => s.College)
                          .Where(s => s.Id == id).FirstOrDefault();

            if (vm.DisplayImage != null)
            {
                student.DisplayImage = fileService.Upload(vm.DisplayImage);
            }

            student.Name      = vm.Name;
            student.Roll_no   = vm.Roll_no;
            student.CollegeId = vm.SelectedCollegeId;
            dbContext.SaveChanges();
            TempData["editmessage"] = "Edited Successfully";
            return(RedirectToAction("Index"));
        }
コード例 #7
0
        public ActionResult Edit(int Id)
        {
            Student std = mySqlContext.Student.Include(x => x.Grade)
                          .Include(details => details.StudentDetails).FirstOrDefault(x => x.StudentId == Id);
            List <Grade>    grades       = mySqlContext.Grade.ToList();
            StudentCreateVM dynamicModel = new StudentCreateVM();

            dynamicModel.Student = std;
            dynamicModel.Grades  = grades;
            //dynamicModel.StudentDetails =
            //var anonymousObjResult = mySqlContext.Student
            //                .Where(st => st.StudentId == 1)
            //                .Select(st => new {
            //                    Id = st.StudentId,
            //                    Name = st.StudentName
            //                });

            return(View(dynamicModel));
        }
コード例 #8
0
        public ActionResult Create(StudentCreateVM studentmodel, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                var student = StudentVM.ToStudent(studentmodel);
                student.Password = studentmodel.Password;

                string   courseIdstring = collection["Course"];
                string[] courseArr      = courseIdstring.Split(',');

                if (courseArr.Length > 5)
                {
                    //throw new Exception("Cannot Select more than 5 course");
                    ModelState.AddModelError("", "Cannot Select more than 5 course");

                    List <string> gender = new List <string>();
                    gender.Add("Female");
                    gender.Add("Male");
                    var genderlist = new SelectList(gender);
                    ViewBag.Gender = genderlist;

                    List <Course> courses = courseservice.GetAll();
                    ViewBag.courses = new MultiSelectList(courses, "Id", "CourseName");


                    return(View());
                }
                else
                {
                    foreach (string str in courseIdstring.Split(','))
                    {
                        Course c = courseservice.GetById(Convert.ToInt32(str));
                        student.Courses.Add(c);
                    }

                    stdManagementService.Add(student);

                    return(RedirectToAction("Login", "Account"));
                }
            }

            return(View());
        }
コード例 #9
0
        public IActionResult Edit(int id)
        {
            var student = dbContext.Students
                          .Include(s => s.College)
                          .Where(s => s.Id == id).FirstOrDefault();

            if (student == null)
            {
                return(View());
            }
            var studentVm = new StudentCreateVM();

            studentVm.Id                = student.Id;
            studentVm.EditImagePath     = student.DisplayImage;
            studentVm.Name              = student.Name;
            studentVm.Roll_no           = student.Roll_no;
            studentVm.SelectedCollegeId = student.College.Id;
            studentVm.Colleges          = dbContext.Colleges.ToList();
            return(View(studentVm));
        }
コード例 #10
0
        public IActionResult Create([FromForm] StudentCreateVM vm)
        {
            if (ModelState.IsValid)
            {
                Student student = new Student()
                {
                    DisplayImage = vm.DisplayImage.FileName,
                    Name         = vm.Name,
                    Roll_no      = vm.Roll_no,
                    CollegeId    = vm.SelectedCollegeId,
                };
                var fileName = fileService.Upload(vm.DisplayImage);
                student.DisplayImage = fileName;
                getpath = fileName;

                dbContext.Add(student);
                dbContext.SaveChanges();
                TempData["message"] = "Successfully Added";
            }
            return(RedirectToAction("Index"));
        }
コード例 #11
0
        public IActionResult Create(StudentCreateVM studentCreateModel)
        {
            ModelStateDictionary modelState = ModelState;

            if (modelState.IsValid)
            {
                var student = new Student();

                student.Forename      = studentCreateModel.Forename;
                student.Surname       = studentCreateModel.Surname;
                student.DOB           = (DateTime)studentCreateModel.DOB;
                student.TeachingGroup = _teachingGroupService
                                        .GetById(studentCreateModel.TeachingGroup.Id);
                student.Gender = studentCreateModel.Gender;

                _studentService.Add(student);
                _studentService.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Edit"));
        }