예제 #1
0
 public string MessageSent(Conversation conversation)
 {
     try {
         var toUser = _userRepository.GetByGuid(conversation.ToGuid);
         //Mailer.Mailer.SendMail(_adminMailAddress, String.Format("[NEW MESSAGE] From: {0} To: {1}", conversation.FromName, conversation.ToName), MailMessageSentAdmin, _mailTemplatesFolder, conversation);
         return(Mailer.Mailer.SendMail(toUser.Email, String.Format("Katusha says: {0} sent you a message.", conversation.FromName), MailMessageSent, _mailTemplatesFolder, conversation));
     } catch (Exception ex) {
         return(ex.Message);
     }
 }
예제 #2
0
        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);
        }