So far I asked three questions on this forum, but no responses. I hove this time I have more luck :)
On the website I'm working on we have a calendar. For this site we use custom controllers (RenderMvcController) to filter the data before we send it to the View.
We need a way to filter the calendar-items in the controller. For the dates we use two (doc)types of nested content (single date OR a range of dates).
I would like the filtering to be as simple as possible (Linq), so I need to be able to access the properties of the nested content.
My collegue has good experience with Vorto and nested content. All he needed was to extend the generated models with another partial class.
public partial class UmbNewsItem
{
[ImplementPropertyType("news")]
public Newsdetached News
{
get
{
var news = this.GetVortoValue<IPublishedContent>("news");
return news == null ? null : new Newsdetached(news);
}
}
}
I would like something in the same line. The difference is that his nested content is limited to one doctype and only one nested item is permitted. In my case there could be several items and I use nested content of two (doc)types.
Me and my co-worker are both relatively new to Umbraco (< 1 year). This is my first attempt at extending Umbraco generated models.
I use LiveAppData to generate the models. I have a partial class to extend the generated class.
Could this work?
public partial class Agenda
{
//"datum" is the property that has nested content
//returns IEnumerable of Single Date
public IEnumerable<EnkeleDatum> EnkeleDatum
{
get
{
return this.GetPropertyValue<IEnumerable<EnkeleDatum>>("datum");
}
}
//returns IEnumerable of a range of dates
public IEnumerable<Datumbereik> DatumBereik
{
get
{
return this.GetPropertyValue<IEnumerable<Datumbereik>>("datum");
}
}
}
public partial class Agenda : IMySharedInterface
{
public bool ShouldIUseThis
{
//My agenda specific implemetation
return this.
}
}
Personally I don't use the LiveAppData models approach. I've moved to using the API to get compiled models in my own dlls. But that is just another approach you could use.
The forum does work :-) Just sometimes things slip by the wayside unfortunately.
I know there are discussions about the forum happening to try and help this but I think they will be a little bit of time before they are implemented.
In the mean time, please persist. Don't get disheartened if your question doesn't get an answer. You can always throw a bump on it (but don't spam it) to get it back up the list or, if you solve the problem yourself share your answer. :-)
Extending Generated Classes
Hi,
So far I asked three questions on this forum, but no responses. I hove this time I have more luck :)
On the website I'm working on we have a calendar. For this site we use custom controllers (RenderMvcController) to filter the data before we send it to the View.
We need a way to filter the calendar-items in the controller. For the dates we use two (doc)types of nested content (single date OR a range of dates).
I would like the filtering to be as simple as possible (Linq), so I need to be able to access the properties of the nested content.
My collegue has good experience with Vorto and nested content. All he needed was to extend the generated models with another partial class.
I would like something in the same line. The difference is that his nested content is limited to one doctype and only one nested item is permitted. In my case there could be several items and I use nested content of two (doc)types.
Could someone point me in the right direction?
Hi Sven,
How are you generating your classes?
I've you had experience extending classes already, you could add a common interface to the doc types you are looking to work with ?
Nik
Hi.
Me and my co-worker are both relatively new to Umbraco (< 1 year). This is my first attempt at extending Umbraco generated models.
I use LiveAppData to generate the models. I have a partial class to extend the generated class.
Could this work?
Hi Sven,
Yeah, the premise is the same.
So you could do something like:
Personally I don't use the LiveAppData models approach. I've moved to using the API to get compiled models in my own dlls. But that is just another approach you could use.
Nik
Thank you for the time and the response. This is the proof I needed to know that the forum works :)
I have not tested it yet, but at the moment I have written this code:
The forum does work :-) Just sometimes things slip by the wayside unfortunately.
I know there are discussions about the forum happening to try and help this but I think they will be a little bit of time before they are implemented.
In the mean time, please persist. Don't get disheartened if your question doesn't get an answer. You can always throw a bump on it (but don't spam it) to get it back up the list or, if you solve the problem yourself share your answer. :-)
is working on a reply...