Example #1
0
        private void ValidateProfileCollections(ProfileModel profileModel, Profile model)
        {
            var llp = new LookupListProcessor <ProfileModel, Profile, CountriesToVisitModel, CountriesToVisit, string>(
                p => p.CountriesToVisit,
                p => p.CountriesToVisit,
                p => (string)p.Country,
                p => p.Country,
                (modelData, country) => _profileService.DeleteCountriesToVisit(modelData.Id, country),
                (modelData, country) => _profileService.AddCountriesToVisit(modelData.Id, country)
                );

            var llp2 = new LookupListProcessor <ProfileModel, Profile, LanguagesSpokenModel, LanguagesSpoken, string>(
                p => p.LanguagesSpoken,
                p => p.LanguagesSpoken,
                p => (string)p.Language,
                p => p.Language,
                (modelData, language) => _profileService.DeleteLanguagesSpoken(modelData.Id, language),
                (modelData, language) => _profileService.AddLanguagesSpoken(modelData.Id, language)
                );

            var llp3 = new LookupListProcessor <ProfileModel, Profile, SearchingForModel, SearchingFor, LookingFor>(
                p => p.Searches,
                p => p.Searches,
                p => (LookingFor)p.Search,
                p => p.Search,
                (modelData, search) => _profileService.DeleteSearches(modelData.Id, search),
                (modelData, search) => _profileService.AddSearches(modelData.Id, search)
                );

            llp.Process(Request, ModelState, profileModel, model);
            llp2.Process(Request, ModelState, profileModel, model);
            llp3.Process(Request, ModelState, profileModel, model);
        }
        public IList <string> SetExtendedProfile(AdminExtendedProfile extendedProfile)
        {
            var list   = new List <string>();
            var userDb = _userRepository.SingleAttached(p => p.UserName == extendedProfile.User.UserName);

            if (userDb == null)
            {
                var user = Mapper.Map <User>(extendedProfile.User);
                if (user == null)
                {
                    list.Add("WRONG USER");
                    return(list);
                }
                user.CreationDate = DateTime.Now;
                user.DeletionDate = new DateTime(1900, 1, 1);
                user.ModifiedDate = DateTime.Now;
                userDb            = _userRepository.Add(user);
            }
            else
            {
                if (userDb.Guid != extendedProfile.User.Guid)
                {
                    userDb.Guid = userDb.Guid;
                }
                userDb.Email          = extendedProfile.User.Email;
                userDb.EmailValidated = extendedProfile.User.EmailValidated;
                userDb.FacebookUid    = extendedProfile.User.FacebookUid;
                userDb.PaypalPayerId  = extendedProfile.User.PaypalPayerId;
                userDb.UserRole       = (long)extendedProfile.User.UserRole;
                userDb.Phone          = extendedProfile.User.Phone;
                userDb.UserName       = extendedProfile.User.UserName;
                _userRepository.FullUpdate(userDb);
            }

            if (extendedProfile.Profile.Height < 100)
            {
                extendedProfile.Profile.Height = 170;
            }
            if (extendedProfile.Profile.Height > 240)
            {
                extendedProfile.Profile.Height = 235;
            }
            if (extendedProfile.Profile.BirthYear < 1941)
            {
                extendedProfile.Profile.BirthYear = 1941;
            }
            if (extendedProfile.Profile.BirthYear > (DateTime.Now.Year - 18))
            {
                extendedProfile.Profile.BirthYear = DateTime.Now.Year - 19;
            }
            var profile = GetProfile(_profileService.GetProfileId(userDb.Guid), userDb, extendedProfile);

            foreach (var photo in profile.Photos)
            {
                SetDatetime(photo);
            }
            if (profile.Id == 0)
            {
                if (!String.IsNullOrEmpty(extendedProfile.Profile.FriendlyName))
                {
                    if (_profileRepository.CheckIfFriendlyNameExists(extendedProfile.Profile.FriendlyName))
                    {
                        extendedProfile.Profile.FriendlyName = "";
                    }
                }
                SetDatetime(profile);

                TryFixLocation(profile.Location);
                profile = _profileService.CreateProfile(profile);
            }
            else
            {
                profile = _profileService.UpdateProfile(profile);
            }
            if (extendedProfile.CountriesToVisit != null)
            {
                foreach (var item in extendedProfile.CountriesToVisit)
                {
                    var country = (item == "USA") ? "us" : GetCountryToVisit(item);
                    if (String.IsNullOrWhiteSpace(country))
                    {
                        continue;
                    }
                    _profileService.AddCountriesToVisit(profile.Id, country);
                }
            }
            if (extendedProfile.Searches != null)
            {
                LookingFor searches;
                foreach (var item in extendedProfile.Searches)
                {
                    if (Enum.TryParse(item, out searches))
                    {
                        _profileService.AddSearches(profile.Id, searches);
                    }
                }
            }
            if (extendedProfile.LanguagesSpoken != null)
            {
                foreach (var item in extendedProfile.LanguagesSpoken)
                {
                    var language = GetLanguage(item);
                    if (String.IsNullOrEmpty(language))
                    {
                        continue;
                    }
                    _profileService.AddLanguagesSpoken(profile.Id, language);
                }
            }
            if (extendedProfile.PhotoBackups.Count > 0)
            {
                foreach (var photoBackup in extendedProfile.PhotoBackups)
                {
                    _photoBackupService.AddPhoto(Mapper.Map <PhotoBackup>(photoBackup));
                }
                list.AddRange(from photo in extendedProfile.Profile.Photos from suffix in PhotoTypes.Versions.Keys where _photoBackupService.GeneratePhoto(photo.Guid, (PhotoType)suffix) select "CREATED\t" + photo.Guid);
            }
            if (extendedProfile.Messages != null && extendedProfile.Messages.Count > 0)
            {
                foreach (var message in Mapper.Map <IList <Conversation> >(extendedProfile.Messages))
                {
                    Guid otherGuid;
                    if (message.ToGuid == extendedProfile.Profile.Guid)
                    {
                        message.ToId   = _profileService.GetProfileId(message.ToGuid);
                        otherGuid      = message.FromGuid;
                        message.FromId = _profileService.GetProfileId(message.FromGuid);
                    }
                    else
                    {
                        message.FromId = profile.Id;
                        otherGuid      = message.ToGuid;
                        message.ToId   = _profileService.GetProfileId(message.ToGuid);
                    }
                    var otherUser = _userRepository.GetByGuid(otherGuid);
                    if (otherUser == null)
                    {
                        continue;
                    }
                    var messageGuid = message.Guid;
                    var messageDb   = _conversationRepository.SingleAttached(p => p.Guid == messageGuid);
                    if (messageDb != null)
                    {
                        _conversationService.SendMessage((message.FromId == profile.Id) ? userDb : otherUser, message);
                    }
                }
            }
            return(list);
        }
Example #3
0
        public Profile Generate(int extra = 0)
        {
#if DEBUG
            Logger.Info("Profile START:");
#endif
            IGenerator <User> generator = new UserGenerator(_userService);
            var user = generator.Generate();

            var geoCountries = _resourceService.GetCountries();
            //var countries = new List<string>(geoCountries.Count);
            //countries.AddRange(geoCountries.Select(country => country.Key));
            var countries = new List <string> {
                "tr", "ua", "us"
            };

            var geoLanguages = _resourceService.GetLanguages();
            var languages    = new List <string>(geoLanguages.Count);
            languages.AddRange(geoLanguages.Select(language => language.Key));

            var cn = GeneratorHelper.RND.Next(countries.Count);
            //if (cn <= 0 || cn > countries.Count - 2) cn = 1;
            var co       = countries[cn];
            var cl       = _resourceService.GetCities(co).Take(4).ToArray();
            var ci       = cl[GeneratorHelper.RND.Next(cl.Length)];
            var location = new Location {
                CityCode = int.Parse(ci.Key), CityName = ci.Value, CountryCode = co, CountryName = geoCountries[co]
            };
            var profile = new Profile {
                Name        = GeneratorHelper.RandomString(10, true),
                Gender      = (byte)(GeneratorHelper.RND.Next((int)Sex.MAX) + 1),
                UserId      = user.Id,
                Guid        = user.Guid,
                BodyBuild   = (byte)(GeneratorHelper.RND.Next((int)BodyBuild.MAX) + 1),
                EyeColor    = (byte)(GeneratorHelper.RND.Next((int)EyeColor.MAX) + 1),
                Smokes      = (byte)(GeneratorHelper.RND.Next((int)Smokes.MAX) + 1),
                Location    = location,
                HairColor   = (byte)(GeneratorHelper.RND.Next((int)HairColor.MAX) + 1),
                Alcohol     = (byte)(GeneratorHelper.RND.Next(1 + (int)Alcohol.MAX)),
                Religion    = (byte)(GeneratorHelper.RND.Next((int)Religion.MAX) + 1),
                Description = GeneratorHelper.RandomString(1000, false),
                Height      = GeneratorHelper.RandomNumber(150, 198),
                BirthYear   = GeneratorHelper.RandomNumber(1960, 1989)
            };

            if (profile.Gender == (byte)Sex.Male)
            {
                profile.DickSize      = (byte)(GeneratorHelper.RND.Next((int)DickSize.MAX) + 1);
                profile.DickThickness = (byte)(GeneratorHelper.RND.Next((int)DickThickness.MAX) + 1);
            }
            else
            {
                profile.BreastSize = (byte)(GeneratorHelper.RND.Next((int)BreastSize.MAX) + 1);
            }

            _profileService.CreateProfile(profile);

            foreach (var language in languages.Where(language => GeneratorHelper.RND.Next(10) + 1 == 1))
            {
                _profileService.AddLanguagesSpoken(profile.Id, language);
            }

            for (byte i = 1; i <= (byte)LookingFor.MAX; i++)
            {
                if (GeneratorHelper.RND.Next(2) + 1 == 1)
                {
                    _profileService.AddSearches(profile.Id, (LookingFor)i);
                }
            }

            foreach (var country in countries.Where(country => GeneratorHelper.RND.Next(10) + 1 == 1))
            {
                _profileService.AddCountriesToVisit(profile.Id, country);
            }

            if (extra == 0)
            {
                var photoCount = GeneratorHelper.RND.Next(4);
                if (photoCount > 0)
                {
                    var root    = HttpContext.Current.Server.MapPath(@"~\");
                    var samples = root + "Images\\SamplePhotos\\" + ((Sex)profile.Gender).ToString() + "\\";
                    for (var i = 1; i <= photoCount; i++)
                    {
                        var filename = "me" + i.ToString(CultureInfo.InvariantCulture) + ".jpg";
                        var filepath = samples + filename;
                        var photo    = _photosService.AddSamplePhoto(profile.Id, GeneratorHelper.RandomString(20, false), filename, filepath);
                        if (GeneratorHelper.RND.Next(3) + 1 == 1)
                        {
                            _photosService.MakeProfilePhoto(profile.Id, photo.Guid);
                        }
                    }
                }
            }
            var id = _profileService.GetProfileId(profile.Guid);
            if (id > 0)
            {
                profile = _profileService.GetProfile(id, null, p => p.CountriesToVisit, p => p.LanguagesSpoken, p => p.Searches, p => p.Photos);
            }

#if DEBUG
            Logger.Info("Profile END");
#endif
            return(profile);
        }