Copied to clipboard

Flag this post as spam?

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


  • Nick Babaki 22 posts 71 karma points c-trib
    May 21, 2016 @ 09:36
    Nick Babaki
    0

    Database relations

    I have a price table which created in database and I use petapoco to work with data.

    The reason I didn't created it as Document Type is because I have a vast number of records(The price changes every hour). But number of products are limited so i created Product as a document Type.

    My problem is how I make the relation between price table and products as the prices get updated by a windows service, so the service need to know products and products' id and then create the record in price table.

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    May 21, 2016 @ 20:57
    Bo Damgaard Mortensen
    1

    Hi Mehrdad,

    I tend to simply just couple the node ID to my custom tables, when it's needed.

    So basically, just add a new column on your price table called ProductNodeIdor something like that. That way you can get all prices for a given Product node.

    To make the most clean solution, you could then hook into the IContentService' Deleted event, so when a Product node is deleted, the related prices will also be deleted or be marked as being inactive or whatever the business rules dictate.

    To expose the product nodes to the Windows Service, you could set up an endpoint be creating a new controller class, which inherits from the SurfaceController class. Something like this:

    public class MyController : SurfaceController
    {
         [HttpGet]
         public JsonResult GetProducts()
         {
             // Eventually set up some kind of authentication here
             IEnumerable<IPublishedContent> products = // .. fetch product nodes from Umbraco here
             return Json(products.Select(x => x.Id), JsonRequestBehavior.AllowGet);
         }
    }
    

    The above (not tested, written from top o' my head) method should return a JSON array of your product IDs for your windows service to consume.

    Hope this makes sense :-)

Please Sign in or register to post replies

Write your reply to:

Draft