Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mircea Stanciu 1 post 71 karma points
    Jan 04, 2016 @ 13:31
    Mircea Stanciu
    0

    Custom sql tables with petapoco and mvc routing

    I have a large sql database that I've added connection to web.config. In this database I have listed some services, each row having an id, serviceName, serviceDescription, serviceSummary, serviceBilling.

    Using petapoco, as described here https://www.youtube.com/watch?v=0PtzyrEFG7I i managed to create a view were i can display data.

    This is my petapoco model

    [TableName("[datatable].[dbo].[vw_servicii]")]
    [PrimaryKey("Id", autoIncrement = true)]
    
    public class Service{
    
       public int Id { get; set; }
        public int serviceName{ get; set; }
        public string serviceDescription{ get; set; }
        public string serviceSummary{ get; set; }
        public string serviceBilling{ get; set; }}
    

    then there is this controller that getsAll and get by id:

    public class ServiceController
    {
    
        public static IList<Service> GetAll()
        {
            UmbracoDatabase db = ApplicationContext.Current.DatabaseContext.Database;
            return db.Fetch<Service>("SELECT * FROM [datatable].[dbo].[vw_servicii] WHERE Id = 201000002");
        }
    
        public static IList<Servicii> GetAllById(int ServiciuConsularId)
        {
            UmbracoDatabase db = ApplicationContext.Current.DatabaseContext.Database;
            return db.Fetch<Service>("SELECT * FROM [datatable].[dbo].[vw_servicii] WHERE Id= @0 ", Id);
        }
    
    }
    

    My view does this foreach grab of data

     @foreach (var serv in ServiceController.GetAll())
    {
        foreach (var serv in ServController.GetAllById(201000001))
        { <p>@serv.serviceName</p>}
    

    If i go to /viewName i can see the data. But i need to control the rendering of data with the url. Each product (row in database) must have 3 templates: one to display description, one to display summary, and the last to display the billing data. I should end up with an structure like: /serviceName/templatetype/id.

    A real case would be :

    assurance/description/201000001 
    

    ,were the view would display data from the serviceDescription database column querying "where serviceName=assurance and id =201000001", in the description template . For the same id the url assurance/billing/201000001 would render data from serviceBilling database column using billing template.

    I can't figure out how to tie petapoco with custom mvc routing. Can i do this withoud manualy creating nodes in umbraco's admin?

    kind regard, Mircea

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies