コード例 #1
0
ファイル: AccountController.cs プロジェクト: spenar/hts
        public ActionResult TeacherRegistration(TeacherRegistrationViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var status = WebSecurity.Register(viewModel.Username, viewModel.Password, viewModel.Email, true,
                                                  viewModel.FirstName,
                                                  viewModel.LastName);
                if (status == MembershipCreateStatus.Success)
                {
                    var userID = WebSecurity.GetUserId(viewModel.Username);
                    Roles.AddUserToRole(viewModel.Username, RolesNames.Teacher);

                    this._teacherManager.Add(new Models.Teacher()
                        {
                            Name = viewModel.LastName,
                            IsConfirmed = false,
                            Surname = viewModel.FirstName,
                            UserID = userID
                        });

                    this._institutionManager.AddInstitution2User(viewModel.InstitutionID, userID);
                    this.HttpContext.Cache.SetUserID(userID);
                    return this.RedirectToLocal(Url.Action("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("Register error!", "Register error please contact our support team!");
                    viewModel.Institutions = this._institutionManager.GetAll().Select(x => new SelectListItem()
                        {
                            Value = x.Id.ToString(),
                            Text = x.Name
                        });

                    return this.View("Registrations/TeacherRegistration", viewModel);
                }
            }

            return this.View("Registrations/TeacherRegistration", viewModel);
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: spenar/hts
        public ActionResult TeacherRegistration()
        {
            var viewModel = new TeacherRegistrationViewModel();
            viewModel.Institutions = this._institutionManager.GetAll().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });

            return View("Registrations/TeacherRegistration", viewModel);
        }