// Changes the ID of the tag with ID tagPrimeIdFrom to tagPrimeIdFrom. // (It actually does this by creating copies and deleting the old ones). // The previously existing tag with tagPrimeIdTo will be deleted. // If the from and to are the same, that tag is just deleted. public static void SwitchTagId( this PersonDataContext dataContext, int tagPrimeIdFrom, int tagPrimeIdTo) { // Make a copy of the tag with ID tagPrimeIdFrom but with // ID tagPrimeIdTo. var tagToCopy = dataContext.GetTagPrime(tagPrimeIdFrom); var copyOfTag = new TagPrime(); copyOfTag.Tag = tagToCopy.Tag; copyOfTag.Type = tagToCopy.Type; copyOfTag.AllowNonAdminsToAdd = tagToCopy.AllowNonAdminsToAdd; copyOfTag.PrimeId = tagPrimeIdTo; var tagToDelete = dataContext.GetTagPrime(tagPrimeIdTo); dataContext.TagPrimes.DeleteOnSubmit(tagToDelete); dataContext.TagPrimes.DeleteOnSubmit(tagToCopy); dataContext.SubmitChanges(); if (tagPrimeIdFrom == tagPrimeIdTo) { return; } dataContext.TagPrimes.InsertOnSubmit(copyOfTag); dataContext.SubmitChanges(); }
public static void makeTagToRemoveUnsearchable( this PersonDataContext dataContext, int tagToRemoveId) { var tagToRemove = dataContext.GetTagPrime(tagToRemoveId); var copyOfTagToRemove = new TagPrime(); copyOfTagToRemove.PrimeId = tagToRemove.PrimeId; copyOfTagToRemove.Tag = TagToPrimeDictionary.INVALID_TAG_NAME; dataContext.TagPrimes.DeleteOnSubmit(tagToRemove); dataContext.SubmitChanges(); dataContext.TagPrimes.InsertOnSubmit(copyOfTagToRemove); dataContext.SubmitChanges(); }
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)); } }
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 void AddWhatIDo(string misparIshi, string value) { 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; } personFromDb.WhatIDo = value; dataContext.SubmitChanges(); }
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)); } }
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))); } }