コード例 #1
0
		public void PanelNameNext(object o, System.EventArgs e)
		{
			if (Page.IsValid)
			{
				Guid DuplicateGuid = (Guid)ViewState["BrandDuplicateGuid"];
				BrandSet bs = new BrandSet(new Query(new Q(Brand.Columns.DuplicateGuid, DuplicateGuid)));
				if (bs.Count > 0)
					Response.Redirect("/popup/newbrand/k-" + bs[0].K.ToString());
				else
				{
					Brand b = new Brand();
					b.DateTimeCreated = DateTime.Now;
					b.Name = Cambro.Web.Helpers.StripHtml(NameTextBox.Text.Trim());
					b.IsNew = true;
					b.OwnerUsrK = Usr.Current.K;
					b.IsEdited = false;
					b.DuplicateGuid = DuplicateGuid;
					b.Update();
					b.CreateUniqueUrlName(false);

					//create a new group
					Group g = new Group();
					g.Name = b.Name;
					g.ThemeK = 1;
					g.Description = b.Name + " regulars group for discussing " + b.Name + " parties";
					g.PostingRules = "Discussions about " + b.Name + " parties only. Other topics may be deleted by group moderators.";
					g.DateTimeCreated = DateTime.Now;
					g.PrivateGroupPage = false;
					g.PrivateChat = false;
					g.PrivateMemberList = false;
					g.Restriction = Bobs.Group.RestrictionEnum.None;
					g.CountryK = 0;
					g.PlaceK = 0;
					g.MusicTypeK = 0;
					g.BrandK = b.K;
					g.UrlName = "parties/" + b.UrlName;
					g.EmailOnAllThreads = false;
					g.DuplicateGuid = Guid.NewGuid();

					g.Update();
					b.GroupK = g.K;
					b.Update();

					Response.Redirect("/popup/newbrand/k-" + b.K.ToString());
				}
			}
		}
コード例 #2
0
ファイル: Edit.ascx.cs プロジェクト: davelondon/dontstayin
		void Save(bool RedirectToPic)
		{
			if (IsEdit)
			{
				string newName = Cambro.Web.Helpers.Strip(NameTextBox.Text);
				bool changedName = !CurrentGroup.Name.Equals(newName);
				CurrentGroup.Name = newName;

				CurrentGroup.Description = Cambro.Web.Helpers.Strip(DescriptionTextBox.Text);
				CurrentGroup.PostingRules = Cambro.Web.Helpers.Strip(RulesTextBox.Text);
				CurrentGroup.LongDescriptionHtml = IntroHtml.GetHtml();

				bool newPrivateChat;
				if (GroupPagePrivate.Checked)
				{
					CurrentGroup.PrivateGroupPage = true;
					CurrentGroup.PrivateMemberList = true;
					newPrivateChat = true;
				}
				else
				{
					CurrentGroup.PrivateGroupPage = false;
					CurrentGroup.PrivateMemberList = MembersListPrivate.Checked;
					newPrivateChat = ChatForumPrivate.Checked;
				}
				bool changedPrivateChat = newPrivateChat != CurrentGroup.PrivateChat;
				CurrentGroup.PrivateChat = newPrivateChat;

				if (MembershipMember.Checked)
					CurrentGroup.Restriction = Group.RestrictionEnum.Member;
				else if (MembershipModerator.Checked)
					CurrentGroup.Restriction = Group.RestrictionEnum.Moderator;
				else
					CurrentGroup.Restriction = Group.RestrictionEnum.None;

				int newTheme;
				if (ThemesRadioButtonList.SelectedValue.Equals("18"))
					newTheme = 0;
				else
				{
					Theme t = new Theme(int.Parse(ThemesRadioButtonList.SelectedValue));
					newTheme = t.K;
				}
				bool changedTheme = newTheme != CurrentGroup.ThemeK;
				CurrentGroup.ThemeK = newTheme;


				int newCountry;
				int oldCountry = CurrentGroup.CountryK;
				if (LocationTypeCountry.Checked || LocationTypePlace.Checked)
				{
					Country c = new Country(int.Parse(LocationCountryDropDown.SelectedValue));
					if (!c.Enabled)
						throw new Exception("invalid country!");
					newCountry = c.K;
				}
				else
				{
					newCountry = 0;
				}
				bool changedCountry = CurrentGroup.CountryK != newCountry;
				CurrentGroup.CountryK = newCountry;

				int newPlace;
				int oldPlace = CurrentGroup.PlaceK;
				if (LocationTypePlace.Checked)
				{
					Place p = new Place(int.Parse(LocationPlaceDropDown.SelectedValue));
					if (!p.Enabled || p.CountryK != CurrentGroup.CountryK)
						throw new Exception("invalid place!");
					newPlace = p.K;
				}
				else
				{
					newPlace = 0;
				}
				bool changedPlace = CurrentGroup.PlaceK != newPlace;
				CurrentGroup.PlaceK = newPlace;

				int newMusicType;
				if (CurrentGroup.ThemeK == 1 || CurrentGroup.ThemeK == 2)
				{
					if (!MusicTypesRadioButtonList.SelectedValue.Equals("0"))
					{
						MusicType mt = new MusicType(int.Parse(MusicTypesRadioButtonList.SelectedValue));
						if (!(mt.ParentK == 0 || mt.ParentK == 1))
							throw new Exception("Invalid music type");
						newMusicType = mt.K;
					}
					else
					{
						newMusicType = 0;
					}
				}
				else
				{
					newMusicType = 0;
				}
				bool changedMusic = CurrentGroup.MusicTypeK != newMusicType;
				CurrentGroup.MusicTypeK = newMusicType;

				if (changedName)
					CurrentGroup.CreateUniqueUrlName(false);

				Transaction transaction = null;//new Transaction();
				try
				{
					if (changedPrivateChat)
					{
						Update update = new Update();
						update.Table = TablesEnum.Thread;
						update.Changes.Add(new Assign(Thread.Columns.PrivateGroup, CurrentGroup.PrivateChat));
						update.Where = new Q(Thread.Columns.GroupK, CurrentGroup.K);
						update.Run(transaction);
					}

					if (changedTheme)
					{
						Update update = new Update();
						update.Table = TablesEnum.Thread;
						update.Changes.Add(new Assign(Thread.Columns.ThemeK, CurrentGroup.ThemeK));
						update.Where = new Q(Thread.Columns.GroupK, CurrentGroup.K);
						update.Run(transaction);
					}

					if (changedCountry)
					{
						Update update = new Update();
						update.Table = TablesEnum.Thread;
						update.Changes.Add(new Assign(Thread.Columns.CountryK, CurrentGroup.CountryK));
						update.Where = new And(new Q(Thread.Columns.ParentObjectType, Model.Entities.ObjectType.Group), new Q(Thread.Columns.ParentObjectK, CurrentGroup.K));
						update.Run(transaction);
					}

					if (changedPlace)
					{
						Update update = new Update();
						update.Table = TablesEnum.Thread;
						update.Changes.Add(new Assign(Thread.Columns.PlaceK, CurrentGroup.PlaceK));
						update.Where = new And(new Q(Thread.Columns.ParentObjectType, Model.Entities.ObjectType.Group), new Q(Thread.Columns.ParentObjectK, CurrentGroup.K));
						update.Run(transaction);

						if (oldPlace > 0)
						{
							Place oldP = new Place(oldPlace);
							oldP.UpdateTotalComments(null);
						}
						if (newPlace > 0)
						{
							Place newP = new Place(newPlace);
							newP.UpdateTotalComments(null);
						}
					}

					if (changedMusic)
					{
						Update update = new Update();
						update.Table = TablesEnum.Thread;
						update.Changes.Add(new Assign(Thread.Columns.MusicTypeK, CurrentGroup.MusicTypeK));
						update.Where = new Q(Thread.Columns.GroupK, CurrentGroup.K);
						update.Run(transaction);
					}

					if (changedName)
					{
						Utilities.UpdateChildUrlFragmentsJob job = new Utilities.UpdateChildUrlFragmentsJob(Model.Entities.ObjectType.Group, CurrentGroup.K, true);
						job.ExecuteAsynchronously();
					}
					CurrentGroup.Update(transaction);

					//transaction.Commit();
				}
				catch (Exception ex)
				{
					//transaction.Rollback();
					throw ex;
				}
				finally
				{
					//transaction.Close();
				}
				if (RedirectToPic)
				{
					if (ContainerPage.Url["promoterk"].IsInt)
						Response.Redirect(CurrentGroup.UrlApp("edit", "pic", "", "promoterk", ContainerPage.Url["promoterk"]));
					else
						Response.Redirect(CurrentGroup.UrlApp("edit", "pic", ""));
				}
				else
				{
					RedirectSaved();
				}


			}
			else
			{
				GroupSet gsDup = new GroupSet(new Query(new Q(Group.Columns.DuplicateGuid, (Guid)ContainerPage.ViewStatePublic["GroupDuplicateGuid"])));
				if (gsDup.Count != 0)
				{
					Response.Redirect(gsDup[0].UrlApp("edit", "pic", ""));
				}
				else
				{
					Group g = new Group();
					g.Name = Cambro.Web.Helpers.Strip(NameTextBox.Text);
					g.Description = Cambro.Web.Helpers.Strip(DescriptionTextBox.Text);

					g.LongDescriptionHtml = IntroHtml.GetHtml();
					
					g.PostingRules = Cambro.Web.Helpers.Strip(RulesTextBox.Text, true, true, false, true);
					g.DateTimeCreated = DateTime.Now;
					g.PrivateGroupPage = GroupPagePrivate.Checked;
					if (GroupPagePrivate.Checked)
					{
						g.PrivateMemberList = true;
						g.PrivateChat = true;
					}
					else
					{
						g.PrivateMemberList = MembersListPrivate.Checked;
						g.PrivateChat = ChatForumPrivate.Checked;
					}

					if (MembershipMember.Checked)
						g.Restriction = Group.RestrictionEnum.Member;
					else if (MembershipModerator.Checked)
						g.Restriction = Group.RestrictionEnum.Moderator;
					else
						g.Restriction = Group.RestrictionEnum.None;

					if (ThemesRadioButtonList.SelectedValue.Equals("18"))
						g.ThemeK = 0;
					else
					{
						Theme t = new Theme(int.Parse(ThemesRadioButtonList.SelectedValue));
						g.ThemeK = t.K;
					}

					if (LocationTypeCountry.Checked || LocationTypePlace.Checked)
					{
						Country c = new Country(int.Parse(LocationCountryDropDown.SelectedValue));
						if (!c.Enabled)
							throw new Exception("invalid country!");
						g.CountryK = c.K;
					}
					if (LocationTypePlace.Checked)
					{
						Place p = new Place(int.Parse(LocationPlaceDropDown.SelectedValue));
						if (!p.Enabled || p.CountryK != g.CountryK)
							throw new Exception("invalid place!");
						g.PlaceK = p.K;
					}

					if (g.ThemeK == 1 || g.ThemeK == 2)
					{
						if (!MusicTypesRadioButtonList.SelectedValue.Equals("0"))
						{
							MusicType mt = new MusicType(int.Parse(MusicTypesRadioButtonList.SelectedValue));
							if (!(mt.ParentK == 0 || mt.ParentK == 1))
								throw new Exception("Invalid music type");
							g.MusicTypeK = mt.K;
						}
					}

					g.CreateUniqueUrlName(false);

					g.DuplicateGuid = (Guid)ContainerPage.ViewStatePublic["GroupDuplicateGuid"];
					g.EmailOnAllThreads = false;

					g.Update();

					g.ChangeUsr(false, Usr.Current.K, true, true, true, true, Bobs.GroupUsr.StatusEnum.Member, DateTime.Now, true);

					Response.Redirect(g.UrlApp("edit", "pic", ""));
				}
			}
		}