void uiSaveButton_Click(object sender, EventArgs e) { if (!uiPlacesChooser.SelectedPlaceKs.Any()) { throw new Exception("You cannot visit nowhere. This should not have been an available option from the site"); } using (var transaction = new Transaction()) { Delete delete = new Delete(TablesEnum.UsrPlaceVisit, new Q(UsrPlaceVisit.Columns.UsrK, Usr.Current.K)); delete.Run(transaction); foreach (var item in this.uiPlacesChooser.SelectedPlaceKs) { UsrPlaceVisit utv = new UsrPlaceVisit(); utv.UsrK = Usr.Current.K; utv.PlaceK = item; utv.Update(transaction); } transaction.Commit(); Usr.Current.UpdatePlacesVisitCount(true); } this.uiSaveButton.Attributes["disabled"] = "true"; }
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; } }
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(); }
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); } }
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()); }
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(); } }