public async Task <IActionResult> RegisterStudentAsync([FromForm] RegisterStudentViewModel studentView)
        {
            var student = StudentMapper.ToActualObjectNoId(studentView);
            RegisterViewModel registration = new RegisterViewModel
            {
                Email           = studentView.Email,
                Password        = studentView.Password,
                ConfirmPassword = studentView.ConfirmPassword
            };

            IdentityResult result = await _userManager.CreateAsync(new ApplicationUser { Email = registration.Email, UserName = registration.Email }, registration.Password);

            if (result.Succeeded)
            {
                var studentUserManager = await _userManager.FindByEmailAsync(registration.Email);

                var roleStudent = await _roleManager.FindByNameAsync("Student");

                await _userManager.AddToRoleAsync(studentUserManager, roleStudent.Name);

                student.IdUser = studentUserManager.Id;
                _studentService.AddStudent(student);

                if (studentView.Cv != null)
                {
                    _studentService.UploadCV(student.IdUser, studentView.Cv);
                }

                return(Ok());
            }
            return(BadRequest());
        }
Esempio n. 2
0
        public ActionResult RegisterStudent(int?courseId)
        {
            //create instance of the database &role store & role manager
            //so we can show the roles in the dropdown list t create the user
            var userdb = ApplicationDbContext.Create();
            IQueryable <Course> courseList = null;

            if (courseId != null)
            {
                courseList = userdb.Courses.Where(sa => sa.Id == courseId);
            }
            else
            {
                courseList = userdb.Courses.Where(sa => sa.EndDate > DateTime.Today);
            }
            //Show courses list

            List <SelectListItem> courseListWithDefault = courseList.Select(course => new SelectListItem {
                Text = course.Name, Value = course.Id.ToString()
            }).ToList();
            var courseTip = new SelectListItem {
                Value = null,
                Text  = "--- Select Course---"
            };

            courseListWithDefault.Insert(0, courseTip);

            //create a template of the user registert view model and set its properties{lists} our we created
            var template = new RegisterStudentViewModel {
                Courses = courseListWithDefault
            };

            return(View(template));
        }
Esempio n. 3
0
        public ActionResult RegisterStudent(RegisterStudentViewModel model)
        {
            //extract data from model to login table
            var login = new Login();

            login.Adress      = model.Adress;
            login.Description = model.Description;
            login.Email       = model.Email;
            login.imageUrl    = model.imageUrl;
            login.Name        = model.Name;
            login.Password    = model.Password;
            login.phone       = model.phone;
            login.userType    = model.userType;
            //extract data from model to Student table
            var student = new Student();

            student.Adress      = login.Adress;
            student.Description = login.Description;
            student.Email       = login.Email;
            student.imageUrl    = login.imageUrl;
            student.Name        = login.Name;
            student.Password    = login.Password;
            student.phone       = login.phone;
            LoginServices.Instance.SaveLogin(login);
            StudentServices.Instance.SaveStudent(student);
            return(View());
        }
        public async Task <IActionResult> RegisterNewStudent(RegisterStudentViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var newUser = new IdentityUser()
                {
                    Email = viewModel.Email, UserName = viewModel.Email
                };
                var result = await _userManager.CreateAsync(newUser, viewModel.Password);

                if (result.Succeeded)
                {
                    Student newStudent = new Student()
                    {
                        Year = viewModel.Year, AppUserId = newUser.Id
                    };
                    _dbContext.Students.Add(newStudent);
                    _dbContext.SaveChanges();
                    await _userManager.AddToRoleAsync(newUser, "StudentRole");

                    await _signInManager.SignInAsync(newUser, true);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }
            return(View(viewModel));
        }
        public IActionResult Register(RegisterStudentViewModel model)
        {
            model.Faculties = _context.Faculties.ToList();
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var transaction = _context.Database.BeginTransaction())
            {
                var matchedUser = _context.Users
                                  .FirstOrDefault(u => (u.Email == model.User.Email));
                if (matchedUser != null)
                {
                    ViewData["Message"] = "Taki u¿ytkownik istnieje ju¿ w systemie!";
                    return(View(model));
                }

                model.User.Password = GetSha256FromString(model.User.Password);

                _context.Users.Add(model.User);
                _context.SaveChanges();

                model.Student.UserId = model.User.Id;
                _context.Students.Add(model.Student);
                _context.SaveChanges();

                transaction.Commit();
                HttpContext.Session.SetString("UserRole", "student");
            }
            TempData["Message"] = "Pomyœlnie zarejestrowano";

            return(RedirectToAction("Login", "Authentication"));
        }
Esempio n. 6
0
        public ViewResult Register(Student student)
        {
            RegisterStudentViewModel viewModel = new RegisterStudentViewModel
            {
                Departments = DepartmentGateway.GetAllDepartments()
            };

            if (ModelState.IsValid)
            {
                StudentGateway sg = new StudentGateway();

                string registrationNumber = GetRegistrationNumber(student);

                int rowAffected = sg.Save(student, registrationNumber);

                if (rowAffected > 0)
                {
                    ViewBag.Message = "Saved";
                }
                else
                {
                    ViewBag.Message = "Error";
                }

                return(View(viewModel));
            }

            // Model state is not valid
            viewModel.Student = student;

            return(View(viewModel));
        }
        public async Task <IActionResult> RegisterNewStudent(RegisterStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser()
                {
                    Email = model.Email, UserName = model.StudentName
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    Student newStudent = new Student()
                    {
                        Age = model.Age, AppUserId = user.Id, StudentName = model.StudentName
                    };
                    _dbContext.Students.Add(newStudent);
                    _dbContext.SaveChanges();
                    await _userManager.AddToRoleAsync(user, "studentRole");

                    await _signInManager.SignInAsync(user, true);

                    return(RedirectToAction("index", "home"));
                }
            }
            return(View(model));
        }
        public RegisterStudentViewModel GetRegisterStudentViewModelWithBasicData()
        {
            var semesters     = _unitOfWork.Semesters.GetAll();
            var fieldsOfStudy = _unitOfWork.FieldsOfStudy.GetAll();

            var semestersSelectList = semesters.Select(semester => new SelectListItem()
            {
                Value = semester.SemesterId.ToString(),
                Text  = semester.Semester1
            }).ToList();

            var fieldsOfStudySelectList = fieldsOfStudy.Select(fieldOfStudy => new SelectListItem()
            {
                Value = fieldOfStudy.FieldOfStudyId.ToString(),
                Text  = fieldOfStudy.FieldOfStudy,
            }).ToList();

            var model = new RegisterStudentViewModel()
            {
                FieldsOfStudy = fieldsOfStudySelectList,
                Semesters     = semestersSelectList,
            };

            return(model);
        }
Esempio n. 9
0
        public async Task <IActionResult> RegisterStudent([FromBody] RegisterStudentViewModel registerStudent)
        {
            List <string> errorList       = new List <string>();
            var           applicationUser = new ApplicationUser
            {
                Email         = registerStudent.Email,
                UserName      = registerStudent.UserName,
                SecurityStamp = Guid.NewGuid().ToString(),
                Department    = registerStudent.Department,
                StudyYear     = registerStudent.StudyYear.ToString()
            };

            var result = await _userManager.CreateAsync(applicationUser, registerStudent.Password);

            if (result.Succeeded)
            {
                await _userManager.AddToRolesAsync(applicationUser, new List <string> {
                    "User", "Student", "Developer"
                });

                //Return successful
                return(Ok(
                           new { username = applicationUser.UserName, email = applicationUser.Email, status = 1, message = "Register Successfully" }
                           ));
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                    errorList.Add(error.Description);
                }
            }
            return(BadRequest(errorList));
        }
Esempio n. 10
0
        public async Task <ActionResult> RegisterStudent(RegisterStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var student = new Student()
                    {
                        UserId = user.Id, Name = model.Name, BirthDate = model.BirthDate, PreviousEducation = model.PreviousEducation, PreviousEducationDetail = model.PreviousEducationDetail, CourseId = model.CourseId
                    };
                    UserManager.AddToRole(user.Id, "Student");
                    _db.Student.Add(student);
                    _db.SaveChanges();
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public IActionResult Register()
        {
            var model = new RegisterStudentViewModel();

            model.Faculties = _context.Faculties.ToList();

            return(View(model));
        }
Esempio n. 12
0
        public ActionResult RegisterStudent()
        {
            var registrationStudentViewModel = new RegisterStudentViewModel()
            {
                Courses = _db.Course.ToList()
            };

            return(View(registrationStudentViewModel));
        }
Esempio n. 13
0
        // GET: Student
        public ViewResult Register()
        {
            RegisterStudentViewModel viewModel = new RegisterStudentViewModel
            {
                Departments = DepartmentGateway.GetAllDepartments()
            };

            return(View(viewModel));
        }
Esempio n. 14
0
        public ActionResult RegisterStudent()
        {
            //Data data = new Data();
            RegisterStudentViewModel model = new RegisterStudentViewModel();

            //model.Versions = _dbContext.Versions.ToList();
            //model.Classes = _dbContext.Classes.ToList();

            return(View(model));
        }
Esempio n. 15
0
        public IActionResult StudentRegister()
        {
            RegisterStudentViewModel model = new RegisterStudentViewModel
            {
                GroupItems = populateGroups(),
                Birthday   = DateTime.Now
            };

            return(View(model));
        }
Esempio n. 16
0
 public ActionResult RegisterStudent(RegisterStudentViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     else
     {
         return(FinishResigration(new RegisterViewModel(model)));
     }
 }
Esempio n. 17
0
        public ActionResult RegisterStudent(RegisterStudentViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Something went wrong, check correctness of the data!");
                return(View());
            }

            TempData["Message"] = _accountService.SaveStudent(viewModel);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 18
0
        public IActionResult CreateStudent()
        {
            RegisterStudentViewModel model = new RegisterStudentViewModel
            {
                GroupItems = PopulateGroups(),
                Birthday   = DateTime.Now
            };

            ViewData["Title"] = "Добавление студента";

            return(View(model));
        }
 public static Student ToActualObjectNoId(RegisterStudentViewModel studentViewModel)
 {
     return(new Student()
     {
         Firstname = studentViewModel.Firstname,
         Lastname = studentViewModel.Lastname,
         University = studentViewModel.University,
         Specialization = studentViewModel.Specialization,
         College = studentViewModel.College,
         Year = studentViewModel.Year,
     });
 }
Esempio n. 20
0
        public RedirectToRouteResult RegisterStudent(RegisterStudentViewModel model)
        {
            Login login = new Login(model.Id, model.Password, true, false, false, "");
            Dictionary <string, BlockChain> subjects = new Dictionary <string, BlockChain>();
            Student student = new Student(model.FullName, model.Faculty, model.Cathedra, model.Course, model.Group, model.Id, model.Email, subjects);

            _dbContext.SetStudent(student);
            _dbContext.SetLogin(login);
            return(RedirectToRoute(new {
                controller = "Admin",
                action = "RegisteredSuccessful"
            }));
        }
Esempio n. 21
0
        public bool Register(RegisterStudentViewModel vm)
        {
            Student student = Mapper.Instance.Map <RegisterStudentViewModel, Student>(vm);

            if (this.Context.Students.Any(name => name.Username == vm.Username))
            {
                return(false);
            }
            else
            {
                this.Context.Students.Add(student);
                this.Context.SaveChanges();
                return(true);
            }
        }
Esempio n. 22
0
        public async Task <IActionResult> StudentRegister(RegisterStudentViewModel registerUserViewModel)
        {
            /* Console.WriteLine("GroupId = " + registerUserViewModel.GroupId);
             * Console.WriteLine("Name = " + registerUserViewModel.Name);*/

            registerUserViewModel.GroupItems = populateGroups();

            if (_databaseWorker.GroupExists(registerUserViewModel.GroupId))
            {
                if (ModelState.IsValid)
                {
                    IdentityResult result = await _authentication.CreateUserAsync(registerUserViewModel);

                    if (result.Succeeded)
                    {
                        User user = await _authentication.FindUserByEmailAsync(registerUserViewModel.Email);

                        if (!await _authentication.CreateStudentUserAsync(user.Id, registerUserViewModel.GroupId))
                        {
                            await _authentication.DeleteUserAsync(user);

                            return(View(registerUserViewModel));
                        }

                        // установка куки
                        await _authentication.SignInAsync(user);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        foreach (var error in result.Errors)
                        {
                            ModelState.AddModelError(string.Empty, error.Description);
                        }
                    }
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Choosen Group does not exists!");
            }


            Console.WriteLine("is not valid or upper else group does not exists!");

            return(View(registerUserViewModel));
        }
Esempio n. 23
0
        public ActionResult RegisterStudent(RegisterStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser();
                user.UserName             = model.PhoneNumber;
                user.PhoneNumber          = model.PhoneNumber;
                user.PhoneNumberConfirmed = true;

                var result = UserManager.Create(user, model.Password);
                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Student");

                    StudentProfile student = new StudentProfile();
                    student.Name             = model.Name;
                    student.PhoneNumber      = model.PhoneNumber;
                    student.ParmanentAddress = model.PermanentAddress;
                    student.PresentAddress   = model.PresentAddress;
                    student.InstituteName    = model.InstituteName;
                    student.FatherName       = model.FatherName;
                    student.FatherOccupation = model.FatherOccupation;
                    student.RegisterDate     = DateTime.Now;
                    student.Version          = model.Version;
                    student.Class            = model.Class;
                    student.UserId           = user.Id;

                    _dbContext.StudentProfiles.Add(student);
                    _dbContext.SaveChanges();
                    SignInManager.SignIn(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    //string msg = "Registration successful. Please log in to continue.";
                    string msg = "";


                    return(RedirectToAction("Index", "Home", new { message = msg }));
                }
                AddErrors(result);
            }

            return(View(model));
        }
Esempio n. 24
0
        private RegisterStudentViewModel PopulateStudentRegisterViewModel()
        {
            List <IdentityRole>      roles;
            RegisterStudentViewModel viewModel = new RegisterStudentViewModel();

            using (var db = new ApplicationDbContext())
            {
                var roleStore = new RoleStore <IdentityRole>(db);
                var roleMngr  = new RoleManager <IdentityRole>(roleStore);
                roles = roleMngr.Roles.ToList();
            }

            ViewBag.Roles = new SelectList(roles, "Name", "Name");

            return(viewModel);
        }
Esempio n. 25
0
        public async Task <IActionResult> RegisterStudent(RegisterStudentViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName           = model.Email,
                    FirstName          = model.FirstName,
                    LastName           = model.LastName,
                    RegistrationNumber = model.RegistrationNumber,
                    Group = model.Group,
                    Email = model.Email
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var result2 = await _userManager.AddToRoleAsync(user, UserRoles.Student.ToString());

                    if (result2.Succeeded)
                    {
                        _logger.LogInformation("User created a new account with password.");

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                        await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                        //await _signInManager.SignInAsync(user, isPersistent: false);

                        _logger.LogInformation("User created a new account with password.");

                        return(RedirectToLocal(returnUrl));
                    }
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 26
0
        public async Task <ActionResult> RegisterStudent(RegisterStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user   = new ApplicationUser(model);
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", new { studentsOnly = true, courseId = model.CourseId }));
                }
                AddErrors(result);
            }
            MakeBreadCrumbs();
            // If we got this far, something failed, redisplay form
            ViewBag.CourseId = new SelectList(db.Courses, "Id", "Name");
            return(View(model));
        }
Esempio n. 27
0
        public async Task <ActionResult> RegisterStudent(RegisterStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await UserManager.AddToRoleAsync(user.Id, model.UserRole);

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }



                AddErrors(result);
            }

            List <IdentityRole>      roles;
            RegisterStudentViewModel viewModel = new RegisterStudentViewModel();

            using (var db = new ApplicationDbContext())
            {
                var roleStore = new RoleStore <IdentityRole>(db);
                var roleMngr  = new RoleManager <IdentityRole>(roleStore);
                roles = roleMngr.Roles.ToList();
            }
            ViewBag.Roles = new SelectList(roles, "Name", "Name");

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 28
0
        public async Task <ActionResult> CreateStudent(RegisterStudentViewModel registerUserViewModel)
        {
            registerUserViewModel.GroupItems = PopulateGroups();

            if (_databaseWorker.GroupExists(registerUserViewModel.GroupId))
            {
                if (ModelState.IsValid)
                {
                    IdentityResult result = await _authentication.CreateUserAsync(registerUserViewModel);

                    if (result.Succeeded)
                    {
                        User user = await _authentication.FindUserByEmailAsync(registerUserViewModel.Email);

                        if (!await _authentication.CreateStudentUserAsync(user.Id, registerUserViewModel.GroupId))
                        {
                            await _authentication.DeleteUserAsync(user);

                            return(View("CreateStudent", registerUserViewModel));
                        }

                        return(RedirectToAction("Users"));
                    }
                    else
                    {
                        foreach (var error in result.Errors)
                        {
                            ModelState.AddModelError(string.Empty, error.Description);
                        }
                    }
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Выбирете группу для студента");
            }

            return(View("CreateStudent", registerUserViewModel));
        }
Esempio n. 29
0
        public async Task <ActionResult> RegisterStudent(RegisterStudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    UserManager.AddToRole(user.Id, "Student");
                    Student student = new Student
                    {
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        StudyYear = model.StudyYear,
                        UserId    = user.Id
                    };

                    db.Students.Add(student);
                    db.SaveChanges();

                    return(RedirectToAction("Details", "Student", new { id = student.StudentId }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 30
0
        public ActionResult Register(RegisterStudentViewModel vm)
        {
            var httpCookie = this.Request.Cookies.Get("sessionId");

            if (httpCookie != null && AuthenticationManager.IsAuthenticated(httpCookie.Value))
            {
                return(RedirectToAction("All", "Course"));
            }

            if (this.repository.Register(vm))
            {
                if (ModelState.IsValid && vm.ConfirmPassword == vm.Password)
                {
                    return(RedirectToAction("Login"));
                }
                return(RedirectToAction("Register"));
            }
            else
            {
                ModelState.AddModelError("", "Username taken");
                return(View());
            }
        }
Esempio n. 31
0
        public async Task<ActionResult> RegisterStudent(RegisterStudentViewModel model)
        {
            if (model == null)
            {
                return PartialView("_RegisterStudent", model);
            }
            if (ModelState.IsValid)
            {
                var user = new User { UserName = model.Username, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    var newUser = _db.Users.FirstOrDefault(x => x.UserName == user.UserName);
                    if (newUser != null)
                    {
                        var roleUser = this.UserManager.AddToRole(newUser.Id, "Student");
                    }

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return PartialView("_RegisterStudent",model);
        }