public ViewResult ChangeInfo(UserFull userModification) { if (ModelState.IsValid) { MembershipUser mu = Membership.GetUser(); RegisteredUser ru = (RegisteredUser)registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey)); userModification.Email = ru.EmailAddress; ru.FirstName = userModification.FirstName; ru.LastName = userModification.LastName; ru.PhoneNumber = string.Empty; ru.ChangeZipCode(userModification.ZipCode); ru.Size = userSizeRepository.Get(userModification.UserSize); if (userModification.PrivacyStatus == PrivacyLevel.Private.ToString()) { ru.Closet.PrivacyLevel = PrivacyLevel.Private; } if (userModification.PrivacyStatus == PrivacyLevel.Friends.ToString()) { ru.Closet.PrivacyLevel = PrivacyLevel.Friends; } if (userModification.PrivacyStatus == PrivacyLevel.FavoriteOutfit.ToString()) { ru.Closet.PrivacyLevel = PrivacyLevel.FavoriteOutfit; } if (userModification.PrivacyStatus == PrivacyLevel.FullCloset.ToString()) { ru.Closet.PrivacyLevel = PrivacyLevel.FullCloset; } registeredUserRepository.SaveOrUpdate(ru); userModification.Alert = "User information updated successfully"; } GetAccountData(userModification); return(View("Index", userModification)); }
public bool RegisterMember(string email, string userName, string firstName, string lastName, string password, UserSize userSize, int membershipUserId, string zipCode, IList <UserFlavor> userFlavors, IList <EventType> eventTypes, IList <Garment> mygarments, IList <Garment> mywishlist, string validateUri, string channel, string invitationCode) { bool mustConfirmMail = true; try { IDictionary <string, object> propertyValues; bool invited = false; email = email.ToLower().Trim(); userName = userName.ToLower().Trim(); basicUserRepository.DbContext.BeginTransaction(); if (!string.IsNullOrEmpty(invitationCode)) { propertyValues = new Dictionary <string, object>(); propertyValues.Add("Code", invitationCode); InvitationCode ic = invitationCodeRepository.FindOne(propertyValues); if (!invitationValidatorService.IsValidCode(ic)) { throw new InvalidInvitationCodeException(); } mustConfirmMail = string.IsNullOrEmpty(ic.EmailAddress); ic.MarkUsed(); invitationCodeRepository.SaveOrUpdate(ic); } RegisteredUser user = new RegisteredUser(); user.UserName = userName; user.FirstName = firstName; user.LastName = lastName; user.EmailAddress = email.ToLower().Trim(); user.Size = userSize; user.PhoneNumber = string.Empty; user.MembershipUserId = membershipUserId; user.RegistrationCode = Guid.NewGuid().ToString(); // Used for email verification purposes. user.ChangeZipCode(zipCode); user.SetFlavors(userFlavors); user.Channel = channel; if (eventTypes != null) { foreach (EventType eventType in eventTypes) { user.AddEventType(eventType); } } // Create Closet Closet closet = new Closet(); closet.User = user; closet.PrivacyLevel = PrivacyLevel.Private; closet.MarkAsProcessed(); if (mygarments != null) { foreach (Garment garment in mygarments) { closet.AddGarment(garment); } } user.Closet = closet; // Check if the user does not exist with that mail propertyValues = new Dictionary <string, object>(); propertyValues.Add("EmailAddress", email); BasicUser bu = basicUserRepository.FindOne(propertyValues); // HACK: We need to change the mail of the invited user to be able to add the new registered user. if (bu != null && bu is InvitedUser) { InvitedUser iu = bu as InvitedUser; iu.EmailAddressReplaced = iu.EmailAddress; iu.EmailAddress += new Random().Next().ToString(); basicUserRepository.SaveOrUpdate(iu); basicUserRepository.DbContext.CommitTransaction(); basicUserRepository.DbContext.BeginTransaction(); closetRepository.SaveOrUpdate(closet); basicUserRepository.SaveOrUpdate(user); propertyValues = new Dictionary <string, object>(); propertyValues.Add("User", bu); IList <Friend> lst = friendRepository.FindAll(propertyValues); if (lst.Count > 0) { foreach (Friend f in lst) { Friend newFriend = new Friend(); newFriend.BasicUser = user; newFriend.User = f.BasicUser; newFriend.Status = FriendStatus.Pending; friendRepository.SaveOrUpdate(newFriend); } } invited = true; } else { closetRepository.SaveOrUpdate(closet); basicUserRepository.SaveOrUpdate(user); } // Create wishlist even if no items been selected for further use. WishList wl = new WishList(); wl.User = user; // Save Wish List if (mywishlist != null && mywishlist.Count > 0) { foreach (Garment wishlist in mywishlist) { wl.AddGarment(wishlist); } } wishListRepository.SaveOrUpdate(wl); // Send Email Confirmation Mail if (mustConfirmMail) { SendValidationCode(user, validateUri); } // Commit Transaction basicUserRepository.DbContext.CommitTransaction(); new FashionAde.Utils.OutfitEngineService.OutfitEngineServiceClient().CreateOutfits(closet.Id); if (invited) { basicUserRepository.MigrateInvited(bu as InvitedUser, user); } } catch { try { basicUserRepository.DbContext.RollbackTransaction(); } catch { } throw; } return(mustConfirmMail); }