コード例 #1
0
        public static void AddAdmin(string misparIshi,
                                    bool isSuperAdmin,
                                    // Whether we should set isSuperAdmin if this admin already exists or
                                    // just leave the current value.
                                    bool forceNewAdminLevel = true)
        {
            if (!CurrentMisparIshi.IsSuperAdmin())
            {
                return;
            }
            var dataContext   = new AdminDataContext();
            var existingAdmin = dataContext.Admins
                                .Where(admin => admin.MisparIshi == misparIshi)
                                .FirstOrDefault();

            if (existingAdmin != null)
            {
                if (forceNewAdminLevel)
                {
                    existingAdmin.IsSuperAdmin = isSuperAdmin;
                }
            }
            else
            {
                var newAdmin = new Admin();
                newAdmin.MisparIshi   = misparIshi;
                newAdmin.IsSuperAdmin = isSuperAdmin;
                dataContext.Admins.InsertOnSubmit(newAdmin);
            }
            dataContext.SubmitChanges();
            AdminChangeWriter.WriteAdminChange(
                String.Format("Added admin {0}", misparIshi));
            CurrentMisparIshi.SetAdmins();
        }
コード例 #2
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));
            }
        }
コード例 #3
0
        public static void DeleteAdmin(string misparIshi)
        {
            if (!CurrentMisparIshi.IsSuperAdmin())
            {
                return;
            }
            var dataContext   = new AdminDataContext();
            var existingAdmin = dataContext.Admins
                                .Where(admin => admin.MisparIshi == misparIshi)
                                .FirstOrDefault();

            if (existingAdmin == null || existingAdmin.IsSuperAdmin)
            {
                return;
            }
            dataContext.Admins.DeleteOnSubmit(existingAdmin);
            dataContext.SubmitChanges();
            AdminChangeWriter.WriteAdminChange(
                String.Format("Deleted admin {0}", misparIshi));
            CurrentMisparIshi.SetAdmins();
        }
コード例 #4
0
        public static void AddPersonalField(
            string misparIshi,
            string value,
            string inputType)
        {
            var dataContext = new PersonDataContext();

            var personsFromDb = dataContext.Persons
                                .Where(person => person.MisparIshi.Equals(misparIshi))
                                .ToList();

            if (personsFromDb.Count() != 1)
            {
                return;
            }

            var personFromDb = personsFromDb.First();

            if (!CurrentMisparIshi.IsCurrentUserOrAdmin(
                    personFromDb.MisparIshi))
            {
                return;
            }

            switch (inputType)
            {
            case PersonalFieldAdder.WHAT_I_DO:
                personFromDb.WhatIDo = value;
                break;

            case ADD_MOBILE:
                var normailzedMobileNumber = value.ToValidMobileNumber();
                if (normailzedMobileNumber == null)
                {
                    return;
                }
                personFromDb.Mobile = normailzedMobileNumber;
                personFromDb.MobilePhoneIsManuallyInput = true;
                break;

            case ADD_WORK_NUMBER:
                var normailzedWorkNumber = value.ToValidNonMobileNumber();
                if (normailzedWorkNumber == null)
                {
                    return;
                }
                personFromDb.WorkPhone = normailzedWorkNumber;
                personFromDb.WorkPhoneIsManuallyInput = true;
                break;

            case ADD_OTHER_NUMBER:
                var normailzedOtherNumber = value.ToValidNonMobileNumber();
                if (normailzedOtherNumber == null)
                {
                    return;
                }
                personFromDb.OtherTelephone            = normailzedOtherNumber;
                personFromDb.OtherPhoneIsManuallyInput = true;
                break;

            case SEX:
                personFromDb.Sex = value;
                personFromDb.SexIsManuallyInput = true;
                break;
            }

            dataContext.SubmitChanges();

            if (CurrentMisparIshi.IsAdminButNotCurrentUser(misparIshi))
            {
                AdminChangeWriter.WriteAdminChange(
                    String.Format(
                        "Set field of type {0} for {1} to {2}",
                        inputType,
                        personFromDb.MisparIshi,
                        value));
            }
        }
コード例 #5
0
        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)));
            }
        }