Ejemplo n.º 1
0
        public async Task <ActionResult> Create(CreateStudentViewModel student)
        {
            if (ModelState.IsValid)
            {
                Student newStudent = new Student()
                {
                    Name             = student.Name,
                    LastName         = student.LastName,
                    FatherName       = student.FatherName,
                    PhoneNumber      = student.PhoneNumber,
                    DateOfBirthday   = student.DateOfBirthday,
                    TrialDate        = student.TrialDate,
                    ParentName       = student.ParentName,
                    ParentLastName   = student.ParentLastName,
                    ParentFatherName = student.ParentFatherName
                };
                var studentId = await _studentService.CreateAsyncReturnId(student);

                if (student.Comment != null)
                {
                    Comment comment = new Comment
                    {
                        StudentId = studentId,
                        Text      = student.Comment,
                        Create    = DateTime.Now
                    };
                    await _commentService.CreateAsync(comment);
                }

                return(RedirectToAction(nameof(SelectLeadStudents)));
            }

            return(View(student));
        }
        public async Task <IActionResult> Create(CreateStudentViewModel model)
        {
            // If statment saying only continue if the required fields are filled out meaning the ModelState is Valid
            if (ModelState.IsValid)
            {
                // Telling the Database Interface to Add the Student from the view model to the database
                _context.Add(model.Student);

                // A foreach looping through the SelectedExercises to create the instances of the StudentExercise for every one in the list. Then adding them to the database. The foreach works because each entry in the list is an int representing the exerciseId then it takes the student Id from the created student in the model to make the StudentExercise. Needs to be in an if statement so a person can create a student not assign them an exercise.
                if (model.SelectedExercises != null)
                {
                    foreach (int exerciseId in model.SelectedExercises)
                    {
                        StudentExercise newSE = new StudentExercise()
                        {
                            StudentId  = model.Student.StudentId,
                            ExerciseId = exerciseId
                        };
                        _context.Add(newSE);
                    }
                }
                // wait for changes before commiting them to the database. This is like how copy works. Add is like copying something to the clipboard but to put it somewhere you need to paste which is the SaveChangesAsync part.
                await _context.SaveChangesAsync();

                // Once the new Student is created and saved redirect to the index view
                return(RedirectToAction(nameof(Index)));
            }
            // Getting the data from the database needed to make the list of cohorts to choose from. Only need if you don't do it in the view model which we did so this is not needed.
            // ViewData["CohortId"] = new SelectList(_context.Cohorts, "CohortId", "Name", model.Student.CohortId);
            return(View(model));
        }
Ejemplo n.º 3
0
 public IActionResult Register(CreateStudentViewModel model)
 {
     if (ModelState.IsValid)
     {
         string  uniqueFileName = UploadedFile(model);
         Student student        = new Student()
         {
             Age             = model.Age,
             City            = model.City,
             ConfirmPassword = model.ConfirmPassword,
             Country         = model.Country,
             Email           = model.Email,
             FirstName       = model.FirstName,
             gender          = model.gender,
             LastName        = model.LastName,
             Password        = model.Password,
             ProfileImg      = uniqueFileName,
         };
         _db.AddStudent(student);
         return(View("Login"));
     }
     else
     {
         return(View());
     }
 }
        // GET: Students/Create
        public IActionResult Create()
        {
            // ViewData["CohortId"] = new SelectList(_context.Cohorts, "CohortId", "Name");
            CreateStudentViewModel model = new CreateStudentViewModel(_context);

            return(View(model));
        }
        // Add, Edit, and Delete Student methods
        public void AddStudent(CreateStudentViewModel studentVM)
        {
            var student = studentVM.ToStudent();

            context.Students.Add(student);
            Save();
        }
Ejemplo n.º 6
0
        public IActionResult Create(CreateStudentViewModel model)
        {
            ViewData["ReturnUrl"] = ReturnUrl;
            PopulateGrades();
            PopulateStudents();
            PopulateParents();
            if (ModelState.IsValid)
            {
                var userId = this.userManager.GetUserId(this.User);

                var student = new Student
                {
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    Stud_Email   = model.Stud_Email,
                    Parent_Email = model.Parent_Email,
                    Class_Id     = model.Class_Id,
                    Active       = model.Active,
                    Created_At   = DateTime.UtcNow,
                    Created_By   = userId,
                    Updated_By   = null,
                };

                db.Student.Add(student);
                db.SaveChanges();
                return(RedirectToAction("List", "Student"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 7
0
        public ActionResult CreateSudent()
        {
            CreateStudentViewModel model = new CreateStudentViewModel();

            if (GetMyRoles() != null || GetMyRoles().Contains("admin") || GetMyRoles().Contains("dephead") || GetMyRoles().Contains("personal"))
            {
                ApplicationDbContext dbContext = new ApplicationDbContext();
                List <Group>         listGroup = new List <Group>();
                listGroup = dbContext.Groups.Where(x => x.isActive).ToList();
                if (listGroup.Count == 0)
                {
                    ViewBag.Success = false;
                    ViewBag.Message = "Вы не можете создать студента, так как группы еще не добавили";
                    return(View("Result"));
                }
                foreach (var item in listGroup)
                {
                    model.GroupDropdownData.Add(new SelectListItem {
                        Text = item.Name + "(" + item.Stage + "курс)", Value = item.Id.ToString()
                    });
                }
            }
            else
            {
                ViewBag.Success = false;
                ViewBag.Message = "У вас нет доступа";
                return(View("Result"));
            }
            return(View(model));
        }
        public async Task <ActionResult> Edit(int id, CreateStudentViewModel studentViewModel)
        {
            var temp = await _studentService.FindById(id);

            var existingCode = await _studentService.FindByCode(studentViewModel.Account);

            if (existingCode == null || existingCode.Account == temp.Account)
            {
                var student = new UpdateStudentDto
                {
                    Account       = studentViewModel.Account,
                    Email         = studentViewModel.Email,
                    Campus        = studentViewModel.Campus,
                    FirstName     = studentViewModel.FirstName,
                    SecondName    = studentViewModel.SecondName,
                    FirstSurname  = studentViewModel.FirstSurname,
                    SecondSurname = studentViewModel.SecondSurname,
                    Careers       = studentViewModel.Careers,
                    Settlement    = studentViewModel.Settlement,
                    Id            = id
                };
                await _studentService.Update(id, student);

                return(Ok());
            }
            else
            {
                return(BadRequest("Ya existe un Estudiante con este numero de Cuenta"));
            }
        }
Ejemplo n.º 9
0
        public ActionResult Create(CreateStudentViewModel student)
        {
            var input = new StudentInputRegister
            {
                Address   = student.Address,
                Birthdate = student.Birthdate,
                City      = student.City,
                Country   = student.Country,
                CourseId  = student.SelectedCourse,
                CPF       = student.CPF,
                Email     = student.Email,
                FirstName = student.FirstName,
                Gender    = student.Gender,
                LastName  = student.LastName,
                Phone     = student.Phone
            };
            var result = _studentCommand.Handle(input);

            if (!result.IsValid)
            {
                foreach (var n in result.Notifications)
                {
                    ModelState.AddModelError(n.Key, n.Value);
                }
                student.Courses = GetComboboxCourse();
                return(View(student));
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 10
0
        public ActionResult Create(CreateStudentViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Student student = new Student
                    {
                        LastName      = model.LastName,
                        FirstMidName  = model.FirstMidName,
                        EnrolmentDate = model.EnrolmentDate
                    };

                    db.Students.Add(student);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(model));
        }
Ejemplo n.º 11
0
        public IActionResult Create(CreateStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                string  uniqueFileName = ProcessFileUpload(model);
                Student student        = new Student()
                {
                    firstName   = model.FirstName,
                    middleName  = model.MiddleName,
                    lastName    = model.LastName,
                    email       = model.Email,
                    age         = model.Age,
                    entryYear   = model.EntryYear,
                    birthDate   = model.BirthDate,
                    grade       = model.Grade,
                    phoneNumber = model.PhoneNumber,
                    season      = model.Semester,
                    gender      = model.Gender,
                    photoPath   = uniqueFileName,
                    address     = model.Address,
                    city        = model.City,
                    state       = model.State
                };
                _studentRepository.AddStudent(student);

                return(RedirectToAction("Details", "Home", new { id = student.id }));
            }
            return(View(model));
        }
        public async Task <ActionResult> Create(CreateStudentViewModel studentViewModel)
        {
            var existingCode = await _studentService.FindByCode(studentViewModel.Account);

            if (existingCode == null)
            {
                var student = new CreateStudentDto
                {
                    Account       = studentViewModel.Account,
                    FirstName     = studentViewModel.FirstName,
                    SecondName    = studentViewModel.SecondName,
                    FirstSurname  = studentViewModel.FirstSurname,
                    SecondSurname = studentViewModel.SecondSurname,
                    Campus        = studentViewModel.Campus,
                    Careers       = studentViewModel.Careers,
                    Settlement    = studentViewModel.Settlement,
                    Email         = studentViewModel.Email
                };

                await _studentService.Create(student);

                return(Ok());
            }
            else
            {
                return(BadRequest("Ya existe un Estudiante con este numero de Cuenta"));
            }
        }
        public async Task <IActionResult> Create(CreateStudentViewModel model)
        {
            if (ModelState.IsValid)
            { //goes to database-please add student
                _context.Add(model.Student);
                //for each student add the students exercises-contains the ids of the exercises
                //for each id we put in the join table for exercises is joined wit hthat student
                foreach (int exerciseId in model.SelectedExercises)
                {
                    StudentExercise newSE = new StudentExercise()
                    {
                        StudentId  = model.Student.StudentId,
                        ExerciseId = exerciseId
                    };
                    //last step added to databse
                    //inserting the joiner table-shown above with studentid and exercise id
                    _context.Add(newSE);
                }
                //add says I WANT to insert this int othe data base-and as soon as I call save changes it is
                //actually entered into the database-similar to write changes in DB broswer
                await _context.SaveChangesAsync();

                //redirects you to the index html
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CohortId"] = new SelectList(_context.Cohorts, "CohortId", "Name", model.Student.CohortId);
            return(View(model));
        }
Ejemplo n.º 14
0
        public ActionResult SaveStudent([ModelBinder(typeof(MyStudentModelBinder))] StudentModel e, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
            case "Save":
                if (ModelState.IsValid)
                {
                    StudentBusinessLayer stubal = new StudentBusinessLayer();
                    stubal.Savestudent(e);
                    //return Content(e.FirstName + "|" + e.LastName + "|" + e.Age);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //return View("CreateStudent");
                    CreateStudentViewModel csm = new CreateStudentViewModel();
                    csm.FirstName = e.FirstName;
                    csm.LastName  = e.LastName;
                    if (e.Age > 0)
                    {
                        csm.Age = e.Age;
                    }
                    else
                    {
                        csm.Age = 0;
                    }
                    return(View("CreateStudent", csm));
                }

            case "Cancel":
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
Ejemplo n.º 15
0
 public ActionResult Create()
 {
     if (User.IsInRole("Administrator"))
     {
         MembershipUserCollection users = Membership.GetAllUsers();
         var model = new CreateStudentViewModel
         {
             Users = users.OfType <MembershipUser>().Select(x => new SelectListItem
             {
                 Value = x.UserName,
                 Text  = x.UserName,
             })
         };
         return(View(model));
     }
     if (User.IsInRole("Default"))
     {
         MembershipUserCollection users = Membership.FindUsersByName(User.Identity.Name);
         var model = new CreateStudentViewModel
         {
             Users = users.OfType <MembershipUser>().Select(x => new SelectListItem
             {
                 Value = x.UserName,
                 Text  = x.UserName,
             })
         };
         return(View(model));
     }
     return(View(/*user has a role that is not "Default" or "Administrator"  Needs error message*/));
 }
        public ActionResult Create(CreateStudentViewModel student)
        {
            if (ModelState.IsValid)
            {
                Lecture thisLecture = _lectureService.GetLecture(student.Lecture_Key);
                if (thisLecture != null)
                {
                    Student s = new Student
                    {
                        Lecture_ID   = thisLecture.ID,
                        Compeny      = student.Compeny,
                        Employee_ID  = student.Employee_ID,
                        Birthday     = student.Birthday,
                        Email        = student.Email,
                        Gender       = (int)student.Gender,
                        Name         = student.Name,
                        Phone_Number = student.Phone_Number,
                        CreateDate   = DateTime.Now,
                        Key          = Guid.NewGuid()
                    };
                    _studentService.Add(s);
                    _unitOfWork.Commit();

                    return(RedirectToAction("Index1", "Question", new { ID = 1, key = s.Key }));
                }
            }
            ViewBag.Lecture_Key = student.Lecture_Key;
            return(View(student));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Create(CreateStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                _context.Add(model.Student);

                if (model.SelectedExercises != null)
                {
                    foreach (int exerciseId in model.SelectedExercises)
                    {
                        StudentExercise newSE = new StudentExercise()
                        {
                            StudentId  = model.Student.StudentId,
                            ExerciseId = exerciseId
                        };
                        _context.Add(newSE);
                    }
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CohortId"] = new SelectList(_context.Cohorts, "CohortId", "Name", model.Student.CohortId);
            return(View(model));
        }
        public async Task <IActionResult> Create(CreateStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                // insert new student into db
                _context.Add(model.Student);

                // loop over each selected exercise
                foreach (int exerciseId in model.SelectedExercises)
                {
                    // create a new instance of StudentExercise for each selected exercise
                    StudentExercise newSE = new StudentExercise()
                    {
                        StudentId  = model.Student.StudentId,
                        ExerciseId = exerciseId
                    };
                    // insert each selected exercise to the StudentExercise join table in db
                    _context.Add(newSE);
                }
                // once complete with db updates, save changes to the db
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CohortId"] = new SelectList(_context.Cohorts, "CohortId", "Name", model.Student.CohortId);
            return(View(model));
        }
        public async Task <IActionResult> Create(CreateStudentViewModel model)
        {
            // Create the student
            await _studentService.CreateAsync(model.Name);

            // Redirect back to the list
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 20
0
        //// GET: Student/Create
        public PartialViewResult Create()
        {
            var model = new CreateStudentViewModel();

            model.StudentNumber = GetUniqueNumber();
            ViewData["ClassId"] = new SelectList(cls.GetForDropDown(), "Id", "Name");
            return(PartialView(model));
        }
        public async Task <IActionResult> Post(CreateStudentViewModel student)
        {
            Logger.Debug($"Post called with {student.Name}.");

            Guid id = await studentService.CreateAsync(mapper.Map <CreateStudentModel>(student));

            return(StatusCode(StatusCodes.Status201Created, id));
        }
 public ActionResult Create([Bind(Include = "StudentID, StudentName, ClassID")] CreateStudentViewModel vm)
 {
     if (ModelState.IsValid)
     {
         repo.AddStudent(vm);
         return(RedirectToAction("Index"));
     }
     return(View(vm));
 }
        // Student ViewModels
        public CreateStudentViewModel GetCreateStudentViewModel()
        {
            var vm = new CreateStudentViewModel
            {
                Classes = new SelectList(GetAllClasses(), "ClassID", "ClassName")
            };

            return(vm);
        }
Ejemplo n.º 24
0
        // GET: Student/Create
        public ActionResult Create()
        {
            var createStudentViewModel = new CreateStudentViewModel
            {
                Levels = new SelectList(_studentService.GetAllLevel(), "Id", "Name")
            };

            return(View(createStudentViewModel));
        }
        public ActionResult Add(CreateStudentViewModel model)
        {
            var faculty = _facultyManager.ReadFaculty(model.FacultyAlias);

            model.Student.FacultyRefId = faculty.Id;
            model.Student.Faculty = faculty;
            _objectFactory.GetRepositoryInstance<Student>().Add(model.Student);
            _objectFactory.Commit();
            return RedirectToAction("Index");
        }
Ejemplo n.º 26
0
        // GET: Students/Create
        public ActionResult Create()
        {
            // Create a new instance of a CreateStudentViewModel
            // If we want to get all the cohorts, we need to use the constructor that's expecting a connection string.
            // When we create this instance, the constructor will run and get all the cohorts.
            CreateStudentViewModel studentViewModel = new CreateStudentViewModel(_config.GetConnectionString("DefaultConnection"));

            // Once we've created it, we can pass it to the view
            return(View(studentViewModel));
        }
        // GET: Students/Create
        public IActionResult Create()
        {
            CreateStudentViewModel newStudent = new CreateStudentViewModel()
            {
                DanceTypes  = new SelectList(_context.DanceTypes, "Id", "Name"),
                SkillLevels = new SelectList(_context.SkillLevels, "Id", "Level")
            };


            return(View(newStudent));
        }
        public ActionResult Create(CreateStudentViewModel viewModel)
        {
            var request = new StudentCreate.Request(SystemPrincipal.Name, viewModel.CommandModel);
            var response = DomainServices.Dispatch(request);

            if (!response.HasValidationIssues)
                return RedirectToAction("Index");

            ModelState.AddRange(response.ValidationDetails);
            return View(viewModel);
        }
Ejemplo n.º 29
0
        public async Task CreateStudentAsync(CreateStudentViewModel createStudentViewModel)
        {
            string jsonStringBody = JsonSerializer.Serialize(createStudentViewModel);

            using StringContent content = new StringContent(jsonStringBody, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _httpClient.PostAsync("student/create-student", content);

            if (!response.IsSuccessStatusCode)
            {
                throw new ApplicationException($"{response.ReasonPhrase}: The status code is: {(int)response.StatusCode}");
            }
        }
Ejemplo n.º 30
0
        // GET: Student/Create
        public ActionResult Create()
        {
            if (!UserIsInRole("Admin"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            var student = new CreateStudentViewModel
            {
                Courses = GetComboboxCourse()
            };

            return(View(student));
        }
 public ActionResult Add()
 {
     var faculties = _objectFactory.GetRepositoryInstance<Faculty>().GetAll().ToList();
     var model = new CreateStudentViewModel()
     {
         AllFaculties = faculties.Select(x => new SelectListItem()
         {
             Text = x.Name,
             Value = x.Name
         }).ToList()
     };
     return View(model);
 }
Ejemplo n.º 32
0
        public ActionResult Create(CreateStudentViewModel viewModel)
        {
            var request  = new StudentCreate.Request(SystemPrincipal.Name, viewModel.CommandModel);
            var response = DomainServices.Dispatch(request);

            if (!response.HasValidationIssues)
            {
                return(RedirectToAction("Index"));
            }

            ModelState.AddRange(response.ValidationDetails);
            return(View(viewModel));
        }
Ejemplo n.º 33
0
 public ActionResult Create(CreateStudentViewModel viewmodel)
 {
     try
     {
         uow.Student.Add(viewmodel.Student);
         uow.Commit();
         return(RedirectToAction("Index", "Department"));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError(string.Empty, ex.Message);
         return(RedirectToAction("Create"));
     }
 }