/// <summary> /// Registers the user. /// </summary> /// <param name="widget">The widget.</param> /// <param name="model">The model.</param> /// <param name="collection">The collection.</param> /// <param name="user">The user.</param> /// <returns></returns> public static bool RegisterUser(RegistrationWidget widget, RegistrationWidgetViewModel model, FormCollection collection, out User user) { var userService = ServiceLocator.Current.GetInstance <IUserService>(); var userProfileService = ServiceLocator.Current.GetInstance <IUserProfileService>(); user = new User(); model.MapTo(user); userService.SetPassword(user, model.Password); var isSuccess = userService.Save(user); if (isSuccess) { var profile = new UserProfile { User = user, ProfileType = widget.ProfileType }; foreach (var item in widget.ProfileType.ProfileHeaders) { foreach (var element in item.ProfileElements) { var elementName = String.Format("{0}_{1}", (ElementType)element.Type, element.Id); var value = collection[elementName]; if (value == null) { continue; } profile.AddProfileElement(new UserProfileElement { UserProfile = profile, ProfileElement = element, Value = value }); } } isSuccess = userProfileService.Save(profile); } return(isSuccess); }