Example #1
0
        public override int GetHashCode()
        {
            int result = 1;

            result = (result * 397) ^ (AltEmailAddress != null ? AltEmailAddress.GetHashCode() : 0);
            result = (result * 397) ^ (AltTelephoneContact != null ? AltTelephoneContact.GetHashCode() : 0);
            result = (result * 397) ^ (CreatedOn != null ? CreatedOn.GetHashCode() : 0);
            result = (result * 397) ^ (DateOfBirth != null ? DateOfBirth.GetHashCode() : 0);
            result = (result * 397) ^ (EmailAddress != null ? EmailAddress.GetHashCode() : 0);
            result = (result * 397) ^ (Gender != null ? Gender.GetHashCode() : 0);
            result = (result * 397) ^ (GivenName != null ? GivenName.GetHashCode() : 0);
            result = (result * 397) ^ (HomeLanguage != null ? HomeLanguage.GetHashCode() : 0);
            result = (result * 397) ^ Id.GetHashCode();
            result = (result * 397) ^ (LastModified != null ? LastModified.GetHashCode() : 0);
            result = (result * 397) ^ (MaritalStatus != null ? MaritalStatus.GetHashCode() : 0);
            result = (result * 397) ^ (NextOfKinAddress != null ? NextOfKinAddress.GetHashCode() : 0);
            result = (result * 397) ^ (NextOfKinContact != null ? NextOfKinContact.GetHashCode() : 0);
            result = (result * 397) ^ (NextOfKinName != null ? NextOfKinName.GetHashCode() : 0);
            result = (result * 397) ^ (NextOfKinRelationship != null ? NextOfKinRelationship.GetHashCode() : 0);
            result = (result * 397) ^ (Occupation != null ? Occupation.GetHashCode() : 0);
            result = (result * 397) ^ (Organisation != null ? Organisation.GetHashCode() : 0);
            result = (result * 397) ^ (OtherName != null ? OtherName.GetHashCode() : 0);
            result = (result * 397) ^ (PermentAddress != null ? PermentAddress.GetHashCode() : 0);
            result = (result * 397) ^ (PersonOwnerType != null ? PersonOwnerType.GetHashCode() : 0);
            result = (result * 397) ^ (PlaceOfBirth != null ? PlaceOfBirth.GetHashCode() : 0);
            result = (result * 397) ^ (PostalAddress != null ? PostalAddress.GetHashCode() : 0);
            result = (result * 397) ^ (PreferredLanguage != null ? PreferredLanguage.GetHashCode() : 0);
            result = (result * 397) ^ (ProfilePhotoName != null ? ProfilePhotoName.GetHashCode() : 0);
            result = (result * 397) ^ (Religion != null ? Religion.GetHashCode() : 0);
            result = (result * 397) ^ (Surname != null ? Surname.GetHashCode() : 0);
            result = (result * 397) ^ (TelephoneContact != null ? TelephoneContact.GetHashCode() : 0);
            result = (result * 397) ^ (Title != null ? Title.GetHashCode() : 0);
            result = (result * 397) ^ (WebsiteUrl != null ? WebsiteUrl.GetHashCode() : 0);
            return(result);
        }
Example #2
0
        public async ValueTask <User?> ExecuteAsync(User user, IServiceProvider serviceProvider,
                                                    CancellationToken ct)
        {
            Validate <Validator> .It(this);

            var newUser = user;

            if (Is.Changed(FullName, user.FullName))
            {
                newUser = newUser with
                {
                    FullName = FullName.Trim()
                };
            }

            if (Is.Changed(EmailAddress, user.EmailAddress))
            {
                newUser = newUser with
                {
                    EmailAddress = EmailAddress.Trim().ToLowerInvariant()
                };
            }

            if (Is.Changed(PhoneNumber, user.PhoneNumber))
            {
                newUser = newUser with
                {
                    PhoneNumber = PhoneNumber.Trim().ToLowerInvariant()
                };
            }

            if (Is.Changed(Properties, user.Properties))
            {
                newUser = newUser with
                {
                    Properties = Properties
                };
            }

            if (Is.Changed(PreferredLanguage, user.PreferredLanguage))
            {
                newUser = newUser with
                {
                    PreferredLanguage = PreferredLanguage.Trim()
                };
            }

            if (Is.Changed(PreferredTimezone, user.PreferredTimezone))
            {
                newUser = newUser with
                {
                    PreferredTimezone = PreferredTimezone.Trim()
                };
            }

            if (Is.Changed(RequiresWhitelistedTopics, user.RequiresWhitelistedTopics))
            {
                newUser = newUser with
                {
                    RequiresWhitelistedTopics = RequiresWhitelistedTopics.Value
                };
            }

            if (Settings != null)
            {
                var newSettings = Settings;

                if (MergeSettings)
                {
                    newSettings = ChannelSettings.Merged(user.Settings, Settings);
                }

                newUser = newUser with
                {
                    Settings = newSettings
                };
            }

            if (string.IsNullOrWhiteSpace(user.ApiKey))
            {
                var tokenGenerator = serviceProvider.GetRequiredService <IApiKeyGenerator>();

                newUser = newUser with
                {
                    ApiKey = await tokenGenerator.GenerateUserTokenAsync(user.AppId, user.Id)
                };
            }

            return(newUser);
        }
    }
}
Example #3
0
 public override Calendar DisplayDate()
 {
     PreferredLanguage.DisplayDate(DateTime.Now);
     return(this);
 }
Example #4
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Href != null)
         {
             hashCode = hashCode * 59 + Href.GetHashCode();
         }
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Status != null)
         {
             hashCode = hashCode * 59 + Status.GetHashCode();
         }
         if (StatusReason != null)
         {
             hashCode = hashCode * 59 + StatusReason.GetHashCode();
         }
         if (PreferredLanguage != null)
         {
             hashCode = hashCode * 59 + PreferredLanguage.GetHashCode();
         }
         if (ValidFor != null)
         {
             hashCode = hashCode * 59 + ValidFor.GetHashCode();
         }
         if (EngagedParty != null)
         {
             hashCode = hashCode * 59 + EngagedParty.GetHashCode();
         }
         if (PartyRoleType != null)
         {
             hashCode = hashCode * 59 + PartyRoleType.GetHashCode();
         }
         if (Account != null)
         {
             hashCode = hashCode * 59 + Account.GetHashCode();
         }
         if (PaymentMethod != null)
         {
             hashCode = hashCode * 59 + PaymentMethod.GetHashCode();
         }
         if (ContactMedium != null)
         {
             hashCode = hashCode * 59 + ContactMedium.GetHashCode();
         }
         if (Characteristic != null)
         {
             hashCode = hashCode * 59 + Characteristic.GetHashCode();
         }
         if (CreditProfile != null)
         {
             hashCode = hashCode * 59 + CreditProfile.GetHashCode();
         }
         if (Agreement != null)
         {
             hashCode = hashCode * 59 + Agreement.GetHashCode();
         }
         if (RelatedParty != null)
         {
             hashCode = hashCode * 59 + RelatedParty.GetHashCode();
         }
         return(hashCode);
     }
 }
Example #5
0
        /// <summary>
        /// Returns true if Customer instances are equal
        /// </summary>
        /// <param name="other">Instance of Customer to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Customer other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Href == other.Href ||
                     Href != null &&
                     Href.Equals(other.Href)
                     ) &&
                 (
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ) &&
                 (
                     StatusReason == other.StatusReason ||
                     StatusReason != null &&
                     StatusReason.Equals(other.StatusReason)
                 ) &&
                 (
                     PreferredLanguage == other.PreferredLanguage ||
                     PreferredLanguage != null &&
                     PreferredLanguage.Equals(other.PreferredLanguage)
                 ) &&
                 (
                     ValidFor == other.ValidFor ||
                     ValidFor != null &&
                     ValidFor.Equals(other.ValidFor)
                 ) &&
                 (
                     EngagedParty == other.EngagedParty ||
                     EngagedParty != null &&
                     EngagedParty.Equals(other.EngagedParty)
                 ) &&
                 (
                     PartyRoleType == other.PartyRoleType ||
                     PartyRoleType != null &&
                     PartyRoleType.Equals(other.PartyRoleType)
                 ) &&
                 (
                     Account == other.Account ||
                     Account != null &&
                     Account.SequenceEqual(other.Account)
                 ) &&
                 (
                     PaymentMethod == other.PaymentMethod ||
                     PaymentMethod != null &&
                     PaymentMethod.SequenceEqual(other.PaymentMethod)
                 ) &&
                 (
                     ContactMedium == other.ContactMedium ||
                     ContactMedium != null &&
                     ContactMedium.SequenceEqual(other.ContactMedium)
                 ) &&
                 (
                     Characteristic == other.Characteristic ||
                     Characteristic != null &&
                     Characteristic.SequenceEqual(other.Characteristic)
                 ) &&
                 (
                     CreditProfile == other.CreditProfile ||
                     CreditProfile != null &&
                     CreditProfile.SequenceEqual(other.CreditProfile)
                 ) &&
                 (
                     Agreement == other.Agreement ||
                     Agreement != null &&
                     Agreement.SequenceEqual(other.Agreement)
                 ) &&
                 (
                     RelatedParty == other.RelatedParty ||
                     RelatedParty != null &&
                     RelatedParty.SequenceEqual(other.RelatedParty)
                 ));
        }
Example #6
0
        private async Task <Outgoing> PostDelete(Incoming incoming)
        {
            switch (incoming.search.remove.type)
            {
            case "activeprojects":
                ActiveProject activeProject = _repo.ActiveProjects.FindByCondition(p => p.ActiveProjectId == incoming.search.remove.id).SingleOrDefault();
                if (activeProject == null)
                {
                    return(await PostError("PostRemove(): activeProject id does not exist"));
                }
                _repo.ActiveProjects.Delete(activeProject);
                break;

            case "badphrases":
                BadPhrase badPhrase = _repo.BadPhrases.FindByCondition(p => p.BadPhraseId == incoming.search.remove.id).SingleOrDefault();
                if (badPhrase == null)
                {
                    return(await PostError("PostRemove(): badPhrase id does not exist"));
                }
                _repo.BadPhrases.Delete(badPhrase);
                break;

            case "badwords":
                BadWord badWord = _repo.BadWords.FindByCondition(w => w.BadWordId == incoming.search.remove.id).SingleOrDefault();
                if (badWord == null)
                {
                    return(await PostError("PostRemove(): badWord id does not exist"));
                }
                _repo.BadWords.Delete(badWord);
                break;

            case "languages":
                Language language = _repo.Languages.FindByCondition(l => l.LanguageId == incoming.search.remove.id).SingleOrDefault();
                if (language == null)
                {
                    return(await PostError("PostRemove(): language id does not exist"));
                }
                _repo.Languages.Delete(language);
                break;

            case "nearconceptideas":            // NearConceptIdeas cannot be deleted.
                break;

            case "nearconcepts":
            case "nearconceptphrases":          // NearConceptPhrases can be deleted.  The linked NearConceptIdea is not deleted.
                NearConceptPhrase nearConceptPhrase = _repo.NearConceptPhrases.FindByCondition(p => p.NearConceptPhraseId == incoming.search.remove.id).SingleOrDefault();
                if (nearConceptPhrase == null)
                {
                    return(await PostError("PostRemove(): nearConceptPhrase id does not exist"));
                }
                _repo.NearConceptPhrases.Delete(nearConceptPhrase);
                break;

            case "platforms":
                Platform platform = _repo.Platforms.FindByCondition(p => p.PlatformId == incoming.search.remove.id).SingleOrDefault();
                if (platform == null)
                {
                    return(await PostError("PostRemove(): platform id does not exist"));
                }
                _repo.Platforms.Delete(platform);
                break;

            case "preferredlanguages":
                PreferredLanguage preferredLanguage = _repo.PreferredLanguages.FindByCondition(p => p.PreferredLanguageId == incoming.search.remove.id).SingleOrDefault();
                if (preferredLanguage == null)
                {
                    return(await PostError("PostRemove(): preferredLangauge id does not exist"));
                }
                _repo.PreferredLanguages.Delete(preferredLanguage);
                break;

            case "preferredsearches":
                PreferredSearch preferredSearch = _repo.PreferredSearches.FindByCondition(p => p.PreferredSearchId == incoming.search.remove.id).SingleOrDefault();
                if (preferredSearch == null)
                {
                    return(await PostError("PostRemove(): preferredSearch id does not exist"));
                }
                _repo.PreferredSearches.Delete(preferredSearch);
                break;

            case "rawsearches":
                RawSearch rawSearch = _repo.RawSearches.FindByCondition(s => s.RawSearchId == incoming.search.remove.id).SingleOrDefault();
                if (rawSearch == null)
                {
                    return(await PostError("PostRemove(): rawSearch id does not exist"));
                }
                _repo.RawSearches.Delete(rawSearch);
                break;

            case "settings":
                Setting setting = _repo.Settings.FindByCondition(s => s.SettingId == incoming.search.remove.id).SingleOrDefault();
                if (setting == null)
                {
                    return(await PostError("PostRemove(): setting id does not exist"));
                }
                _repo.Settings.Delete(setting);
                break;

            default:
                return(await PostError("something went wrong in delete"));
            }
            _repo.Save();
            incoming.search.request.type = incoming.search.remove.type;
            return(await PostGet(incoming));
        }
Example #7
0
        private async Task <Outgoing> PostPut(Incoming incoming)
        {
            switch (incoming.search.edit.type)
            {
            case "activeprojects":
                ActiveProject activeProject = _repo.ActiveProjects.FindByCondition(p => p.ActiveProjectId == incoming.search.edit.id).SingleOrDefault();
                if (activeProject == null)
                {
                    return(await PostError("PostEdit(): activeProject id does not exist"));
                }
                activeProject.ProjectType = incoming.search.edit.newname;
                activeProject.Day         = incoming.search.edit.day;
                _repo.ActiveProjects.Update(activeProject);
                break;

            case "badphrases":
                BadPhrase badPhrase = _repo.BadPhrases.FindByCondition(p => p.BadPhraseId == incoming.search.edit.id).SingleOrDefault();
                if (badPhrase == null)
                {
                    return(await PostError("PostEdit(): badPhrase id does not exist"));
                }
                badPhrase.Phrase = incoming.search.edit.newname;
                _repo.BadPhrases.Update(badPhrase);
                break;

            case "badwords":
                BadWord badWord = _repo.BadWords.FindByCondition(w => w.BadWordId == incoming.search.edit.id).SingleOrDefault();
                if (badWord == null)
                {
                    return(await PostError("PostEdit(): badWord id does not exist"));
                }
                badWord.Word = incoming.search.edit.newname;
                _repo.BadWords.Update(badWord);
                break;

            case "languages":
                Language language = _repo.Languages.FindByCondition(l => l.LanguageId == incoming.search.edit.id).SingleOrDefault();
                if (language == null)
                {
                    return(await PostError("PostEdit(): language id does not exist"));
                }
                language.LanguageName = incoming.search.edit.newname;
                _repo.Languages.Update(language);
                break;

            case "nearconceptideas":            // NearConceptIdeas can be edited by themselves.
            {
                NearConceptIdea nearConceptIdea = _repo.NearConceptIdeas.FindByCondition(i => i.NearConceptIdeaId == incoming.search.edit.id).SingleOrDefault();
                if (nearConceptIdea == null)
                {
                    return(await PostError("PostEdit(): nearConceptIdea id does not exist"));
                }
                nearConceptIdea.ProperForm = incoming.search.edit.newname;
                nearConceptIdea.Day        = incoming.search.edit.day;
                _repo.NearConceptIdeas.Update(nearConceptIdea);
                break;
            }

            case "nearconcepts":
            case "nearconceptphrases":          // NearConceptPhrases must be edited with a NearConceptIdea.
            {
                NearConceptPhrase nearConceptPhrase = _repo.NearConceptPhrases.FindByCondition(p => p.NearConceptPhraseId == incoming.search.edit.id).SingleOrDefault();
                if (nearConceptPhrase == null)
                {
                    return(await PostError("PostEdit(): nearConceptPhrase id does not exist"));
                }
                // Doesn't make sense to edit the NearConceptIdea since it may be tied to other NearConceptPhrases.
                // If the edited NearConceptIdea doesn't already exist, it will be created.
                NearConceptIdea nearConceptIdea = _repo.NearConceptIdeas.FindByCondition(i => i.ProperForm == incoming.search.edit.matchto).SingleOrDefault();
                if (nearConceptIdea == null)            // add new nearConceptIdea;
                {
                    nearConceptIdea            = new NearConceptIdea();
                    nearConceptIdea.ProperForm = incoming.search.edit.matchto;
                    nearConceptIdea.Day        = incoming.search.edit.day;
                    _repo.NearConceptIdeas.Create(nearConceptIdea);
                    _repo.Save();
                    // reload it to get the id.
                    nearConceptIdea = _repo.NearConceptIdeas.FindByCondition(i => i.ProperForm == incoming.search.edit.matchto).SingleOrDefault();
                }
                nearConceptPhrase.Phrase    = incoming.search.edit.newname;
                nearConceptPhrase.ConceptId = nearConceptIdea.NearConceptIdeaId;
                _repo.NearConceptPhrases.Update(nearConceptPhrase);
                break;
            }

            case "platforms":
                Platform platform = _repo.Platforms.FindByCondition(p => p.PlatformId == incoming.search.edit.id).SingleOrDefault();
                if (platform == null)
                {
                    return(await PostError("PostEdit(): platform id does not exist"));
                }
                platform.PlatformName = incoming.search.edit.newname;
                _repo.Platforms.Update(platform);
                break;

            case "preferredlanguages":
                PreferredLanguage preferredLanguage = _repo.PreferredLanguages.FindByCondition(p => p.PreferredLanguageId == incoming.search.edit.id).SingleOrDefault();
                if (preferredLanguage == null)
                {
                    return(await PostError("PostEdit(): preferredLangauge id does not exist"));
                }
                preferredLanguage.LanguageName = incoming.search.edit.newname;
                preferredLanguage.Day          = incoming.search.edit.day;
                _repo.PreferredLanguages.Update(preferredLanguage);
                break;

            case "preferredsearches":
                PreferredSearch preferredSearch = _repo.PreferredSearches.FindByCondition(p => p.PreferredSearchId == incoming.search.edit.id).SingleOrDefault();
                if (preferredSearch == null)
                {
                    return(await PostError("PostEdit(): preferredSearch id does not exist"));
                }
                preferredSearch.SearchName = incoming.search.edit.newname;
                _repo.PreferredSearches.Update(preferredSearch);
                break;

            case "rawsearches":
                RawSearch rawSearch = _repo.RawSearches.FindByCondition(s => s.RawSearchId == incoming.search.edit.id).SingleOrDefault();
                if (rawSearch == null)
                {
                    return(await PostError("PostEdit(): rawSearch id does not exist"));
                }
                rawSearch.StudentName = incoming.search.username;
                rawSearch.Search      = incoming.search.edit.newname;
                _repo.RawSearches.Update(rawSearch);
                break;

            case "settings":
                Setting setting = _repo.Settings.FindByCondition(s => s.SettingId == incoming.search.edit.id).SingleOrDefault();
                if (setting == null)
                {
                    return(await PostError("PostEdit(): setting id does not exist"));
                }
                setting.SettingName = incoming.search.edit.newname;
                setting.Set         = incoming.search.isetting.set;
                _repo.Settings.Update(setting);
                break;

            default:
                return(await PostError("something went wrong in edit"));
            }
            _repo.Save();
            incoming.search.request.type = incoming.search.edit.type;
            return(await PostGet(incoming));
        }
Example #8
0
        private async Task <Outgoing> PostAdd(Incoming incoming)
        {
            switch (incoming.search.add.type)
            {
            case "activeprojects":
                ActiveProject activeProject = new ActiveProject();
                activeProject.ProjectType = incoming.search.add.name;
                activeProject.Day         = incoming.search.add.day;
                _repo.ActiveProjects.Create(activeProject);
                break;

            case "badphrases":
                BadPhrase badPhrase = new BadPhrase();
                badPhrase.Phrase = incoming.search.add.name;
                _repo.BadPhrases.Create(badPhrase);
                break;

            case "badwords":
                BadWord badWord = new BadWord();
                badWord.Word = incoming.search.add.name;
                _repo.BadWords.Create(badWord);
                break;

            case "languages":
                Language language = new Language();
                language.LanguageName = incoming.search.add.name;
                _repo.Languages.Create(language);
                break;

            case "nearconceptideas":            // NearConceptIdeas can be added by themselves.
            {
                NearConceptIdea nearConceptIdea = new NearConceptIdea();
                nearConceptIdea.ProperForm = incoming.search.add.name;
                nearConceptIdea.Day        = incoming.search.add.day;
                _repo.NearConceptIdeas.Create(nearConceptIdea);
                break;
            }

            case "nearconcepts":
            case "nearconceptphrases":          // NearConceptPhrases must be added with a NearConceptIdea.
            {
                NearConceptPhrase nearConceptPhrase = new NearConceptPhrase();
                NearConceptIdea   nearConceptIdea   = _repo.NearConceptIdeas.FindByCondition(i => i.ProperForm == incoming.search.add.matchTo).SingleOrDefault();
                if (nearConceptIdea == null)            // add new nearConceptIdea;
                {
                    nearConceptIdea            = new NearConceptIdea();
                    nearConceptIdea.ProperForm = incoming.search.add.matchTo;
                    nearConceptIdea.Day        = incoming.search.add.day;
                    _repo.NearConceptIdeas.Create(nearConceptIdea);
                    _repo.Save();
                    // reload it to get the id.
                    nearConceptIdea = _repo.NearConceptIdeas.FindByCondition(i => i.ProperForm == incoming.search.add.matchTo).SingleOrDefault();
                }
                nearConceptPhrase.Phrase    = incoming.search.add.name;
                nearConceptPhrase.ConceptId = nearConceptIdea.NearConceptIdeaId;
                _repo.NearConceptPhrases.Create(nearConceptPhrase);
                break;
            }

            case "platforms":
                Platform platform = new Platform();
                platform.PlatformName = incoming.search.add.name;
                _repo.Platforms.Create(platform);
                break;

            case "preferredlanguages":
                PreferredLanguage preferredLanguage = new PreferredLanguage();
                preferredLanguage.LanguageName = incoming.search.add.name;
                preferredLanguage.Day          = incoming.search.add.day;
                _repo.PreferredLanguages.Create(preferredLanguage);
                break;

            case "preferredsearches":
                PreferredSearch preferredSearch = new PreferredSearch();
                preferredSearch.SearchName = incoming.search.add.name;
                _repo.PreferredSearches.Create(preferredSearch);
                break;

            case "rawsearches":
                RawSearch rawSearch = new RawSearch();
                rawSearch.StudentName = incoming.search.username;
                rawSearch.Search      = incoming.search.add.name;
                _repo.RawSearches.Create(rawSearch);
                break;

            case "settings":
                Setting setting = new Setting();
                setting.SettingName = incoming.search.add.name;
                setting.Set         = incoming.search.isetting.set;
                _repo.Settings.Create(setting);
                break;

            default:
                return(await PostError("something went wrong in add"));
            }
            _repo.Save();
            incoming.search.request.type = incoming.search.add.type;
            return(await PostGet(incoming));
        }