I am trying to create a white list part for the site's settings that will allow an admin user to enter a list of urls that are considered "white listed". I'm having a problem with storing this information in the database though. When creating a new content type with information that belongs in the database you can use the following:
public class ShareBarSettingsPart : ContentPart<ShareBarSettingsPartRecord> {
public string AddThisAccount {
get { return Record.AddThisAccount; }
set { Record.AddThisAccount = value; }
}
}
to set the value of AddThisAccount in the database. My problem is I need a list of urls in the database and not just a single item. I tried the following but it gives me an error:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
namespace Speedbump.Models
{
public class SpeedBumpSettingsRecord : ContentPartRecord
{
public virtual List<string> whiteList { get; set; }
}
public class SpeedBumpSettingsPart : ContentPart<SpeedBumpSettingsRecord>
{
public List<string> whiteList
{
get { return Record.whiteList; }
set { Record.whiteList.Add(value); } //I need to be able to add a single record to the list here
}
}
}
Any help would be greatly appreciated, thank you.
List<string> is not supported as a record property type. It doesn't matter however as you should never use a record for a site setting part. Use Store and Retrieve instead. Any existing settings part will give you an example.
Related
I use:
- MS SQL Server 2014 database;
- Entity Framework.
I am using GridControl with an "empty row" element.
The user is trying to add a new entry in the GridControl.
After adding a new record does not update the field, which is formed by the database.
In my case, this field is "ID".
It can also be other fields that the database forms.
The "ID" field is updated only after the new record is being edited.
Question.
How to make the field that is filled with the database updated in the GridControl after adding a new entry in the GridControl?
namespace Rsh.frm.frm3.Core.ModelEFFrm_3
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class PrbEntitiesF3 : DbContext
{
public PrbEntitiesF3()
: base("name=PrbEntitiesF3")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<tbl_930_3_2_Test> tbl_930_3_2_Test { get; set; }
}
}
namespace Rsh.frm.frm3.Core.ModelEFFrm_3
{
using System;
using System.Collections.Generic;
public partial class tbl_930_3_2_Test
{
public int Id { get; set; }
public string Text { get; set; }
}
}
public partial class Frm3UC : UserControl
{
PrbEntitiesF3 entiF3;
public Frm3UC()
{
InitializeComponent();
entiF3 = new PrbEntitiesF3();
}
public void FillGrid3()
{
entiF3.tbl_930_3_2_Test.Load();
bs3.DataSource = entiF3.tbl_930_3_2_Test.Local.ToBindingList();
gridControl3.DataSource = bs3;
}
public void Save()
{
entiF3.SaveChanges();
}
}
Update_1
I want to make the logic work:
1. User filled the field.
User. Clicked "Enter".
The code (or standard tools "devexpress") adds a new entry to the Grid.
The code (or standard tools "devexpress") saves an entry to the database.
The code (or standard tools "devexpress") fills in the fields that the database creates.
In my case, this is the "ID" field.
I want to say that the value of the "ID" field is created in the database.
This value needs to be displayed in the Grid for the new record that the user added.
The solution is to handle the GridView_FocusedRowChanged event.
Please see the following screencast:
https://screencast-o-matic.com/watch/cqnZFt0Qeb
I am using dapper extensions and have a question about the class mapper. Unfortunately most of my tables need some mapping done to them such as different schemas etc.
So I find I am typically doing a lot of swapping out the DefaultMapper as per below:
public Hierarchies HierarchyGetByName(string aName)
{
Hierarchies result;
using (SqlConnection cn = GetSqlConnection())
{
cn.Open();
Type currModelMapper = DapperExtensions.DapperExtensions.DefaultMapper;
try
{
DapperExtensions.DapperExtensions.DefaultMapper = typeof(HierarchiesMapper);
IFieldPredicate predicate = Predicates.Field<Hierarchies>(f => f.Name, Operator.Eq, aName);
result = cn.GetList<Hierarchies>(predicate).FirstOrDefault();
}
finally
{
DapperExtensions.DapperExtensions.DefaultMapper = currModelMapper;
}
cn.Close();
}
return result;
}
If I access 2 tables then I have to do this twice for instance.
Is there a way to add all the mapper classes at once to say a collection and depending on the table being accessed the correct one is chosen?
You could add a set of classes within your app that apply custom remapping to your entities. For example these 3 empty classes apply the PrefixDapperTableMapper to the Profile and FileNotificationAdhocRecipient classes while the AnotherDifferentTypeOfDapperClassMapper is applied to NotificationProfile.
public class ProfileMapper : PrefixDapperTableMapper<Domain.Entities.Profile>
{
}
public class FileNotificationAdhocRecipientMapper : PrefixDapperTableMapper<Domain.Entities.FileNotificationAdhocRecipient>
{
}
public class NotificationProfileMapper : AnotherDifferentTypeOfDapperClassMapper<Domain.Entities.NotificationProfile>
{
}
and your actual mapping code exists in separate mappers (I've not shown AnotherDifferentTypeOfDapperClassMapper but that would be similar to below)
public class PrefixDapperTableMapper<T> : ClassMapper<T> where T : class
{
public PrefixDapperTableMapper()
{
AutoMap();
}
//name or schema manipulations in some overrides here.
}
As long as they're in the same assembly, DapperExtensions will find and use them or you can set the mapping assembly with code similar to:
DapperExtensions.DapperExtensions.SetMappingAssemblies({ typeof(ProfileMapper ).Assembly })
I would like to know how Solr indexes general link field or do we need to create computed index field for this ?
I have a helper class which is inheriting from SearchResultItem and it has below index field.
[IndexField("Call To Action")]
public LinkField CallToAction { get; set; }
This field is a general link field in sitecore.
Below is the search code which retrieves all the Event_card values except CallToAction (i.e. Always null). if I convert the field type from Link to string , I get the entire general link raw value which is difficult to parse at view and make it editable through glass mapper.
if (result.TotalSearchResults != 0)
{
//Load Event card data to be displayed on page
var resultItems =
result.Select(c => new Event_Card
{
Headline = c.Document.Headline,
Start_Date=c.Document.StartDate,
Content=c.Document.ContentData,
Call_To_Action=c.Document.CallToAction // this is always null
});
}
Here is my Entity class related to Event_Card
Event_Card
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
[SitecoreField(IEvent_CardConstants.Call_To_ActionFieldName)]
public virtual Link Call_To_Action { get; set; }
IEvent_Card
[SitecoreField(IEvent_CardConstants.Call_To_ActionFieldName)]
Link Call_To_Action { get; set; }
public static partial class IEvent_CardConstants
{
public static readonly ID Call_To_ActionFieldId = new ID("4c296a05-d05f-47c5-8934-8801bec5be85");
public const string Call_To_ActionFieldName = "Call To Action";
}
Can anybody let me know How can I achieve this. If we need to use computed field , an example would be of great help.
Thanks in Advance !
I just quickly browsed and found useful link for you.
Map sitecore 8 general link field from Index
I think this Stack overflow question describes what you are saying and there is a link which might be helpful to you.
This may be a very simple question but I'm very new to EPiServer, so pls help.
I'm working on the EPiServer Relate demo site. I want to progrmatically create a new attribute on Episerver.Common.Security.IUser type. I have created attributes using CMS edit mode Admin options. But I want to know how to do this in code.
You may want to use CommunityAttributeBuilder (https://github.com/Geta/Community.EntityAttributeBuilder) that is similar to PageTypeBuilder for CMS. Currently it's supporting CMS6, I'll commit v7 as soon I will finish testing.
By decorating your class properties with special attribute you will find those created in target site.
For instance:
[CommunityEntity(TargetType = typeof(IUser))]
public class UserAttributes : IClubUserAttributes
{
[CommunityEntityMetadata]
public virtual int AccessType { get; set; }
[CommunityEntityMetadata]
public virtual string Code { get; set; }
[CommunityEntityMetadata]
public virtual int EmployeeKey { get; set; }
[CommunityEntityMetadata]
public virtual bool IsAdmin { get; set; }
}
Library will scan all assemblies and look for types decorated with CommunityEntity attribute, if found one then properties will be scanned and those decorated with CommunityEntityMetadata attribute will be automatically created in DB.
It also supports strongly-typed interface over IUser type:
var metadata = user.AsAttributeExtendable<UserAttributes>();
metadata.AccessType = info.AccessType;
metadata.Code = info.Code;
metadata.EmployeeKey = info.EmployeeKey;
metadata.IsAdmin = info.IsAdmin;
More info about library could be found - http://world.episerver.com/Blogs/Valdis-Iljuconoks/Dates/2012/6/Community-Attribute-Builder-final/
More info about internals (if interested) could be found here - http://www.tech-fellow.lv/2012/06/when-you-need-something-stronger/
You need to use the AttributeHandler class.
Joel has written a great guide with example code here
I am struggling with returning a complex type from my services layer. It doesnt seem to be accessible from my object context.
This is the query in the service layer. All compiling fine.
public IQueryable<USP_GetPostsByThreadID_Result> uspGetPostsByThreadID(int ThreadID)
{
return this.ObjectContext.USP_GetPostsByThreadID(ThreadID).AsQueryable();
}
When I try and call it from my client, the ForumContext is not seeing it. I checked the client generated file and nothing similar is being generated. Help!!!
The name of your method may not meet the expected convention for queries. Try one or both of the following:
Add the [Query] attribute
Rename the method to GetUspPostsByThreadID
Result:
[System.ServiceModel.DomainServices.Server.Query]
public IQueryable<USP_GetPostsByThreadID_Result> GetUspPostsByThreadID(int ThreadID)
{
return this.ObjectContext.USP_GetPostsByThreadID(ThreadID).AsQueryable();
}
Its very common to have a stored procedure returning data from multiple tables. The return type doesn't fit well under any of the Entity Types(Tables). Therefore if we define Complex Type as the return collection of objects from Stored Procedure invocation, it becomes quite a powerful tool for the developer.
Following these steps I have achieved successfully the configuration of complex type on a sample AdventureWorks database.
1. Refer the picture and ensure the Stored procedure and function import is done.
2. Add the Domain Service name it as AdventureDomainService.
3. Now its time to define the tell the RIA services framework to identify my Complex Type as Entity Type. To be able to do this, we need to identify a [Key] DataAnnotation. Entity types provide data structure to the application's data model and by design, each entity type is required to define a unique entity key. We can define key on one property or a set of properties in metadata class file AdventureDomainService.metadata.cs
First define the class then add MetadatatypeAttribute like :
[MetadataTypeAttribute(typeof(CTEmployeeManagers.CTEmployeeManagersMetadata))]
public partial class CTEmployeeManagers
{
internal sealed class CTEmployeeManagersMetadata
{
private CTEmployeeManagersMetadata() { }
[Key]
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int ManagerID { get; set; }
public string ManagerFirstName { get; set; }
public string ManagerLastName { get; set; }
}
}
Define the Domain service method to return the collection of objects/entities for populating the Silverlight Grid or any other data consuming controls.
public IQueryable<CTEmployeeManagers> GetEmployeeManagers(int empId)
{
return this.ObjectContext.GetEmployeeManagers(empId).AsQueryable();
}
We define IQueryable if we are to fetch the records from datasources like SQL, whereas we define IEnumerable if we are to fetch the records from in memory collections,dictionaty,arrays.lists, etc.
Compile the server side to generate the client proxy.
In the Silverlight side open the MainPage.xaml or wherever the datagrid is put, then add following namespaces :
using System.ServiceModel.DomainServices.Client;
using SLBusinessApplication.Web;
using SLBusinessApplication.Web.Services;
..
Load the data and display:
public partial class MyPage : Page
{
AdventureDomainContext ctx = new AdventureDomainContext();
public MyPage()
{
InitializeComponent();
LoadOperation loadOp = this.ctx.Load(this.ctx.GetEmployeeManagersQuery(29));
myGrid.ItemsSource = loadOp.Entities;
}
// Executes when the user navigates to this page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
}
That is all that is needed to do.
It has to be part of an entity. Complex types cannot be returned by themselves