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);
        }
 public void AddUser(UserProfile userProfile)
 {
     UserProfiles.InsertOnSubmit(userProfile);
     SubmitChanges();
 }
partial         void UpdateUserProfile(UserProfile instance)
        {
            ExecuteDynamicUpdate(instance);
        }
		private void detach_UserProfiles(UserProfile entity)
		{
			this.SendPropertyChanging();
			entity.School = null;
		}
 partial void DeleteUserProfile(UserProfile instance);
 partial void UpdateUserProfile(UserProfile instance);
 partial void InsertUserProfile(UserProfile instance);
        public ActionResult 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 = model.SchoolId;
                            userProfile.UserName = model.UserName;
                            db.UserProfiles.InsertOnSubmit(userProfile);
                            db.SubmitChanges(ConflictMode.ContinueOnConflict);
                        }
                    }
                    WebSecurity.CreateAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);

                    //return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }
            using (var db = new UsersContext())
            {
                if (!db.DatabaseExists())
                    db.CreateDatabase();
                ViewBag.Schools = db.Schools.ToList();
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }