Example #1
0
        public static void DeleteTag(string tagName)
        {
            lock (AdminTagAdder.LOCK)
            {
                if (!CurrentMisparIshi.IsAdmin())
                {
                    return;
                }
                if (!TagToPrimeDictionary.TAG_NAME_TO_TAG.ContainsKey(tagName))
                {
                    return;
                }
                var tagToRemoveId = TagToPrimeDictionary.TAG_NAME_TO_TAG[tagName].PrimeId;

                var dataContext = new PersonDataContext();
                var biggestTag  = dataContext.TagPrimes
                                  .OrderByDescending(tag => tag.PrimeId)
                                  .FirstOrDefault();
                var biggestTagId = biggestTag.PrimeId;
                if (biggestTagId < 2)
                {
                    return;
                }

                // Ok so we've isolated the ID of the tag we want to remove R
                // and the ID biggest tag B. We now do the following:
                // (1) Change R's text to  " ". This is a bit of a hack but elsewhere
                // the code will ensure that " " is not searchable or rendered. Note
                // that we do this by deleting it and creating a new one.
                // (2) For every person with tag R, divide their tag value by R.ID.
                //     For every person with tag B, multiple their tag value by R.ID.
                // (3) Change R's text to B's text. Delete B.
                // (4) For every person with tag B, divide their tag value by B.ID.
                // (5) Reset the dictionaries.

                // Step (1).
                dataContext.makeTagToRemoveUnsearchable(tagToRemoveId);

                // Step (2)
                dataContext.RemoveTagIdFromAllPeople(tagToRemoveId);
                dataContext.Persons
                .Where(person => person.Tags % biggestTagId == 0)
                .ToList()
                .ForEach(person => { person.Tags *= tagToRemoveId; });
                dataContext.SubmitChanges();

                // Step (3)
                dataContext.SwitchTagId(biggestTagId, tagToRemoveId);

                // Step (4)
                dataContext.RemoveTagIdFromAllPeople(tagToRemoveId);

                // Step (5)
                TagToPrimeDictionary.ResetTagToPrimeDictionaries();

                AdminChangeWriter.WriteAdminChange(
                    String.Format("Deleted tag {0}", tagName));
            }
        }
Example #2
0
        public static IEnumerable <object> AddTag(string tagToAdd, bool isTagForAnyone)
        {
            //if (!CurrentMisparIshi.IsAdmin())
            //{
            //    return createResponseObject(
            //        "You're not an admin, what are you doing here??");
            //}

            if (tagToAdd.Contains(" "))
            {
                return(createResponseObject(
                           "אסור להוסיף תגים עם רווחים"));
            }


            var nextPrime = TagToPrimeDictionary.GetNextPrime();

            if (nextPrime == -1)
            {
                return(createResponseObject(
                           "יש 10,000 תגים ויותר מזה לא נתמך"));
            }


            var dataContext         = new PersonDataContext();
            var alreadyExistingTags =
                dataContext.TagPrimes.Where(tag => tag.Tag.Equals(tagToAdd));

            if (alreadyExistingTags.Count() > 0)
            {
                return(createResponseObject(
                           String.Format("התג {0} כבר קיים", tagToAdd)));
            }

            var newTagPrime = new TagPrime();

            newTagPrime.PrimeId             = nextPrime;
            newTagPrime.Tag                 = tagToAdd;
            newTagPrime.AllowNonAdminsToAdd = isTagForAnyone;

            dataContext.TagPrimes.InsertOnSubmit(newTagPrime);
            dataContext.SubmitChanges();

            TagToPrimeDictionary.ResetTagToPrimeDictionaries();

            return(createResponseObject(
                       String.Format("התג {0} התווסף בהצלחה", tagToAdd)));
        }
        public static IEnumerable <object> AddTag(
            string tagToAdd, bool isTagForAnyone, string type)
        {
            lock (LOCK)
            {
                if (!CurrentMisparIshi.IsAdmin())
                {
                    return(createResponseObject(
                               "You're not an admin, what are you doing here??"));
                }

                if (tagToAdd.Contains(" "))
                {
                    return(createResponseObject(
                               "אסור להוסיף תגים עם רווחים"));
                }

                if (tagToAdd.Length == 0)
                {
                    return(createResponseObject("נו באמת..."));
                }

                if (type.Length == 0)
                {
                    return(createResponseObject("נא להוסיף סוג"));
                }


                var nextPrime = TagToPrimeDictionary.GetNextPrime();
                if (nextPrime == -1)
                {
                    return(createResponseObject(
                               "יש 10,000 תגים ויותר מזה לא נתמך"));
                }


                var dataContext         = new PersonDataContext();
                var alreadyExistingTags =
                    dataContext.TagPrimes.Where(tag => tag.Tag.Equals(tagToAdd));
                if (alreadyExistingTags.Count() > 0)
                {
                    return(createResponseObject(
                               String.Format("התג {0} כבר קיים", tagToAdd)));
                }

                var newTagPrime = new TagPrime();
                newTagPrime.PrimeId             = nextPrime;
                newTagPrime.Tag                 = tagToAdd;
                newTagPrime.AllowNonAdminsToAdd = isTagForAnyone;
                newTagPrime.Type                = type;

                dataContext.TagPrimes.InsertOnSubmit(newTagPrime);
                dataContext.SubmitChanges();

                TagToPrimeDictionary.ResetTagToPrimeDictionaries();

                AdminChangeWriter.WriteAdminChange(
                    String.Format("Added tag {0} of type {1}", tagToAdd, type));

                return(createResponseObject(
                           String.Format("התג {0} מסוג {1} התווסף בהצלחה", tagToAdd, type)));
            }
        }