Beispiel #1
0
		public void MergeAndDelete(Event merge)
		{
			if (this.K == merge.K)
				throw new DsiUserFriendlyException("Can't merge event into itself!");

			Cambro.Web.Helpers.WriteAlertHeader();

			//throw new Exception("This function isn't finished yet!");

			Cambro.Web.Helpers.WriteAlert("Starting merge...", 1);

			#region Articles
			if (true)
			{

				Query q = new Query();
				q.QueryCondition = new Q(Article.Columns.EventK, merge.K);
				ArticleSet ars = new ArticleSet(q);
				foreach (Article a in ars)
				{
					Cambro.Web.Helpers.WriteAlert("Merging article " + a.K + "...", 2);
					a.ParentObjectK = this.K;
					a.EventK = this.K;

					if (a.Relevance <= Model.Entities.Article.RelevanceEnum.Venue)
						a.VenueK = this.VenueK;
					else
						a.VenueK = 0;

					if (a.Relevance <= Model.Entities.Article.RelevanceEnum.Place)
						a.PlaceK = this.Venue.PlaceK;
					else
						a.PlaceK = 0;

					if (a.Relevance <= Model.Entities.Article.RelevanceEnum.Country)
						a.CountryK = this.Venue.Place.CountryK;
					else
						a.CountryK = 0;

					a.UrlFragment = this.UrlFilterPartVenueDate;
					a.Update();


					#region Threads
					if (true)
					{
						Update u = new Update();
						u.Table = TablesEnum.Thread;
						u.Where = new Q(Thread.Columns.ArticleK, a.K);
						u.Changes.Add(new Assign(Thread.Columns.UrlFragment, a.UrlFilterPart));
						u.Changes.Add(new Assign(Thread.Columns.EventK, this.K));
						u.Changes.Add(new Assign(Thread.Columns.VenueK, this.VenueK));
						u.Changes.Add(new Assign(Thread.Columns.PlaceK, this.Venue.PlaceK));
						u.Changes.Add(new Assign(Thread.Columns.CountryK, this.Venue.Place.CountryK));
						u.Run();
					}
					#endregion
					#region Galleries
					if (true)
					{
						Update u = new Update();
						u.Table = TablesEnum.Gallery;
						u.Where = new Q(Gallery.Columns.ArticleK, a.K);
						u.Changes.Add(new Assign(Gallery.Columns.UrlFragment, a.UrlFilterPart));
						u.Run();
					}
					#endregion
					#region Photos
					if (true)
					{
						Update u = new Update();
						u.Table = TablesEnum.Photo;
						u.Where = new Q(Photo.Columns.ArticleK, a.K);
						u.Changes.Add(new Assign(Photo.Columns.UrlFragment, a.UrlFilterPart));
						u.Run();
					}
					#endregion
				}
				Cambro.Web.Helpers.WriteAlert("Done merging articles...", 2);
			}
			#endregion
			#region Banners
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging banners...", 4);
				Update u = new Update();
				u.Table = TablesEnum.Banner;
				u.Where = new Q(Banner.Columns.EventK, merge.K);
				u.Changes.Add(new Assign(Banner.Columns.EventK, this.K));
				u.Run();
				Cambro.Web.Helpers.WriteAlert("Done merging banners...", 4);
			}
			#endregion
			#region Comp
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging competitions...", 5);
				Update u = new Update();
				u.Table = TablesEnum.Comp;
				u.Where = new Q(Comp.Columns.EventK, merge.K);
				u.Changes.Add(new Assign(Comp.Columns.EventK, this.K));
				u.Run();
				Cambro.Web.Helpers.WriteAlert("Done merging competitions...", 5);
			}
			#endregion
			#region EventMusicType
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging music types...", 6);
				Query q1 = new Query();
				q1.TableElement = MusicType.EventJoin;
				q1.QueryCondition = new Q(Event.Columns.K, merge.K);
				MusicTypeSet ems1 = new MusicTypeSet(q1);

				Query q2 = new Query();
				q2.TableElement = MusicType.EventJoin;
				q2.QueryCondition = new Q(Event.Columns.K, this.K);
				MusicTypeSet ems2 = new MusicTypeSet(q2);

				bool hasAllMuisc = false;
				ArrayList majorTypes = new ArrayList();
				ArrayList relevantTypes = new ArrayList();

				#region find major types
				foreach (MusicType mt in ems1)
				{
					if (mt.K == 1)
					{
						hasAllMuisc = true;
						break;
					}
					if (mt.ParentK == 1 && !majorTypes.Contains(mt.K))
						majorTypes.Add(mt.K);
				}
				if (!hasAllMuisc)
				{
					foreach (MusicType mt in ems2)
					{
						if (mt.K == 1)
						{
							hasAllMuisc = true;
							break;
						}
						if (mt.ParentK == 1 && !majorTypes.Contains(mt.K))
							majorTypes.Add(mt.K);
					}
				}
				#endregion
				if (!hasAllMuisc)
				{
					foreach (MusicType mt in ems1)
					{
						if (!majorTypes.Contains(mt.ParentK) && !relevantTypes.Contains(mt.K))
							relevantTypes.Add(mt.K);
					}
					foreach (MusicType mt in ems2)
					{
						if (!majorTypes.Contains(mt.ParentK) && !relevantTypes.Contains(mt.K))
							relevantTypes.Add(mt.K);
					}
				}
				if (hasAllMuisc || relevantTypes.Count == 0)
				{
					Delete d = new Delete(TablesEnum.EventMusicType, new Q(EventMusicType.Columns.EventK, this.K));
					d.Run();
					EventMusicType emt = new EventMusicType();
					emt.EventK = this.K;
					emt.MusicTypeK = 1;
					emt.Update();
				}
				else
				{
					Delete d = new Delete(TablesEnum.EventMusicType, new Q(EventMusicType.Columns.EventK, this.K));
					d.Run();
					foreach (int mtK in relevantTypes)
					{
						EventMusicType emt = new EventMusicType();
						emt.EventK = this.K;
						emt.MusicTypeK = mtK;
						emt.Update();
					}
				}
				Cambro.Web.Helpers.WriteAlert("Done merging music types...", 6);
			}
			#endregion
			#region EventBrand
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging brands...", 7);
				EventBrandSet ebs = new EventBrandSet(new Query(new Q(EventBrand.Columns.EventK, merge.K)));
				foreach (EventBrand eb in ebs)
				{
					try
					{
						EventBrand ebThis = new EventBrand(this.K, eb.BrandK);
					}
					catch
					{
						EventBrand ebThis = new EventBrand();
						ebThis.EventK = this.K;
						ebThis.BrandK = eb.BrandK;
						ebThis.Update();
					}
				}
				Cambro.Web.Helpers.WriteAlert("Done merging brands...", 7);
			}
			#endregion
			 
			#region Gallery
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging galleries...", 9);
				Update u = new Update();
				u.Table = TablesEnum.Gallery;
				u.Where = new Q(Gallery.Columns.EventK, merge.K);
				u.Changes.Add(new Assign(Gallery.Columns.EventK, this.K));
				u.Changes.Add(new Assign(Gallery.Columns.UrlFragment, this.UrlFilterPartVenueDate));
				u.Run();
				Cambro.Web.Helpers.WriteAlert("Done merging galleries...", 9);
			}
			#endregion
			#region Photo
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging photos...", 10);
				Update u = new Update();
				u.Table = TablesEnum.Photo;
				u.Where = new Q(Photo.Columns.EventK, merge.K);
				u.Changes.Add(new Assign(Photo.Columns.EventK, this.K));
				u.Changes.Add(new Assign(Photo.Columns.UrlFragment, this.UrlFilterPartVenueDate));
				u.Run();
				Cambro.Web.Helpers.WriteAlert("Done merging photos...", 10);
			}
			#endregion
			#region GroupEvent
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging group-event links...", 11);
				GroupEventSet ges = new GroupEventSet(new Query(new Q(GroupEvent.Columns.EventK, merge.K)));
				foreach (GroupEvent ge in ges)
				{
					try
					{
						GroupEvent geThis = new GroupEvent(ge.GroupK, this.K);
					}
					catch
					{
						GroupEvent geThis = new GroupEvent();
						geThis.EventK = this.K;
						geThis.GroupK = ge.GroupK;
						geThis.Update();
					}
				}
				Cambro.Web.Helpers.WriteAlert("Done merging group-event links...", 11);
			}
			#endregion
			#region Thread ParentObjects
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging topics (1/2)...", 12);
				Update u = new Update();
				u.Table = TablesEnum.Thread;
				u.Where = new And(
					new Q(Thread.Columns.ParentObjectType, Model.Entities.ObjectType.Event),
					new Q(Thread.Columns.ParentObjectK, merge.K));
				u.Changes.Add(new Assign(Thread.Columns.ParentObjectK, this.K));
				u.Run();
				Cambro.Web.Helpers.WriteAlert("Done merging topics (1/2)...", 12);
			}
			#endregion
			#region Thread
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging topics (2/2)...", 13);
				Update u = new Update();
				u.Table = TablesEnum.Thread;
				u.Where = new And(
					new Q(Thread.Columns.EventK, merge.K),
					new Q(Thread.Columns.ArticleK, 0));
				u.Changes.Add(new Assign(Thread.Columns.EventK, this.K));
				u.Changes.Add(new Assign(Thread.Columns.UrlFragment, this.UrlFilterPartVenueDate));
				u.Run();
				Cambro.Web.Helpers.WriteAlert("Done merging topics (2/2)...", 13);
			}
			#endregion
			#region UsrEventAttended
			if (true)
			{
				Cambro.Web.Helpers.WriteAlert("Merging members...", 14);
				UsrEventAttendedSet ueas = new UsrEventAttendedSet(new Query(new Q(UsrEventAttended.Columns.EventK, merge.K)));
				foreach (UsrEventAttended uea in ueas)
				{
					try
					{
						UsrEventAttended ueaThis = new UsrEventAttended(uea.UsrK, this.K);
						bool changed = false;
						if (!uea.SendUpdate && ueaThis.SendUpdate)
						{
							ueaThis.SendUpdate = false;
							changed = true;
						}
						if (uea.Spotter && !ueaThis.Spotter)
						{
							ueaThis.Spotter = true;
							changed = true;
						}
						if (changed)
							ueaThis.Update();
					}
					catch
					{
						UsrEventAttended ueaThis = new UsrEventAttended();
						ueaThis.EventK = this.K;
						ueaThis.UsrK = uea.UsrK;
						ueaThis.SendUpdate = uea.SendUpdate;
						ueaThis.Spotter = uea.Spotter;
						ueaThis.Update();
					}
				}
				Cambro.Web.Helpers.WriteAlert("Done merging members...", 14);
			}
			#endregion

			if (!this.HasPic)
			{
				Cambro.Web.Helpers.WriteAlert("Merging picture...", 15);
				this.Pic = merge.Pic;
				this.PicMiscK = merge.PicMiscK;
				this.PicPhotoK = merge.PicPhotoK;
				this.PicState = merge.PicState;
				merge.Pic = Guid.Empty;
				merge.PicMiscK = 0;
				merge.PicPhotoK = 0;
				merge.PicState = "";
				merge.Update();
				Cambro.Web.Helpers.WriteAlert("Done merging picture...", 15);
			}

			this.AdminNote += "Event " + merge.K + " was merged with this one " + DateTime.Now.ToString() + ". The admin note from event " + merge.K + " is:\n********************\n" + merge.AdminNote + "\n********************\n";

			if (!this.HasGuestlist && merge.HasGuestlist)
			{
				Cambro.Web.Helpers.WriteAlert("Merging guestlist...", 16);
				this.HasGuestlist = true;
				this.GuestlistOpen = merge.GuestlistOpen;
				this.GuestlistFinished = merge.GuestlistOpen;
				this.GuestlistLimit = merge.GuestlistLimit;
				this.GuestlistCount = merge.GuestlistCount;
				this.GuestlistDetails = merge.GuestlistDetails;
				this.GuestlistPromoterK = merge.GuestlistPromoterK;
				this.GuestlistRegularPrice = merge.GuestlistRegularPrice;
				this.GuestlistPrice = merge.GuestlistPrice;
				this.GuestlistPromotion = merge.GuestlistPromotion;

				Delete d = new Delete(TablesEnum.UsrEventGuestlist, new Q(UsrEventGuestlist.Columns.EventK, this.K));
				d.Run();

				Update u = new Update();
				u.Table = TablesEnum.UsrEventGuestlist;
				u.Where = new Q(UsrEventGuestlist.Columns.EventK, merge.K);
				u.Changes.Add(new Assign(UsrEventGuestlist.Columns.EventK, this.K));
				u.Run();
				Cambro.Web.Helpers.WriteAlert("Done merging guestlist...", 16);
			}

			if (merge.Donated)
				this.Donated = true;

			if (merge.HasHilight)
				this.HasHilight = true;

			this.UpdateUsrAttendCount(false);

			this.Update();

			int mergeVenueK = merge.VenueK;

			Cambro.Web.Helpers.WriteAlert("Deleting old event...", 17);
			merge.DeleteAll(null);
			Cambro.Web.Helpers.WriteAlert("Done deleting old event...", 17);

			if (mergeVenueK != this.VenueK)
			{
				Venue mergeVenue = new Venue(mergeVenueK);
				Cambro.Web.Helpers.WriteAlert("Updating stats for old venue...", 18);
				mergeVenue.UpdateTotalComments(null);
				mergeVenue.UpdateTotalEvents(null);
				Cambro.Web.Helpers.WriteAlert("Done updating stats for old venue...", 18);
			}

			Cambro.Web.Helpers.WriteAlert("Updating stats for new event...", 19);
			this.UpdateMusicTypesStringNoUpdate();
			this.UpdateTotalComments(null);
			this.UpdateHasSpotter(null);
			this.UpdateTotalPhotos(null);
			this.Venue.UpdateTotalEvents(null);
			Cambro.Web.Helpers.WriteAlert("Done updating stats for new event...", 19);

			this.Update();
			Cambro.Web.Helpers.WriteAlert("Done merging events!", 20);


		}
Beispiel #2
0
		public void AssignBrand(int BrandK, bool Add, Transaction transaction)
		{
			try
			{
				EventBrand eb = new EventBrand(this.K, BrandK);
				if (!Add)
				{
					eb.Delete(transaction);
				}
			}
			catch
			{
				if (Add)
				{
					Brand b = new Brand(BrandK);
					EventBrand eb = new EventBrand();
					eb.EventK = this.K;
					eb.BrandK = b.K;
					eb.Update(transaction);
				}
			}
		}
Beispiel #3
0
		public static Event AddEvent(
			string name, 
			int venueK, 
			StartTimes? startTime, 
			DateTime date, 
			string shortDetails, 
			string safeLongDetails, 
			Guid? duplicateGuid, 
			int? capacity, 
			Usr usr, 
			int[] musicTypeKs, 
			int[] brandKs,
			bool spotterRequest,
			string spotterRequestName,
			string spotterRequestNumber)
		{
			Event ev = new Event();

			Venue venue = new Venue(venueK);
			Transaction t = null;//new Transaction();
			try
			{
				ev.AddedDateTime = DateTime.Now;
				ev.VenueK = venue.K;
				ev.Name = Cambro.Web.Helpers.StripHtml(name).Trim();
				ev.StartTime = startTime ?? StartTimes.Evening;;
				ev.DateTime = date;
				ev.ShortDetailsHtml = Cambro.Misc.Utility.Snip(Cambro.Web.Helpers.StripHtml(shortDetails ?? ""), 500);

				ev.LongDetailsHtml = safeLongDetails;

				ev.DuplicateGuid = duplicateGuid ?? Guid.NewGuid();

				ev.Capacity = capacity ?? venue.Capacity;

				ev.AdminNote += "Event added by owner " + DateTime.Now.ToString();

				ev.OwnerUsrK = Usr.Current.K;

				ev.SpotterRequest = spotterRequest;
				ev.SpotterRequestName = spotterRequestName;
				ev.SpotterRequestNumber = spotterRequestNumber;

				if (!usr.IsSuper)
				{
					ev.IsNew = true;
					ev.ModeratorUsrK = Usr.GetEventModeratorUsrK();
				}
				ev.InitUrlFragment();
				ev.Update(t);

				foreach (int musicTypeK in musicTypeKs ?? new int[]{})
				{
					MusicType mt = new MusicType(musicTypeK);
					EventMusicType emt = new EventMusicType();
					emt.EventK = ev.K;
					emt.MusicTypeK = mt.K;
					emt.Update(t);
				}
				foreach (int brandK in brandKs ?? new int[] { })
				{
					EventBrand eb = new EventBrand();
					eb.BrandK = brandK;
					eb.EventK = ev.K;
					eb.Update(t);
				}

				ev.UpdateMusicTypesString(t);

				ev.Venue.UpdateTotalEvents(t);
				ev.Owner.UpdateEventCount(t);

				//t.Commit();
				

			}
			catch (Exception ex)
			{
				//t.Rollback();
				ev.DeleteAll(null);
				throw ex;
			}
			finally
			{
				//t.Close();
			}

			Mailer sm = new Mailer();
			sm.TemplateType = Mailer.TemplateTypes.AnotherSiteUser;
			sm.UsrRecipient = Usr.Current;
			sm.To = Usr.Current.Email;
			sm.Subject = "You've added an event!";
			sm.Body += "<p>You've added an event to the DontStayIn events database.</p>";
			sm.Body += "<p>Click the link below to view the event:</p>";
			sm.Body += "<p><a href=\"[LOGIN(" + ev.Url() + ")]\">" + HttpUtility.HtmlEncode(ev.FriendlyName) + "</a></p>";
			sm.Body += "<h2>Make changes</h2>";
			sm.Body += "<p>You can make changes or corrections to the event details by clicking the link below:</p>";
			sm.Body += "<p><a href=\"[LOGIN(/event-" + ev.K.ToString() + "/edit)]\">Edit your event</a></p>";
			sm.Body += "<h2>How about a banner advert?</h2>";
			sm.Body += "<p>You can add a banner advert to your event by using the link below:</p>";
			sm.Body += "<p><a href=\"[LOGIN(/pages/bannerpreview/eventk-" + ev.K.ToString() + ")]\">Add a banner</a></p>";
			sm.Body += "<h2>Add photos or a review</h2>";
			sm.Body += "<p>After the event you can upload photos or add a review with the links below:</p>";
			sm.Body += "<p><a href=\"[LOGIN(/pages/galleries/add/eventk-" + ev.K.ToString() + ")]\">Add photos</a> or <a href=\"[LOGIN(" + ev.UrlApp("review") + ")]\">add a review</a></p>";
			sm.Body += "<h2>Are you the event promoter?</h2>";
			sm.Body += "<p>If you organise this event, you can sign up for a FREE promoter account by using the link below:</p>";
			sm.Body += "<p><a href=\"[LOGIN(/pages/promoters/edit)]\">Apply for a promoter account</a></p>";
			sm.RedirectUrl = ev.Url();
			sm.Send();
			return ev;

		}
Beispiel #4
0
		public int DuplicateEvent()
		{
			Transaction t = null;//new Transaction();
			Event ev = new Event();
			try
			{
				ev.AddedDateTime = DateTime.Now;
				ev.VenueK = SelectedEvent.VenueK;
				ev.Name = SelectedEvent.Name;
				ev.StartTime = SelectedEvent.StartTime;
				ev.DateTime = NewDateCalendar.SelectedDate;
				ev.ShortDetailsHtml = SelectedEvent.ShortDetailsHtml;
				ev.LongDetailsHtml = SelectedEvent.LongDetailsHtml;
				ev.IsDescriptionText = SelectedEvent.IsDescriptionText;
				ev.IsDescriptionCleanHtml = SelectedEvent.IsDescriptionCleanHtml;
				ev.Capacity = SelectedEvent.Capacity;
				ev.AdminNote = "Event copied from event " + SelectedEvent.K.ToString() + " by owner " + DateTime.Now.ToString();

				if (SelectedEvent.AdminNote.Length > 0)
					ev.AdminNote += "\nprevious admin note: \n*******\n" + SelectedEvent.AdminNote + "\n*******";

				ev.OwnerUsrK = Usr.Current.K;

				ev.IsNew = true;
				ev.ModeratorUsrK = Usr.GetEventModeratorUsrK();
				
				ev.InitUrlFragment();
				ev.Update(t);
				if (SelectedEvent.Pic != Guid.Empty)
				{
					ev.Pic = Guid.NewGuid();

					Storage.AddToStore(
						Storage.GetFromStore(Storage.Stores.Pix, SelectedEvent.Pic, "jpg"),
						Storage.Stores.Pix,
						ev.Pic,
						"jpg",
						ev,
						"Pic");

				}
				ev.Update(t);
				

				foreach (Brand b in SelectedEvent.Brands)
				{
					EventBrand eb = new EventBrand();
					eb.BrandK = b.K;
					eb.EventK = ev.K;
					eb.Update(t);
				}

				ev.Venue.UpdateTotalEvents(t);
				ev.Owner.UpdateEventCount(t);

				if (SelectedEvent.MusicTypes.Count > 0)
				{
					foreach (MusicType mt in SelectedEvent.MusicTypes)
					{
						EventMusicType emt = new EventMusicType();
						emt.EventK = ev.K;
						emt.MusicTypeK = mt.K;
						emt.Update(t);
					}
				}
				ev.UpdateMusicTypesString(t);

				//t.Commit();
			}
			catch (Exception ex)
			{
				//t.Rollback();
				ev.DeleteAll(null);
				if (!ev.Pic.Equals(Guid.Empty))
				{
					Storage.RemoveFromStore(Storage.Stores.Pix, ev.Pic, "jpg");
				}
				throw ex;
			}
			finally
			{
				//t.Close();
			}

			return ev.K;

		}