private void createUser(User user, string name, string status,
                                User.eGender gender, User.eGender interestedIn,
                                int ipIdx, int age, string img1, string img2)
        {
            var username = name.Replace(" ", "").Substring(0, 4) + age;
            var random = new Random((int)(DateTime.Now.Ticks % int.MaxValue));
            int day = random.Next(1, 28);
            int month = random.Next(1, 12);
            int year = DateTime.Now.Year - age;

            if (!Classes.User.IsUsernameTaken(username))
            {
                user.Username = username;
                user.Password = username;
                user.Name = name;
                user.Gender = gender;
                user.InterestedIn = interestedIn;
                user.StatusText = status;
                user.Email = String.Format("{0}@lovehitch.com", username);
                user.Birthdate = new DateTime(year, month, day);
                Classes.User.Create(user, String.Format("192.168.{0}.{1}", ipIdx / 255, ipIdx % 255));

                ProfileTopic[] topics = ProfileTopic.Fetch();
                foreach (ProfileTopic profileTopic in topics)
                {
                    ProfileQuestion[] questions = profileTopic.FetchQuestions();
                    foreach (ProfileQuestion profileQuestion in questions)
                    {
                        try
                        {
                            var existAnswer = ProfileAnswer.Fetch(username, profileQuestion.Id);
                            if (existAnswer != null) continue;
                        }
                        catch
                        {
                            ProfileChoice[] choices = profileQuestion.FetchChoices();
                            if (choices != null && choices.Length > 0)
                            {
                                var answer = new ProfileAnswer(username, profileQuestion.Id)
                                {
                                    Value = choices[random.Next(choices.Length - 1)].Value
                                };
                                try
                                {
                                    answer.Save();
                                }
                                catch (Exception ex) { }
                            }
                        }
                    }
                }
            }
            else
            {
                user = Classes.User.Load(username);
            }

            if (user != null && user.SignupIp.IsNotNullOrEmpty() && user.SignupIp.StartsWith("192.168."))
            {
                user.updateLastLogin(DateTime.Now.Ticks.ToString());

                var pathTemplate = Config.Directories.Home + @"\images\profiles\{0}.jpg";
                if (img1.Trim().IsNotNullOrEmpty())
                    StoreUserPhoto(user, String.Format(pathTemplate, img1), true);
                if (img2.IsNotNullOrEmpty())
                    StoreUserPhoto(user, String.Format(pathTemplate, img2), false);
            }
        }
 private void createUser(User user, string username, string status, 
                 User.eGender gender, User.eGender interestedIn, int ipIdx)
 {
     if (!Classes.User.IsUsernameTaken(username))
     {
         user.Username = username;
         user.Password = username;
         user.Name = String.Format("{0} {1}{2}", status, gender, user.Age);
         user.Gender = gender;
         user.InterestedIn = interestedIn;
         user.StatusText = status;
         user.Email = String.Format("{0}@lovehitch.com", username);
         Classes.User.Create(user, String.Format("192.168.{0}.{1}", ipIdx/255, ipIdx%255));
     }
     
     var random = new Random((int)(DateTime.Now.Ticks%int.MaxValue));
     ProfileTopic[] topics = ProfileTopic.Fetch();
     foreach (ProfileTopic profileTopic in topics)
     {
         ProfileQuestion[] questions = profileTopic.FetchQuestions();
         foreach (ProfileQuestion profileQuestion in questions)
         {
             try
             {
                 var existAnswer = ProfileAnswer.Fetch(username, profileQuestion.Id);
                 if (existAnswer != null) continue;
             }
             catch
             {
                 ProfileChoice[] choices = profileQuestion.FetchChoices();
                 if (choices!=null&&choices.Length > 0)
                 {
                     var answer = new ProfileAnswer(username, profileQuestion.Id)
                                      {
                                          Value = choices[random.Next(choices.Length - 1)].Value
                                      };
                     answer.Save();
                 }
             }
         }
     }
 }
Пример #3
0
        protected void btnSaveAndApprove_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess)
                return;
            
            ProfileAnswer answer = new ProfileAnswer(username, questionID);

            if (txtAnswer.Text.Trim() == String.Empty)
                btnReject_Click(null, null);
            else
                answer.Value = txtAnswer.Text;
            answer.Approved = true;
            answer.Save();

            #region Add FriendUpdatedProfile Event

            Event newEvent = new Event(username);

            newEvent.Type = Event.eType.FriendUpdatedProfile;
            UpdatedProfile updatedProfile = new UpdatedProfile();
            updatedProfile.QuestionIDs = new List<int>() {answer.Question.Id };
            newEvent.DetailsXML = Misc.ToXml(updatedProfile);

            newEvent.Save();

            string[] usernames = Classes.User.FetchMutuallyFriends(username);

            foreach (string friendUsername in usernames)
            {
                if (Config.Users.NewEventNotification)
                {
                    string text = String.Format("Your friend {0} has updated the \"{1}\" section in their profile".TranslateA(),
                                            "<b>" + username + "</b>", answer.Question.Name);
                    int imageID = 0;
                    try
                    {
                        imageID = Photo.GetPrimary(username).Id;
                    }
                    catch (NotFoundException)
                    {
                        User user = null;
                        try
                        {
                            user = Classes.User.Load(username);
                            imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                        }
                        catch (NotFoundException)
                        {
                            break;
                        }
                    }
                    string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                    Classes.User.SendOnlineEventNotification(username, friendUsername, text, thumbnailUrl,
                                                             UrlRewrite.CreateShowUserUrl(username));
                }
            }

            #endregion

            Response.Redirect("ApproveAnswers.aspx");
        }