Exemplo n.º 1
0
        public object Add()
        {
            if (!this.isValid || tagAlreadyExists())
            {
                return(false);
            }
            if (this.isCommunityHeadTag)
            {
                AdminAdder.AddAdmin(personFromDb.MisparIshi,
                                    false, false /* forceNewAdminLevel */);
            }
            if (this.isAdminChange)
            {
                AdminChangeWriter.WriteAdminChange(
                    String.Format(
                        "Added tag {0} for {1}",
                        TagToPrimeDictionary.PRIME_TO_TAG[tagPrime].Tag,
                        personFromDb.MisparIshi));
            }
            long newTagValue = this.personFromDb.Tags * tagPrime;

            if ((newTagValue > long.MaxValue || newTagValue < this.personFromDb.Tags) && (newTagValue % tagPrime != 0))
            {
                // Here we check if Tags * tagPrime went over the long.MaxValue.
                // Note - The value loops around to negative and continutes rising.
                // So, newTagValue will probably never actually be over MaxValue, so we check if the tag exists
                // in the new tag variable. A complete fix will require changing the way we store tags.
                return(false);
            }
            this.personFromDb.Tags = newTagValue;
            this.dataContext.SubmitChanges();
            return(TagToPrimeDictionary.PRIME_TO_TAG[tagPrime].ToJson());
        }
Exemplo n.º 2
0
 public bool Delete()
 {
     if (!this.isValid || !tagAlreadyExists())
     {
         return(false);
     }
     if (this.isCommunityHeadTag)
     {
         AdminAdder.DeleteAdmin(personFromDb.MisparIshi);
     }
     if (this.isAdminChange)
     {
         AdminChangeWriter.WriteAdminChange(
             String.Format(
                 "Deleted tag {0} for {1}",
                 TagToPrimeDictionary.PRIME_TO_TAG[tagPrime].Tag,
                 personFromDb.MisparIshi));
     }
     this.personFromDb.Tags /= tagPrime;
     this.dataContext.SubmitChanges();
     return(true);
 }