// GET: Manager/Collections/Edit/5 public ActionResult Edit(int?id, int?entityTypeId) { CFCollection model; if (id.HasValue && id.Value > 0) { model = CollectionService.GetCollection(id.Value); if (model == null) { return(HttpNotFound("Collection was not found")); } } else { if (entityTypeId.HasValue) { model = CollectionService.CreateCollection(entityTypeId.Value); } else { List <CFEntityType> entityTypes = EntityTypeService.GetEntityTypes(CFEntityType.eTarget.Collections).ToList(); ViewBag.SelectEntityViewModel = new SelectEntityTypeViewModel() { EntityTypes = entityTypes }; model = new CFCollection(); } } return(View(model)); }
/// <summary> /// Shows the edit. /// </summary> /// <param name="entityTypeId">The entity type id.</param> protected void ShowEdit(int entityTypeId) { EntityTypeService entityTypeService = new EntityTypeService(new RockContext()); EntityType entityType = entityTypeService.Get(entityTypeId); if (entityType != null) { mdEdit.Title = ActionTitle.Edit(EntityType.FriendlyTypeName); hfEntityTypeId.Value = entityType.Id.ToString(); tbName.Text = entityType.Name; tbName.Enabled = false; // !entityType.IsEntity; tbFriendlyName.Text = entityType.FriendlyName; cbCommon.Checked = entityType.IsCommon; ceIndexResultsTemplate.Text = entityType.IndexResultTemplate; ceIndexDocumentUrl.Text = entityType.IndexDocumentUrl; ceLinkUrl.Text = entityType.LinkUrlLavaTemplate; } else { mdEdit.Title = ActionTitle.Add(EntityType.FriendlyTypeName); hfEntityTypeId.Value = 0.ToString(); tbName.Text = string.Empty; tbName.Enabled = true; tbFriendlyName.Text = string.Empty; cbCommon.Checked = false; ceIndexResultsTemplate.Text = string.Empty; ceIndexDocumentUrl.Text = string.Empty; ceLinkUrl.Text = string.Empty; } ShowDialog("Edit"); }
/// <summary> /// Handles the SaveClick event of the MdEditEntityType control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> /// <exception cref="System.NotImplementedException"></exception> private void MdEditEntityType_SaveClick(object sender, EventArgs e) { using (RockContext rockContext = new RockContext()) { EntityTypeService entityTypeService = new EntityTypeService(rockContext); var entityType = entityTypeService.Get(hfIdValue.ValueAsInt()); entityType.IsIndexingEnabled = cbEnabledIndexing.Checked; rockContext.SaveChanges(); if (cbEnabledIndexing.Checked) { IndexContainer.CreateIndex(entityType.IndexModelType); // call for bulk indexing BulkIndexEntityTypeTransaction bulkIndexTransaction = new BulkIndexEntityTypeTransaction(); bulkIndexTransaction.EntityTypeId = entityType.Id; RockQueue.TransactionQueue.Enqueue(bulkIndexTransaction); } else { IndexContainer.DeleteIndex(entityType.IndexModelType); } } mdEditEntityType.Hide(); LoadEntities(); }
/// <summary> /// Sets the edit value from IEntity.Id value /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="id">The identifier.</param> public void SetEditValueFromEntityId(Control control, Dictionary <string, ConfigurationValue> configurationValues, int?id) { var item = new EntityTypeService(new RockContext()).Get(id ?? 0); string guidValue = item != null?item.Guid.ToString() : string.Empty; SetEditValue(control, configurationValues, guidValue); }
/// <summary> /// Handles the SaveClick event of the mdEdit 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 mdEdit_SaveClick(object sender, EventArgs e) { var rockContext = new RockContext(); EntityTypeService entityTypeService = new EntityTypeService(rockContext); EntityType entityType = entityTypeService.Get(int.Parse(hfEntityTypeId.Value)); if (entityType == null) { entityType = new EntityType(); entityType.IsEntity = true; entityType.IsSecured = true; entityTypeService.Add(entityType); } entityType.Name = tbName.Text; entityType.FriendlyName = tbFriendlyName.Text; entityType.IsCommon = cbCommon.Checked; entityType.IndexResultTemplate = ceIndexResultsTemplate.Text; entityType.IndexDocumentUrl = ceIndexDocumentUrl.Text; entityType.LinkUrlLavaTemplate = ceLinkUrl.Text; rockContext.SaveChanges(); EntityTypeCache.Flush(entityType.Id); hfEntityTypeId.Value = string.Empty; HideDialog(); BindGrid(); }
// GET: Manager/Items public ActionResult Index(int offset = 0, int limit = int.MaxValue, int?typeId = null) { SecurityService.CreateAccessContext(); if (limit == int.MaxValue) { limit = ConfigHelper.PageSize; } var itemQuery = ItemService.GetItems(); if (typeId != null) { itemQuery = itemQuery.Where(i => i.EntityTypeId == typeId.Value); } var entities = itemQuery.OrderBy(e => e.Id).Skip(offset).Take(limit).Include(e => (e as CFEntity).EntityType).Select(e => e as CFEntity); var total = itemQuery.Count(); ViewBag.TotalItems = total; ViewBag.Limit = limit; ViewBag.Offset = offset; ViewBag.SelectedType = typeId; var _eTypes = new SelectList(EntityTypeService.GetEntityTypes(CFEntityType.eTarget.Items).OrderBy(e => e.Name), "Id", "Name"); ViewBag.EntityTypes = JsonConvert.SerializeObject(_eTypes.ToList()); // ViewBag.EntityTypes = new SelectList(EntityTypeService.GetEntityTypes(CFEntityType.eTarget.Items), "Id", "Name", typeId); if (entities != null) { return(View(entities)); } return(View()); }
/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns(DataView dataView) { var entityTypeService = new EntityTypeService(); ddlTransform.Items.Clear(); if (dataView.EntityTypeId.HasValue) { var filteredEntityType = EntityTypeCache.Read(dataView.EntityTypeId.Value); foreach (var component in DataTransformContainer.GetComponentsByTransformedEntityName(filteredEntityType.Name).OrderBy(c => c.Title)) { var transformEntityType = EntityTypeCache.Read(component.TypeName); ListItem li = new ListItem(component.Title, transformEntityType.Id.ToString()); ddlTransform.Items.Add(li); } } ddlTransform.Items.Insert(0, new ListItem(string.Empty, string.Empty)); // Get all entities ddlEntityType.DataSource = entityTypeService.GetEntities() .OrderBy(e => e.FriendlyName) .ToList(); ddlEntityType.DataBind(); ddlEntityType.Items.Insert(0, new ListItem(string.Empty, string.Empty)); }
/// <summary> /// Reads the specified name. /// </summary> /// <param name="name">The name.</param> /// <param name="createNew">if set to <c>true</c> [create new].</param> /// <returns></returns> public static EntityTypeCache Read(string name, bool createNew) { int?entityTypeId = null; lock ( obj ) { if (entityTypes.ContainsKey(name)) { entityTypeId = entityTypes[name]; } } if (entityTypeId.HasValue) { return(Read(entityTypeId.Value)); } var entityTypeService = new EntityTypeService(); var entityTypeModel = entityTypeService.Get(name, createNew, null); if (entityTypeModel != null) { return(Read(entityTypeModel)); } else { return(null); } }
/// <summary> /// Returns EntityType object from cache. If entityBlockType does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static EntityTypeCache Read(int id) { string cacheKey = EntityTypeCache.CacheKey(id); ObjectCache cache = MemoryCache.Default; EntityTypeCache entityType = cache[cacheKey] as EntityTypeCache; if (entityType != null) { return(entityType); } else { var entityTypeService = new EntityTypeService(); var entityTypeModel = entityTypeService.Get(id); if (entityTypeModel != null) { entityType = new EntityTypeCache(entityTypeModel); var cachePolicy = new CacheItemPolicy(); cache.Set(cacheKey, entityType, cachePolicy); cache.Set(entityType.Guid.ToString(), entityType.Id, cachePolicy); return(entityType); } else { return(null); } } }
/// <summary> /// Handles the SelectedIndexChanged event of the etpEntity 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 etpEntity_SelectedIndexChanged(object sender, EventArgs e) { if (!etpEntity.SelectedEntityTypeId.HasValue) { cblDisplay.Visible = false; cblFilter.Visible = false; return; } var entityType = new EntityTypeService(new RockContext()).Get(etpEntity.SelectedEntityTypeId.Value); var type = Type.GetType(entityType.AssemblyName); var properties = GetTypeProperties(type) .Select(p => p.Name) .ToList(); cblDisplay.Items.Clear(); cblFilter.Items.Clear(); foreach (var property in properties) { cblDisplay.Items.Add(property); cblFilter.Items.Add(property); } cblDisplay.Visible = true; cblFilter.Visible = true; }
/// <summary> /// Reads the specified name. /// </summary> /// <param name="name">The name.</param> /// <param name="createNew">if set to <c>true</c> [create new].</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> public static EntityTypeCache Read(string name, bool createNew, RockContext rockContext = null) { int entityTypeId = 0; if (_entityTypes.TryGetValue(name, out entityTypeId)) { return(Read(entityTypeId)); } if (rockContext != null) { var entityTypeModel = new EntityTypeService(rockContext).Get(name, createNew); if (entityTypeModel != null) { return(Read(entityTypeModel)); } } else { using (var myRockContext = new RockContext()) { var entityTypeModel = new EntityTypeService(myRockContext).Get(name, createNew); if (entityTypeModel != null) { return(Read(entityTypeModel)); } } } return(null); }
/// <summary> /// Gets the expression. /// </summary> /// <param name="context">The context.</param> /// <param name="entityIdProperty">The entity identifier property.</param> /// <param name="selection">The selection.</param> /// <returns></returns> public override System.Linq.Expressions.Expression GetExpression(Rock.Data.RockContext context, System.Linq.Expressions.MemberExpression entityIdProperty, string selection) { var attributeValueService = new AttributeValueService(context); var roomReservationGroupAttGuid = ZoomGuid.Attribute.ROOM_RESERVATION_GROUP_ATTRIBUTE.AsGuid(); var reservationLocationEntityTypeId = new EntityTypeService(context).GetNoTracking(com.bemaservices.RoomManagement.SystemGuid.EntityType.RESERVATION_LOCATION.AsGuid()).Id; var resGroupAttValues = attributeValueService.Queryable() .Where(x => x.Attribute.Guid == roomReservationGroupAttGuid) .Select(x => new { EntityId = x.EntityId, Value = x.Value }); var groupQuery = new GroupService(context).Queryable() .Select(g => new { GuidString = g.Guid.ToString(), GroupName = g.Name + " (" + g.Id.ToString() + ")" }); var reservationQuery = new ReservationService(context).Queryable() .Select(r => new { r.Id }); var reservationlocationQuery = new ReservationLocationService(context).Queryable() .Select(rl => new { rl.Id, rl.ReservationId }); var occurrenceService = new RoomOccurrenceService(context); var resultQuery = occurrenceService.Queryable("ReservationLocation") .Select(ro => groupQuery.FirstOrDefault(g => resGroupAttValues.FirstOrDefault(v => reservationQuery.FirstOrDefault(r => reservationlocationQuery.FirstOrDefault(rl => ro.EntityTypeId == reservationLocationEntityTypeId && rl.Id == ro.EntityId).ReservationId == r.Id).Id == v.EntityId).Value.Contains(g.GuidString)).GroupName); return(SelectExpressionExtractor.Extract(resultQuery, entityIdProperty, "ro")); }
/// <summary> /// Used to manually flush the attribute cache. /// </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 btnClearCache_Click(object sender, EventArgs e) { var msgs = new List <string>(); // Clear the static object that contains all auth rules (so that it will be refreshed) Rock.Security.Authorization.Flush(); msgs.Add("Authorizations have been cleared"); // Flush the static entity attributes cache Rock.Web.Cache.AttributeCache.FlushEntityAttributes(); msgs.Add("EntityAttributes have been cleared"); // Clear all cached items Rock.Web.Cache.RockMemoryCache.Clear(); msgs.Add("RockMemoryCache has been cleared"); // Flush Site Domains Rock.Web.Cache.SiteCache.Flush(); // Flush today's Check-in Codes Rock.Model.AttendanceCodeService.FlushTodaysCodes(); string webAppPath = Server.MapPath("~"); // Check for any unregistered entity types, field types, and block types EntityTypeService.RegisterEntityTypes(webAppPath); FieldTypeService.RegisterFieldTypes(webAppPath); BlockTypeService.RegisterBlockTypes(webAppPath, Page, false); msgs.Add("EntityTypes, FieldTypes, BlockTypes have been re-registered"); // Clear workflow trigger cache Rock.Workflow.TriggerCache.Refresh(); // Delete all cached files try { var dirInfo = new DirectoryInfo(Path.Combine(webAppPath, "App_Data/Cache")); foreach (var childDir in dirInfo.GetDirectories()) { childDir.Delete(true); } foreach (var file in dirInfo.GetFiles().Where(f => f.Name != ".gitignore")) { file.Delete(); } msgs.Add("Cached files have been deleted"); } catch (Exception ex) { nbMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning; nbMessage.Visible = true; nbMessage.Text = "The following error occurred when attempting to delete cached files: " + ex.Message; return; } nbMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Success; nbMessage.Visible = true; nbMessage.Title = "Clear Cache"; nbMessage.Text = string.Format("<p>{0}</p>", msgs.AsDelimited("<br />")); }
/// <summary> /// Gets the query. /// </summary> /// <returns></returns> private IQueryable <EntityType> GetQuery() { var entityTypeService = new EntityTypeService(new RockContext()); var entityTypes = entityTypeService.Queryable().AsNoTracking(); // Filter by Name string nameFilter = gfSettings.GetUserPreference("Name"); if (!string.IsNullOrEmpty(nameFilter.Trim())) { entityTypes = entityTypes.Where(a => a.Name.Contains(nameFilter.Trim())); } // Filter by Is Entity bool?isEntityFilter = gfSettings.GetUserPreference("IsEntity").AsBooleanOrNull(); if (isEntityFilter.HasValue) { entityTypes = entityTypes.Where(a => a.IsEntity == isEntityFilter.Value); } // Filter by Is Entity bool?isSecuredFilter = gfSettings.GetUserPreference("IsEntity").AsBooleanOrNull(); if (isSecuredFilter.HasValue) { entityTypes = entityTypes.Where(a => a.IsEntity == isSecuredFilter.Value); } return(entityTypes); }
/// <summary> /// Handles the RowDataBound event of the gList control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param> protected void gList_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) { var noteWatch = e.Row.DataItem as NoteWatch; if (noteWatch == null) { return; } var lWatchingEntityType = e.Row.FindControl("lWatchingEntityType") as Literal; if (lWatchingEntityType != null) { if (noteWatch.EntityTypeId.HasValue) { var entityType = EntityTypeCache.Get(noteWatch.EntityTypeId.Value); if (entityType != null) { lWatchingEntityType.Text = entityType.FriendlyName; if (noteWatch.EntityId.HasValue && noteWatch.EntityTypeId.HasValue) { using (var rockContext = new RockContext()) { IEntity entity = new EntityTypeService(new RockContext()).GetEntity(noteWatch.EntityTypeId.Value, noteWatch.EntityId.Value); if (entity != null) { lWatchingEntityType.Text = entityType.FriendlyName + " (" + entity.ToString() + ")"; } } } } } } }
/// <summary> /// Reads the specified GUID. /// </summary> /// <param name="guid">The GUID.</param> /// <returns></returns> public static EntityTypeCache Read(Guid guid) { ObjectCache cache = MemoryCache.Default; object cacheObj = cache[guid.ToString()]; if (cacheObj != null) { return(Read((int)cacheObj)); } else { var entityTypeService = new EntityTypeService(); var entityTypeModel = entityTypeService.Get(guid); if (entityTypeModel != null) { var entityType = new EntityTypeCache(entityTypeModel); var cachePolicy = new CacheItemPolicy(); cache.Set(EntityTypeCache.CacheKey(entityType.Id), entityType, cachePolicy); cache.Set(entityType.Guid.ToString(), entityType.Id, cachePolicy); return(entityType); } else { return(null); } } }
/// <summary> /// Handles the SaveClick event of the mdEdit 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 mdEdit_SaveClick(object sender, EventArgs e) { var rockContext = new RockContext(); EntityTypeService entityTypeService = new EntityTypeService(rockContext); EntityType entityType = entityTypeService.Get(int.Parse(hfEntityTypeId.Value)); if (entityType == null) { entityType = new EntityType(); entityType.IsEntity = true; entityType.IsSecured = true; entityTypeService.Add(entityType); } entityType.Name = tbName.Text; entityType.FriendlyName = tbFriendlyName.Text; entityType.IsCommon = cbCommon.Checked; rockContext.SaveChanges(); hfEntityTypeId.Value = string.Empty; HideDialog(); BindGrid(); }
/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns() { var entityTypeService = new EntityTypeService(); entityTypeService.RegisterEntityTypes(Server.MapPath("~")); List <EntityType> entityTypes = entityTypeService.GetEntities().OrderBy(w => w.FriendlyName).ToList(); ddlEntityType.DataValueField = "Id"; ddlEntityType.DataTextField = "FriendlyName"; ddlEntityType.DataSource = entityTypes; ddlEntityType.DataBind(); ddlWorkflowType.Items.Clear(); ddlWorkflowType.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var workflowType in new WorkflowTypeService().Queryable().OrderBy(w => w.Name)) { if (workflowType.IsAuthorized("View", CurrentPerson)) { ddlWorkflowType.Items.Add(new ListItem(workflowType.Name, workflowType.Id.ToString())); } } rblTriggerType.Items.Clear(); Type type = typeof(WorkflowTriggerType); foreach (var value in Enum.GetValues(type)) { rblTriggerType.Items.Add(new ListItem(Enum.GetName(type, value).SplitCase().Replace(" ", "-"), Convert.ToInt32(value).ToString())); } }
/// <summary> /// Shows the edit. /// </summary> /// <param name="entityTypeId">The entity type id.</param> protected void ShowEdit(int entityTypeId) { pnlList.Visible = false; pnlDetails.Visible = true; EntityTypeService entityTypeService = new EntityTypeService(); EntityType entityType = entityTypeService.Get(entityTypeId); if (entityType != null) { lActionTitle.Text = ActionTitle.Edit(EntityType.FriendlyTypeName); hfEntityTypeId.Value = entityType.Id.ToString(); tbName.Text = entityType.Name; tbFriendlyName.Text = entityType.FriendlyName; cbCommon.Checked = entityType.IsCommon; } else { lActionTitle.Text = ActionTitle.Add(EntityType.FriendlyTypeName); hfEntityTypeId.Value = 0.ToString(); tbName.Text = string.Empty; tbFriendlyName.Text = string.Empty; cbCommon.Checked = false; } tbName.Enabled = !entityType.IsEntity; }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); // Load Entity Type Filter var entityTypes = new EntityTypeService(new RockContext()).GetEntities().OrderBy(t => t.FriendlyName).ToList(); entityTypeFilter.EntityTypes = entityTypes; entityTypePicker.EntityTypes = entityTypes; _canConfigure = IsUserAuthorized(Authorization.ADMINISTRATE); BindFilter(); rFilter.ApplyFilterClick += rFilter_ApplyFilterClick; if (_canConfigure) { rGrid.DataKeyNames = new string[] { "id" }; rGrid.Actions.ShowAdd = true; rGrid.Actions.AddClick += rGrid_Add; rGrid.GridReorder += rGrid_GridReorder; rGrid.GridRebind += rGrid_GridRebind; rGrid.RowDataBound += rGrid_RowDataBound; modalDetails.SaveClick += modalDetails_SaveClick; modalDetails.OnCancelScript = string.Format("$('#{0}').val('');", hfIdValue.ClientID); } else { nbMessage.Text = "You are not authorized to configure this page"; nbMessage.Visible = true; } }
/// <summary> /// Gets the edit value as the IEntity.Id /// </summary> /// <param name="control">The control.</param> /// <param name="configurationValues">The configuration values.</param> /// <returns></returns> public int?GetEditValueAsEntityId(Control control, Dictionary <string, ConfigurationValue> configurationValues) { Guid guid = GetEditValue(control, configurationValues).AsGuid(); var item = new EntityTypeService(new RockContext()).Get(guid); return(item != null ? item.Id : (int?)null); }
public JsonResult GetPageItems(string q, string entityTypeFilter, int sortAttributeMappingId, bool sortAsc, int page, int itemPerPage, [Bind(Include = "mapIds[]")] int[] mapIds, bool includeImage = false, string lang = null) { int total; SecurityService.CreateAccessContext(); var items = ItemService.GetPagedItems(q, entityTypeFilter, sortAttributeMappingId, sortAsc, page, itemPerPage, out total); List <string> mappings = new List <string>(mapIds.Length); foreach (int id in mapIds) { CFEntityTypeAttributeMapping am = EntityTypeService.GetEntityTypeAttributeMappingById(id); mappings.Add(am.Name); } IEnumerable <Tuple <int, List <string> > > result = ConvertPagedItems(items, mappings, mapIds, includeImage, lang); return(Json(new { total = total, result = result }, JsonRequestBehavior.AllowGet)); }
/// <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) { nbWarning.Visible = false; if (IsUserAuthorized(Authorization.ADMINISTRATE)) { if (!Page.IsPostBack) { EntityTypeService.RegisterEntityTypes(Request.MapPath("~")); BindFilter(); BindGrid(); } else { ShowDialog(); } } else { gEntityTypes.Visible = false; nbWarning.Text = WarningMessage.NotAuthorizedToEdit(EntityType.FriendlyTypeName); nbWarning.Visible = true; } base.OnLoad(e); }
/// <summary> /// Get the entity that we are going to be querying authorization records for. /// </summary> /// <returns>ISecured entity or null if not found.</returns> ISecured GetEntity() { var entityId = tbEntityId.Text.AsInteger(); var entityGuid = tbEntityId.Text.AsGuid(); var entityType = new EntityTypeService(new RockContext()).Get(pEntityType.SelectedEntityTypeId.Value); IEntity entity = null; // // Find the entity they are searching for or display an error if we couldn't parse the Id. // if (entityId != 0) { entity = GetById(entityType.Name, entityId); } else if (entityGuid != Guid.Empty) { entity = GetByGuid(entityType.Name, entityGuid); } if (entity == null || (entity as ISecured) == null) { return(null); } return(( ISecured )entity); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { EntityTypeService entityTypeService = new EntityTypeService(new RockContext()); SortProperty sortProperty = gEntityTypes.SortProperty; var qry = entityTypeService.Queryable().Where(e => e.IsSecured || e.IsEntity); string search = gfSettings.GetUserPreference("Search"); if (!string.IsNullOrWhiteSpace(search)) { qry = qry.Where(h => h.Name.Contains(search) || h.FriendlyName.Contains(search)); } if (sortProperty != null) { qry = qry.Sort(sortProperty); } else { qry = qry.OrderBy(p => p.Name); } gEntityTypes.DataSource = qry.ToList(); gEntityTypes.DataBind(); }
/// <summary> /// Binds the dropdown menus /// </summary> private void BindData() { using (var rockContext = new RockContext()) { RegistrationInstanceService registrationInstanceService = new RegistrationInstanceService(rockContext); var registrationInstances = registrationInstanceService.Queryable().Where(ri => ri.IsActive == true).AsNoTracking().ToList(); ddlRegistrationInstances.DataSource = registrationInstances; RegistrationInstance emptyRegistrationInstance = new RegistrationInstance { Id = -1, Name = "" }; registrationInstances.Insert(0, emptyRegistrationInstance); ddlRegistrationInstances.DataBind(); var entityTypes = new EntityTypeService(new RockContext()).GetEntities() .Where(t => t.Guid.ToString() == Rock.SystemGuid.EntityType.GROUP.ToLower() || t.Guid.ToString() == "5cd9c0c8-c047-61a0-4e36-0fdb8496f066" || t.Guid.ToString() == Rock.SystemGuid.EntityType.DATAVIEW.ToLower()) .OrderBy(t => t.FriendlyName) .ToList(); entityTypes.Insert(0, new EntityType() { Id = -1, FriendlyName = "Select One" }); ddlEntityType.DataSource = entityTypes; ddlEntityType.DataBind(); } }
public override void InitManager(object model) { securityService.CreateAccessContext(); // get db context new Services.SecurityService(db).CreateAccessContext(); CollectionService collectionSrv = new CollectionService(db); EntityTypeService entityTypeSrv = new EntityTypeService(db); SubmissionService formService = new SubmissionService(db); securityService.CreateAccessContext(); Form form = db.FormTemplates.Where(f => f.Id == FormId).FirstOrDefault(); List <SelectListItem> listFormFields = new List <SelectListItem>(); if (form != null) { GetFormField(form.Fields, "", ref listFormFields); mFormFields = new SelectList(listFormFields, "Value", "Text"); } if (EntityTypeId > 0) { mAttributeFields = new SelectList(entityTypeService.GetEntityTypeById(EntityTypeId).AttributeMappings, "Name", "Name"); } base.InitManager(model); }
/// <summary> /// Binds the filter. /// </summary> private void BindFilter() { // Exclude the categories for block and service job attributes, since they are controlled through code attribute decorations var exclusions = new List <Guid>(); exclusions.Add(Rock.SystemGuid.EntityType.BLOCK.AsGuid()); exclusions.Add(Rock.SystemGuid.EntityType.SERVICE_JOB.AsGuid()); var rockContext = new RockContext(); var entityTypes = new EntityTypeService(rockContext).GetEntities() .Where(t => !exclusions.Contains(t.Guid)) .OrderBy(t => t.FriendlyName) .ToList(); entityTypePicker.EntityTypes = entityTypes; // Load Entity Type Filter var attributeEntityTypeId = EntityTypeCache.Read(typeof(Rock.Model.Attribute)).Id; var categoryEntities = new CategoryService(rockContext).Queryable() .Where(c => c.EntityTypeId == attributeEntityTypeId && c.EntityTypeQualifierColumn == "EntityTypeId" && c.EntityTypeQualifierValue != null) .Select(c => c.EntityTypeQualifierValue) .ToList() .Select(c => c.AsInteger()); entityTypeFilter.EntityTypes = entityTypes.Where(e => categoryEntities.Contains(e.Id)).ToList(); entityTypeFilter.SetValue(rFilter.GetUserPreference("EntityType")); }
protected void btnDelete_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(hfConfirmDelete.Value)) { hfConfirmDelete.Value = "DELETE"; btnDelete.CssClass = "btn btn-block btn-danger"; btnDelete.Text = "Confirm Delete"; } else { RockContext rockContext = new RockContext(); int pinEntityId = EntityTypeCache.Get("Rock.Security.Authentication.PINAuthentication").Id; var userLoginEntity = new EntityTypeService(rockContext).Get(pinEntityId); var userAuthorized = userLoginEntity.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson); if (!userAuthorized) { mdEditPin.Hide(); return; } int pinId = hfPinID.ValueAsInt(); UserLoginService userLoginService = new UserLoginService(rockContext); UserLogin pin = userLoginService.Get(pinId); userLoginService.Delete(pin); rockContext.SaveChanges(); mdEditPin.Hide(); DisplayPINs(); } }
/// <summary> /// Gets the entity name /// </summary> /// <param name="entityTypeId">The Id of the Entity Type.</param> /// <param name="entityId">The Id of the Entity.</param> private string GetEntityName(int?entityTypeId, int?entityId, RockContext rockContext) { var retVal = string.Empty; if (entityTypeId.HasValue && entityId.HasValue) { var service = new EntityTypeService(rockContext); var entity = service.GetEntity(( int )entityTypeId, ( int )entityId); if (entity is Group) { retVal = (( Group )entity).Name; } else if (entity is GroupMember) { retVal = (( GroupMember )entity).Person.FullName; } else if (entity is DefinedValue) { retVal = (( DefinedValue )entity).Value; } else if (entity is RegistrationRegistrant) { retVal = (( RegistrationRegistrant )entity).Person.FullName; } } return(retVal); }