public PartialViewResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { using (var db = new UsersContext()) { if (!WebSecurity.UserExists(model.UserName)) { var userProfile = new UserProfile(); userProfile.SchoolId = CurrentUser.School.SchoolId; userProfile.UserName = model.UserName; db.UserProfiles.InsertOnSubmit(userProfile); db.SubmitChanges(); WebSecurity.CreateAccount(model.UserName, model.Password); var newUserId = WebSecurity.GetUserId(model.UserName); var userDetails = new UserDetails(); userDetails.GlobalProfileID = newUserId; userDetails.FirstName = model.FirstName; userDetails.LastName = model.LastName; userDetails.PatronymicName = model.PatronymicName; userDetails.DateOfBirth = model.DateOfBirth; userDetails.Email = model.Email; JournalContext.UserDetails.InsertOnSubmit(userDetails); JournalContext.SubmitChanges(); if (model.SendEmail) { var body = string.Format("Уважаемый {0} {1} {2}!{3}Вы успешно зарегистрированы на портале \"Диалог\".{3} Логин: {4}{3} Пароль: {5}", userDetails.LastName, userDetails.FirstName, userDetails.PatronymicName, Environment.NewLine, model.UserName, model.Password); EmailService.EmailSender.SendText(userDetails.Email, "Регистрация на портале \"Диалог\"", body); } } } return null; } catch (MembershipCreateUserException e) { ModelState.AddModelError("", AccountController.ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return PartialView("_Register", model); }
partial void UpdateUserDetails(UserDetails instance);
partial void DeleteUserDetails(UserDetails instance);
partial void InsertUserDetails(UserDetails instance);