예제 #1
0
        public ActionResult StudentRegistration()
        {
            var viewModel = new StudentRegistrationViewModel();
            viewModel.Institutions = this._institutionManager.GetAll().ToList().Select(x => new SelectListItem()
                {
                    Value = x.Id.ToString(),
                    Text = x.Name
                });

            return View("Registrations/StudentRegistration",viewModel);
        }
예제 #2
0
        public ActionResult StudentRegistration(StudentRegistrationViewModel 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.Student);
                    this._studentManager.Add(new Student()
                        {
                            Name = viewModel.LastName,
                            GroupID = viewModel.GroupID,
                            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/StudentRegistration",viewModel);
                }
            }

            viewModel.Institutions = this._institutionManager.GetAll().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text = x.Name
            });
            return View("Registrations/StudentRegistration", viewModel);
        }