private static Profile GetProfile(long profileId, User userDb, AdminExtendedProfile extendedProfile) { var profile = Mapper.Map <Profile>(extendedProfile.Profile); profile.UserId = userDb.Id; profile.Guid = userDb.Guid; profile.Id = profileId; return(profile); }
public IExtendedProfile GetExtendedProfile(User katushaUser, long profileId) { var includeExpressionParams = new Expression <Func <Profile, object> >[] { p => p.Photos }; var profile = _profileRepository.GetById(profileId, includeExpressionParams); var user = _userRepository.GetById(profile.UserId); IExtendedProfile extendedProfile = new ApiExtendedProfile { Profile = Mapper.Map <ApiProfile>(profile), User = Mapper.Map <ApiUser>(user), CountriesToVisit = _countriesToVisitRepository.Query(p => p.ProfileId == profileId, null, false).Select(ctv => ctv.Country).ToArray(), LanguagesSpoken = _languagesSpokenRepository.Query(p => p.ProfileId == profileId, null, false).Select(ls => ls.Language).ToArray(), Searches = _searchingForRepository.Query(p => p.ProfileId == profileId, null, false).Select(s => ((LookingFor)s.Search).ToString()).ToArray(), }; if (((UserRole)katushaUser.UserRole & UserRole.Administrator) == 0) { } else { var photoBackups = new List <ApiPhotoBackup>(profile.Photos.Count); if (profile.Photos.Count > 0) { foreach (var photo in profile.Photos) { try { var photoBackup = _photoBackupService.GetPhoto(photo.Guid); var apiPhotoBackup = Mapper.Map <ApiPhotoBackup>(photoBackup); if (apiPhotoBackup != null) { photoBackups.Add(apiPhotoBackup); } } catch (Exception) { } } } var ravenMessages = Mapper.Map <IList <Conversation> >(_conversationRepository.Query(p => p.FromId == profileId || p.ToId == profileId, null, false, e => e.From, e => e.To).ToList()); var messages = Mapper.Map <IList <ApiConversation> >(ravenMessages); extendedProfile = new AdminExtendedProfile(extendedProfile) { User = Mapper.Map <ApiAdminUser>(user), Messages = messages, PhotoBackups = photoBackups }; } _profileService.UpdateRavenProfile(profile.Id); return(extendedProfile); }
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); }