protected void OnRowCommand(object o, GridViewCommandEventArgs e)
		{
			TagPhotoHistory tph = new TagPhotoHistory(int.Parse((string) e.CommandArgument));
			switch (e.CommandName)
			{
				case "Disable":
					{
						tph.TagPhoto.SetDisabledAndUpdate(true);
						Bind();
						break;
					}
				case "Enable":
					{
						tph.TagPhoto.SetDisabledAndUpdate(false);
						Bind();
						break;
					}
				case "Block":
					{
						
						tph.TagPhoto.Tag.SetBlockedAndUpdate(true);
						Bind();
						break;
					}
				case "Unblock":
					{
						tph.TagPhoto.Tag.SetBlockedAndUpdate(false);
						Bind();
						break;
					}
				default: throw new NotImplementedException();
			}
		}
Beispiel #2
0
		public static Tag AddTag(string tagText, Tagging.ITaggable objectToTag, Usr usrAddingTag)
		{
			try
			{
				Transaction t = new Transaction();
				try
				{
					Tag tag = Tag.GetTag(tagText);
					if (tag.Blocked)
					{
						throw new InvalidTagException();
					}
					TagPhoto tagPhoto = TagPhoto.GetTagPhoto(tag.K, objectToTag.K);
					TagPhotoHistory.TagPhotoHistoryAction action = TagPhotoHistory.TagPhotoHistoryAction.Created;
					if (tagPhoto == null)
					{
						tagPhoto = new TagPhoto()
						{
							TagK = tag.K,
							PhotoK = objectToTag.K,
							Disabled = false
						};
						tagPhoto.Update(t);
						action = TagPhotoHistory.TagPhotoHistoryAction.Created;
					}
					if (tagPhoto.Disabled)
					{
						if (!usrAddingTag.IsJunior)
						{
							throw new Exception("You do not have rights to re-enable that tag");
						}
						tagPhoto.Disabled = false;
						tagPhoto.Update(t);
						action = TagPhotoHistory.TagPhotoHistoryAction.Enabled;
					}
					TagPhotoHistory history = new TagPhotoHistory()
					{
						DateTime = DateTime.Now,
						Action = action,
						UsrK = usrAddingTag.K,
						TagPhotoK = tagPhoto.K
					};
					history.Update(t);
					t.Commit();

					return tag;
				}
				catch (Exception ex)
				{
					t.Rollback();
					throw ex;
				}
			}
			catch (InvalidTagException)
			{
				return null;
			}
		}
Beispiel #3
0
		public void SetBlockedAndUpdate(bool blocked)
		{
			if (!Usr.Current.IsAdmin)
			{
				throw new Exception("You need to be an admin to block or unblock a tag");
			}
			Transaction t = new Transaction();


			Query q = new Query(new Q(TagPhoto.Columns.TagK, this.K));
			List<int> tagPhotoKs = (new TagPhotoSet(q)).ToList().ConvertAll(tagPhoto => tagPhoto.K);

			List<Assign> changes = new List<Assign>()
				{
					new Assign(TagPhoto.Columns.Disabled, blocked)
				};

			Q condition = new And(
				new Q(TagPhoto.Columns.TagK, this.K),
				new Q(TagPhoto.Columns.Disabled, !blocked)
			);
			Update u = new Update(TablesEnum.TagPhoto, changes, condition);
			u.Run(t);
			foreach (int tagPhotoK in tagPhotoKs)
			{
				TagPhotoHistory historyItem = new TagPhotoHistory()
				{
					Action = blocked ? TagPhotoHistory.TagPhotoHistoryAction.Blocked : TagPhotoHistory.TagPhotoHistoryAction.Unblocked,
					DateTime = DateTime.Now,
					TagPhotoK = tagPhotoK,
					UsrK = Usr.Current.K
				};
				historyItem.Update(t);
			}



			this.Blocked = blocked;
			this.BlockedDateTime = DateTime.Now;
			this.BlockedByUsrK = Usr.Current.K;
			this.Update(t);

			t.Commit();
			(new Caching.CacheKeys.NamespaceCacheKey(CacheKeyPrefix.TagCloudVersion)).Invalidate();
		}
Beispiel #4
0
		public void SetDisabledAndUpdate(bool disabled)
		{
			Transaction transaction = new Transaction();
			try
			{
				this.Disabled = disabled;
				this.Update(transaction);
				TagPhotoHistory historyItem = new TagPhotoHistory()
				{
					Action = disabled ? TagPhotoHistory.TagPhotoHistoryAction.Disabled : TagPhotoHistory.TagPhotoHistoryAction.Enabled,
					DateTime = DateTime.Now,
					TagPhotoK = this.K,
					UsrK = Usr.Current.K
				};
				historyItem.Update(transaction);
				transaction.Commit();
			}
			catch (Exception ex)
			{
				transaction.Rollback();
			}
		}