Esempio n. 1
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;
			}
		}
Esempio n. 2
0
		public static void UpdateTicketsStatusOfEvents()
		{
			Transaction t = new Transaction();
			try
			{
			   Update clear = new Update();
			   clear.Changes.Add(new Assign(Event.Columns.IsTicketsAvailable, false));
			   clear.Table = TablesEnum.Event;
			   clear.Where = new Q(Event.Columns.IsTicketsAvailable, true);
			   Console.WriteLine("Cleared {0} row(s)", clear.Run(t));

			   Update up = new Update();
			   up.Table = TablesEnum.Event;
			   up.Changes.Add(new Assign(Event.Columns.IsTicketsAvailable, true));
			   up.Where = new Q(true);
			   up.From = new Join(
				   new TableElement(TablesEnum.Event),
				   new TableElement(TablesEnum.TicketRun),
				   QueryJoinType.Inner,
				   new And(
					   new Q(TicketRun.Columns.EndDateTime, QueryOperator.GreaterThan, DateTime.Now),
					   new Q(TicketRun.Columns.StartDateTime, QueryOperator.LessThanOrEqualTo, DateTime.Now),
					   new Q(TicketRun.Columns.SoldTickets, QueryOperator.LessThan, TicketRun.Columns.MaxTickets, true),
					   new Q(TicketRun.Columns.Paused, false),
					   new Q(Event.Columns.K, TicketRun.Columns.EventK, true)
				   )
			   );
			   Console.WriteLine("Updated {0} row(s)", up.Run(t));

			   t.Commit();
			}
			catch (Exception ex)
			{
			   t.Rollback();
			   Utilities.AdminEmailAlert("Exception updating TicketsAvailable flag on all events", "Exception updating TicketsAvailable flag on all events", ex);
			}
			finally
			{
			   t.Close();
			}

			Update clearHilight = new Update();
			clearHilight.Changes.Add(new Assign(Event.Columns.HasHilight, false));
			clearHilight.Table = TablesEnum.Event;
			clearHilight.Where = new And(
									new Q(Event.Columns.IsTicketsAvailable, false),
									new Q(Event.Columns.Donated, false),
									new Q(Event.Columns.HasHilight, true));
			Console.WriteLine("Cleared hilight on {0} row(s)", clearHilight.Run());


			Update setHilight = new Update();
			setHilight.Changes.Add(new Assign(Event.Columns.HasHilight, true));
			setHilight.Table = TablesEnum.Event;
			setHilight.Where = new And(
									new Or(new Q(Event.Columns.IsTicketsAvailable, true), new Q(Event.Columns.Donated, true)),
									new Q(Event.Columns.HasHilight, false));
			Console.WriteLine("Set hilight on {0} row(s)", setHilight.Run());

		}
Esempio n. 3
0
		public static void UpdateTicketHeatOfEvents()
		{
			//UPDATE [Event] set [Event].[TicketHeat] = sumBookingFee FROM 
			//(SELECT [Ticket].[EventK], SUM([Ticket].[BookingFee]) AS sumBookingFee FROM [Ticket] WHERE [Ticket].[BuyDateTime]>DATEADD(day, -2, GETDATE()) AND [Ticket].[Enabled] = 1 GROUP BY [Ticket].[EventK]) t1 
			//INNER JOIN [Event] on t1.[EventK] = [Event].[K]

			Transaction t = new Transaction();
			try
			{
				Update clear = new Update();
				clear.Changes.Add(new Assign(Event.Columns.TicketHeat, 0.0));
				clear.Table = TablesEnum.Event;
				clear.Where = new Q(Event.Columns.TicketHeat, QueryOperator.GreaterThan, 0.0);
				Console.WriteLine("Cleared {0} row(s)", clear.Run(t));

				Update up = new Update();
				up.Table = TablesEnum.Event;
				up.Changes.Add(new Assign.Override(Event.Columns.TicketHeat, "sumBookingFee"));
				up.Where = new Q(true);
				up.From = new Join(
					new Join.StringOverride(
						"(SELECT [Ticket].[EventK], SUM([Ticket].[BookingFee]) AS sumBookingFee FROM [Ticket] WHERE [Ticket].[BuyDateTime]>DATEADD(day, -7, GETDATE()) AND [Ticket].[Enabled] = 1 GROUP BY [Ticket].[EventK]) t1"),
					new TableElement(TablesEnum.Event),
					QueryJoinType.Inner,
					new StringQueryCondition("t1.[EventK] = [Event].[K]"));
				
				Console.WriteLine("Updated {0} row(s)", up.Run(t));

				t.Commit();
			}
			catch (Exception ex)
			{
				t.Rollback();
				Utilities.AdminEmailAlert("Exception updating TicketHeat flag on all events", "Exception updating TicketHeat flag on all events", ex);
			}
			finally
			{
				t.Close();
			}

			try
			{
				Event ev1 = new Event(159336);
				ev1.TicketHeat = 1001;
				ev1.Update();
			}
			catch(Exception ex)
			{
				Utilities.AdminEmailAlert("Exception updating TicketHeat flag on CreamFields 159336", "Exception updating TicketHeat flag on CreamFields 159336", ex);
			}

			try
			{
				Event ev2 = new Event(166002);
				ev2.TicketHeat = 1000;
				ev2.Update();
			}
			catch (Exception ex)
			{
				Utilities.AdminEmailAlert("Exception updating TicketHeat flag on CreamFields 166002", "Exception updating TicketHeat flag on CreamFields 166002", ex);
			}

			

			
			
		}
Esempio n. 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();
			}
		}