/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns() { // Controls on Main Campaign Panel GroupService groupService = new GroupService(); List <Group> groups = groupService.Queryable().Where(a => a.GroupType.Guid.Equals(Rock.SystemGuid.GroupType.GROUPTYPE_EVENTATTENDEES)).OrderBy(a => a.Name).ToList(); groups.Insert(0, new Group { Id = None.Id, Name = None.Text }); ddlEventGroup.DataSource = groups; ddlEventGroup.DataBind(); PersonService personService = new PersonService(); List <Person> persons = personService.Queryable().OrderBy(a => a.NickName).ThenBy(a => a.LastName).ToList(); persons.Insert(0, new Person { Id = None.Id, GivenName = None.Text }); ddlContactPerson.DataSource = persons; ddlContactPerson.DataBind(); CampusService campusService = new CampusService(); cpCampuses.Campuses = campusService.Queryable().OrderBy(a => a.Name).ToList();; // Controls on Ad Child Panel MarketingCampaignAdTypeService marketingCampaignAdTypeService = new MarketingCampaignAdTypeService(); var adtypes = marketingCampaignAdTypeService.Queryable().OrderBy(a => a.Name).ToList(); ddlMarketingCampaignAdType.DataSource = adtypes; ddlMarketingCampaignAdType.DataBind(); }
private IQueryable <Campus> GetCampuses(RockContext rockContext = null) { rockContext = rockContext ?? new RockContext(); CampusService campusService = new CampusService(rockContext); return(campusService.Queryable().OrderBy(s => s.Order)); }
/// <summary> /// Handles the Delete event of the gCampuses control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gCampuses_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); CampusService campusService = new CampusService(rockContext); Campus campus = campusService.Get(e.RowKeyId); if (campus != null) { // Don't allow deleting the last campus if (!campusService.Queryable().Where(c => c.Id != campus.Id).Any()) { mdGridWarning.Show(campus.Name + " is the only campus and cannot be deleted (Rock requires at least one campus).", ModalAlertType.Information); return; } string errorMessage; if (!campusService.CanDelete(campus, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } CampusCache.Flush(campus.Id); campusService.Delete(campus); rockContext.SaveChanges(); } BindGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { CampusService campusService = new CampusService(); SortProperty sortProperty = gCampuses.SortProperty; if (sortProperty != null) { gCampuses.DataSource = campusService.Queryable().Sort(sortProperty).ToList(); } else { gCampuses.DataSource = campusService.Queryable().OrderBy(s => s.Name).ToList(); } gCampuses.DataBind(); }
/// <summary> /// Loads the campus picker. /// </summary> private void LoadCampusPicker() { CampusService campusService = new CampusService(new RockContext()); cpCampuses.Campuses = campusService.Queryable().OrderBy(a => a.Name).ToList(); cpCampuses.Visible = cpCampuses.AvailableCampusIds.Count > 0; }
/// <summary> /// Handles the Click event of the btnDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnDelete_Click(object sender, EventArgs e) { var rockContext = new RockContext(); var campusService = new CampusService(rockContext); var campus = new CampusService(rockContext).Get(HiddenCampusId); if (campus != null) { // Don't allow deleting the last campus if (!campusService.Queryable().Where(c => c.Id != campus.Id).Any()) { mdDeleteWarning.Show(campus.Name + " is the only campus and cannot be deleted (Rock requires at least one campus).", ModalAlertType.Information); return; } string errorMessage; if (!campusService.CanDelete(campus, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } campusService.Delete(campus); rockContext.SaveChanges(); NavigateToParentPage(); } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { Campus campus; var rockContext = new RockContext(); var campusService = new CampusService(rockContext); var locationService = new LocationService(rockContext); int campusId = int.Parse(hfCampusId.Value); if (campusId == 0) { campus = new Campus(); campusService.Add(campus); var orders = campusService.Queryable() .Select(t => t.Order) .ToList(); campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0; } else { campus = campusService.Get(campusId); } campus.Name = tbCampusName.Text; campus.IsActive = cbIsActive.Checked; campus.Description = tbDescription.Text; campus.Url = tbUrl.Text; campus.PhoneNumber = tbPhoneNumber.Text; lpLocation.Location = campus.Location; campus.ShortCode = tbCampusCode.Text; campus.TimeZoneId = ddlTimeZone.SelectedValue; var personService = new PersonService(rockContext); var leaderPerson = personService.Get(ppCampusLeader.SelectedValue ?? 0); campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null; campus.ServiceTimes = kvlServiceTimes.Value; campus.LoadAttributes(rockContext); Rock.Attribute.Helper.GetEditValues(phAttributes, campus); if (!campus.IsValid && campus.Location.IsValid) { // Controls will render the error messages return; } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); campus.SaveAttributeValues(rockContext); }); NavigateToParentPage(); }
protected void Page_Load(object sender, EventArgs e) { this.RockPage.AddScriptLink(ResolveUrl("../Scripts/jquery.autocomplete.min.js")); this.RockPage.AddScriptLink(ResolveUrl("../Scripts/underscore.min.js")); this.RockPage.AddScriptLink(ResolveUrl("../Scripts/jstz.min.js")); this.RockPage.AddScriptLink(ResolveUrl("../Scripts/calendar.js")); this.RockPage.AddScriptLink(ResolveUrl("../Scripts/ServiceUEvents.js")); this.RockPage.AddCSSLink(ResolveUrl("../Styles/autocomplete-styles.css")); this.RockPage.AddCSSLink(ResolveUrl("../Styles/ServiceUEvents.css")); this.RockPage.AddCSSLink(ResolveUrl("../Styles/calendar.min.css")); var eventtitleroute = PageParameter("eventcalendarroute"); GetCampus(); if (!Page.IsPostBack) { //i'm filtering out those axd calls becuase they are shwoing up for some reson as a valid valud of eventcalendarroute. if (!string.IsNullOrEmpty(eventtitleroute) && eventtitleroute != "WebResource.axd" && eventtitleroute != "ScriptResource.axd") { var rc = new Rock.Data.RockContext(); // int eventid = 0; string eventId = string.Empty; using ( rc ) { eventId = rc.Database.SqlQuery <string>("exec newpointe_getEventIDbyUrl @url", new SqlParameter("url", eventtitleroute)).ToList <string>()[0]; } if (string.IsNullOrEmpty(eventId)) { SiteCache site = SiteCache.GetSiteByDomain(Request.Url.Host); //site.RedirectToPageNotFoundPage(); } else { hdnEventId.Value = eventId; } } else if (!string.IsNullOrEmpty(eventtitleroute)) { //Response.Redirect( eventtitleroute ); } CampusService campusService = new CampusService(new Rock.Data.RockContext()); var qry = campusService.Queryable().Where(c => !c.Name.Contains("Central Services") && !c.Name.Contains("Online") && !c.Name.Contains("Future") && (c.IsActive ?? false)).Select(p => new { Name = p.Name.Replace("Campus", "").Trim(), ShortCode = p.ShortCode }).OrderBy(c => c.Name).ToList(); rptCampuses.DataSource = qry; rptCampuses.DataBind(); qry.Insert(0, new { Name = "ALL", ShortCode = "ALL" }); ddlCampusDropdown.DataSource = qry; ddlCampusDropdown.DataValueField = "ShortCode"; ddlCampusDropdown.DataTextField = "Name"; ddlCampusDropdown.DataBind(); } }
private static int LoadByGuid2(Guid guid, RockContext rockContext) { var campusService = new CampusService(rockContext); return(campusService .Queryable().AsNoTracking() .Where(c => c.Guid.Equals(guid)) .Select(c => c.Id) .FirstOrDefault()); }
/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns() { CampusService campusService = new CampusService(); List <Campus> campuses = campusService.Queryable().OrderBy(a => a.Name).ToList(); campuses.Insert(0, new Campus { Id = None.Id, Name = None.Text }); ddlCampus.DataSource = campuses; ddlCampus.DataBind(); }
private static CampusCache LoadById2(int id, RockContext rockContext) { var campusService = new CampusService(rockContext); var campusModel = campusService .Queryable("Location").AsNoTracking() .FirstOrDefault(c => c.Id == id); if (campusModel != null) { return(new CampusCache(campusModel)); } return(null); }
/// <summary> /// Binds the filter. /// </summary> private void BindFilter() { txtAccountName.Text = rAccountFilter.GetUserPreference("Account Name"); var campusService = new CampusService(new RockContext()); ddlCampus.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (Campus campus in campusService.Queryable()) { ListItem li = new ListItem(campus.Name, campus.Id.ToString()); li.Selected = campus.Id.ToString() == rAccountFilter.GetUserPreference("Campus"); ddlCampus.Items.Add(li); } ddlIsActive.SelectedValue = rAccountFilter.GetUserPreference("Active"); ddlIsTaxDeductible.SelectedValue = rAccountFilter.GetUserPreference("Tax Deductible"); }
/// <summary> /// Creates the control(s) neccessary for prompting user for a new value /// </summary> /// <param name="configurationValues">The configuration values.</param> /// <param name="id"></param> /// <returns> /// The control /// </returns> public override System.Web.UI.Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id) { var editControl = new RockDropDownList { ID = id }; CampusService campusService = new CampusService(); var campusList = campusService.Queryable().OrderBy(a => a.Name).ToList(); editControl.Items.Add(None.ListItem); foreach (var campus in campusList) { editControl.Items.Add(new ListItem(campus.Name, campus.Id.ToString())); } return(editControl); }
/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns() { // Controls on Main Campaign Panel GroupService groupService = new GroupService(); List <Group> groups = groupService.Queryable().Where(a => a.GroupType.Guid.Equals(new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_EVENTATTENDEES))).OrderBy(a => a.Name).ToList(); groups.Insert(0, new Group { Id = None.Id, Name = None.Text }); ddlEventGroup.DataSource = groups; ddlEventGroup.DataBind(); CampusService campusService = new CampusService(); cpCampuses.Campuses = campusService.Queryable().OrderBy(a => a.Name).ToList(); cpCampuses.Visible = cpCampuses.AvailableCampusIds.Count > 0; }
protected void mdCampus_OnSaveClick(object sender, EventArgs e) { GroupService groupService = new GroupService(rockContext); CampusService campusService = new CampusService(rockContext); var personFamily = _targetPerson.GetFamilies(rockContext).FirstOrDefault(); var theGroup = groupService.Queryable().Where(a => a.Id == personFamily.Id).FirstOrDefault(); var theCampus = campusService.Queryable().Where(c => c.Name == cpCampus.SelectedValue).FirstOrDefault(); theGroup.Campus = theCampus; rockContext.SaveChanges(); mdCampus.Hide(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { var rockContext = new RockContext(); string itemId = PageParameter("businessId"); // Load the Giving Group drop down ddlGivingGroup.Items.Clear(); ddlGivingGroup.Items.Add(new ListItem(None.Text, None.IdValue)); if (int.Parse(itemId) > 0) { var businessService = new PersonService(rockContext); var business = businessService.Get(int.Parse(itemId)); ddlGivingGroup.Items.Add(new ListItem(business.FirstName, business.Id.ToString())); } // Load the Campus drop down ddlCampus.Items.Clear(); ddlCampus.Items.Add(new ListItem(string.Empty, string.Empty)); var campusService = new CampusService(new RockContext()); foreach (Campus campus in campusService.Queryable()) { ListItem li = new ListItem(campus.Name, campus.Id.ToString()); ddlCampus.Items.Add(li); } if (!string.IsNullOrWhiteSpace(itemId)) { ShowDetail("businessId", int.Parse(itemId)); } else { pnlDetails.Visible = false; } } if (!string.IsNullOrWhiteSpace(hfModalOpen.Value)) { mdAddContact.Show(); } }
/// <summary> /// Binds the campuses. /// </summary> protected void BindCampuses() { btnCampusList.Items.Clear(); CampusService campusService = new CampusService(); var items = campusService.Queryable().OrderBy(a => a.Name).Distinct(); if (items.Any()) { btnCampusList.DataSource = items.ToList(); btnCampusList.DataTextField = "Name"; btnCampusList.DataValueField = "Id"; btnCampusList.DataBind(); btnCampusList.SelectedValue = btnCampusList.Items[0].Value; } else { divCampus.Visible = false; } }
/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns() { GroupTypeService groupTypeService = new GroupTypeService(); var groupTypeQry = groupTypeService.Queryable(); // limit GroupType selection to what Block Attributes allow List <int> groupTypeIds = AttributeValue("GroupTypes").SplitDelimitedValues().Select(a => int.Parse(a)).ToList(); if (groupTypeIds.Count > 0) { groupTypeQry = groupTypeQry.Where(a => groupTypeIds.Contains(a.Id)); } List <GroupType> groupTypes = groupTypeQry.OrderBy(a => a.Name).ToList(); ddlGroupType.DataSource = groupTypes; ddlGroupType.DataBind(); int currentGroupId = int.Parse(hfGroupId.Value); // TODO: Only include valid Parent choices (no circular references) GroupService groupService = new GroupService(); List <Group> groups = groupService.Queryable().Where(g => g.Id != currentGroupId).OrderBy(a => a.Name).ToList(); groups.Insert(0, new Group { Id = None.Id, Name = None.Text }); ddlParentGroup.DataSource = groups; ddlParentGroup.DataBind(); CampusService campusService = new CampusService(); List <Campus> campuses = campusService.Queryable().OrderBy(a => a.Name).ToList(); campuses.Insert(0, new Campus { Id = None.Id, Name = None.Text }); ddlCampus.DataSource = campuses; ddlCampus.DataBind(); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { Campus campus; CampusService campusService = new CampusService(); int campusId = int.Parse(hfCampusId.Value);; if (campusId == 0) { campus = new Campus(); campusService.Add(campus, CurrentPersonId); } else { campus = campusService.Get(campusId); } campus.Name = tbCampusName.Text; // check for duplicates if (campusService.Queryable().Count(a => a.Name.Equals(campus.Name, StringComparison.OrdinalIgnoreCase) && !a.Id.Equals(campus.Id)) > 0) { nbMessage.Text = WarningMessage.DuplicateFoundMessage("name", Campus.FriendlyTypeName); nbMessage.Visible = true; return; } if (!campus.IsValid) { // Controls will render the error messages return; } campusService.Save(campus, CurrentPersonId); BindGrid(); pnlDetails.Visible = false; pnlList.Visible = true; }
/// <summary> /// Gets the expression. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="serviceInstance">The service instance.</param> /// <param name="parameterExpression">The parameter expression.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection) { var settings = new FilterSettings(selection); if (!settings.IsValid) { return(null); } var dataContext = ( RockContext )serviceInstance.Context; int stepProgramId = 0; var stepProgram = GetStepProgram(dataContext, settings.StepProgramGuid); if (stepProgram != null) { stepProgramId = stepProgram.Id; } var stepService = new StepService(dataContext); // Filter by Step Program var stepQuery = stepService.Queryable().Where(x => x.StepType.StepProgramId == stepProgramId); // Filter by Step Types if (settings.StepTypeGuids.Count() > 0) { var stepTypeService = new StepTypeService(dataContext); var stepTypeIds = stepTypeService.Queryable() .Where(a => settings.StepTypeGuids.Contains(a.Guid)) .Select(a => a.Id).ToList(); stepQuery = stepQuery.Where(x => stepTypeIds.Contains(x.StepTypeId)); } // Filter by Step Status if (settings.StepStatusGuids.Count() > 0) { var stepStatusService = new StepStatusService(dataContext); var stepStatusIds = stepStatusService.Queryable() .Where(a => settings.StepStatusGuids.Contains(a.Guid)) .Select(a => a.Id).ToList(); stepQuery = stepQuery.Where(x => x.StepStatusId.HasValue && stepStatusIds.Contains(x.StepStatusId.Value)); } // Filter by Date Started if (settings.StartedInPeriod != null) { var startDateRange = settings.StartedInPeriod.GetDateRange(TimePeriodDateRangeBoundarySpecifier.Exclusive); if (startDateRange.Start != null) { stepQuery = stepQuery.Where(x => x.StartDateTime > startDateRange.Start.Value); } if (startDateRange.End != null) { stepQuery = stepQuery.Where(x => x.StartDateTime < startDateRange.End.Value); } } // Filter by Date Completed if (settings.CompletedInPeriod != null) { var completedDateRange = settings.CompletedInPeriod.GetDateRange(TimePeriodDateRangeBoundarySpecifier.Exclusive); if (completedDateRange.Start != null) { stepQuery = stepQuery.Where(x => x.CompletedDateTime > completedDateRange.Start.Value); } if (completedDateRange.End != null) { stepQuery = stepQuery.Where(x => x.CompletedDateTime < completedDateRange.End.Value); } } // Filter by Step Campus if (settings.StepCampusGuids.Count() > 0) { var campusService = new CampusService(dataContext); var stepCampusIds = campusService.Queryable() .Where(a => settings.StepCampusGuids.Contains(a.Guid)) .Select(a => a.Id).ToList(); stepQuery = stepQuery.Where(x => x.CampusId.HasValue && stepCampusIds.Contains(x.CampusId.Value)); } // Create Person Query. var personService = new PersonService(( RockContext )serviceInstance.Context); var qry = personService.Queryable() .Where(p => stepQuery.Any(x => x.PersonAlias.PersonId == p.Id)); var extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"); return(extractedFilterExpression); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { var campusLocationType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.LOCATION_TYPE_CAMPUS.AsGuid()); if (campusLocationType.Id != lpLocation.Location.LocationTypeValueId) { nbEditModeMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Danger; nbEditModeMessage.Text = "The selected named location is not a 'Campus' location type. Please update this before continuing."; return; } Campus campus; var rockContext = new RockContext(); var campusService = new CampusService(rockContext); var locationService = new LocationService(rockContext); int campusId = int.Parse(hfCampusId.Value); if (campusId == 0) { campus = new Campus(); campusService.Add(campus); var orders = campusService.Queryable() .Select(t => t.Order) .ToList(); campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0; } else { campus = campusService.Get(campusId); } campus.Name = tbCampusName.Text; campus.IsActive = cbIsActive.Checked; campus.Description = tbDescription.Text; campus.CampusStatusValueId = dvpCampusStatus.SelectedValueAsInt(); campus.CampusTypeValueId = dvpCampusType.SelectedValueAsInt(); campus.Url = tbUrl.Text; campus.PhoneNumber = tbPhoneNumber.Text; campus.LocationId = lpLocation.Location.Id; campus.ShortCode = tbCampusCode.Text; campus.TimeZoneId = ddlTimeZone.SelectedValue; var personService = new PersonService(rockContext); var leaderPerson = personService.Get(ppCampusLeader.SelectedValue ?? 0); campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null; campus.ServiceTimes = kvlServiceTimes.Value; avcAttributes.GetEditValues(campus); if (!campus.IsValid && campus.Location.IsValid) { // Controls will render the error messages return; } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); campus.SaveAttributeValues(rockContext); }); NavigateToParentPage(); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { if (!ValidateCampus()) { // Error messaging handled by ValidateCampus return; } if (!IsFormValid()) { return; } Campus campus; var rockContext = new RockContext(); var campusService = new CampusService(rockContext); var locationService = new LocationService(rockContext); int campusId = HiddenCampusId; if (campusId == 0) { campus = new Campus(); campusService.Add(campus); var orders = campusService.Queryable() .AsNoTracking() .Select(t => t.Order) .ToList(); campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0; } else { campus = campusService.Get(campusId); } campus.Name = tbCampusName.Text; campus.IsActive = cbIsActive.Checked; campus.Description = tbDescription.Text; campus.CampusStatusValueId = dvpCampusStatus.SelectedValueAsInt(); campus.CampusTypeValueId = dvpCampusType.SelectedValueAsInt(); campus.Url = urlCampus.Text; campus.PhoneNumber = pnbPhoneNumber.Number; campus.LocationId = lpLocation.Location.Id; campus.ShortCode = tbCampusCode.Text; campus.TimeZoneId = ddlTimeZone.SelectedValue; var personService = new PersonService(rockContext); var leaderPerson = personService.GetNoTracking(ppCampusLeader.SelectedValue ?? 0); campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null; campus.ServiceTimes = kvlServiceTimes.Value; avcAttributes.GetEditValues(campus); if (!campus.IsValid && campus.Location.IsValid) { // Controls will render the error messages return; } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); campus.SaveAttributeValues(rockContext); }); NavigateToCurrentPage(new Dictionary <string, string> { { "CampusId", campus.Id.ToString() } }); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { Campus campus; var rockContext = new RockContext(); var campusService = new CampusService(rockContext); var locationService = new LocationService(rockContext); var locationCampusValue = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.LOCATION_TYPE_CAMPUS.AsGuid()); int campusId = int.Parse(hfCampusId.Value); if (campusId == 0) { campus = new Campus(); campusService.Add(campus); var orders = campusService.Queryable() .Select(t => t.Order) .ToList(); campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0; } else { campus = campusService.Get(campusId); } campus.Name = tbCampusName.Text; campus.IsActive = cbIsActive.Checked; campus.Description = tbDescription.Text; campus.Url = tbUrl.Text; campus.PhoneNumber = tbPhoneNumber.Text; if (campus.Location == null) { var location = locationService.Queryable() .Where(l => l.Name.Equals(campus.Name, StringComparison.OrdinalIgnoreCase) && l.LocationTypeValueId == locationCampusValue.Id) .FirstOrDefault(); if (location == null) { location = new Location(); locationService.Add(location); } campus.Location = location; } campus.Location.Name = campus.Name; campus.Location.LocationTypeValueId = locationCampusValue.Id; string preValue = campus.Location.GetFullStreetAddress(); acAddress.GetValues(campus.Location); string postValue = campus.Location.GetFullStreetAddress(); campus.ShortCode = tbCampusCode.Text; campus.TimeZoneId = ddlTimeZone.SelectedValue; var personService = new PersonService(rockContext); var leaderPerson = personService.Get(ppCampusLeader.SelectedValue ?? 0); campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null; campus.ServiceTimes = kvlServiceTimes.Value; campus.LoadAttributes(rockContext); Rock.Attribute.Helper.GetEditValues(phAttributes, campus); if (!campus.IsValid && campus.Location.IsValid) { // Controls will render the error messages return; } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); campus.SaveAttributeValues(rockContext); if (preValue != postValue && !string.IsNullOrWhiteSpace(campus.Location.Street1)) { locationService.Verify(campus.Location, true); } }); Rock.Web.Cache.CampusCache.Flush(campus.Id); NavigateToParentPage(); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { if (!ValidateCampus()) { // Error messaging handled by ValidateCampus return; } if (!IsFormValid()) { return; } Campus campus; var rockContext = new RockContext(); var campusService = new CampusService(rockContext); var locationService = new LocationService(rockContext); int campusId = HiddenCampusId; if (campusId == 0) { campus = new Campus(); campusService.Add(campus); var orders = campusService.Queryable() .AsNoTracking() .Select(t => t.Order) .ToList(); campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0; } else { campus = campusService.Get(campusId); } campus.Name = tbCampusName.Text; campus.IsActive = cbIsActive.Checked; campus.Description = tbDescription.Text; campus.CampusStatusValueId = dvpCampusStatus.SelectedValueAsInt(); campus.CampusTypeValueId = dvpCampusType.SelectedValueAsInt(); campus.Url = urlCampus.Text; campus.PhoneNumber = pnbPhoneNumber.Number; campus.LocationId = lpLocation.Location.Id; campus.ShortCode = tbCampusCode.Text; campus.TimeZoneId = ddlTimeZone.SelectedValue; var personService = new PersonService(rockContext); var leaderPerson = personService.GetNoTracking(ppCampusLeader.SelectedValue ?? 0); campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null; campus.ServiceTimes = kvlServiceTimes.Value; // Remove any CampusSchedules that were removed in the UI var selectedSchedules = CampusSchedulesState.Select(s => s.Guid); var locationsToRemove = campus.CampusSchedules.Where(s => !selectedSchedules.Contains(s.Guid)).ToList(); CampusScheduleService campusScheduleService = null; foreach (var campusSchedule in locationsToRemove) { campusScheduleService = campusScheduleService ?? new CampusScheduleService(rockContext); campus.CampusSchedules.Remove(campusSchedule); campusScheduleService.Delete(campusSchedule); } // Add/Update any CampusSchedules that were added or changed in the UI. foreach (var campusScheduleState in CampusSchedulesState) { var campusSchedule = campus.CampusSchedules.Where(s => s.Guid == campusScheduleState.Guid).FirstOrDefault(); if (campusSchedule == null) { campusSchedule = new CampusSchedule() { CampusId = campus.Id, ScheduleId = campusScheduleState.ScheduleId, ScheduleTypeValueId = campusScheduleState.ScheduleTypeId, Order = campusScheduleState.Order, Guid = Guid.NewGuid() }; campus.CampusSchedules.Add(campusSchedule); } else { campusSchedule.ScheduleId = campusScheduleState.ScheduleId; campusSchedule.ScheduleTypeValueId = campusScheduleState.ScheduleTypeId; } } SaveCampusTopics(campus, rockContext); avcAttributes.GetEditValues(campus); if (!campus.IsValid && campus.Location.IsValid) { // Controls will render the error messages return; } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); campus.SaveAttributeValues(rockContext); }); NavigateToCurrentPage(new Dictionary <string, string> { { "CampusId", campus.Id.ToString() } }); }