Copied to clipboard

Flag this post as spam?

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


  • Benjamin Vejs 3 posts 23 karma points
    Jul 02, 2014 @ 03:42
    Benjamin Vejs
    0

    Retrieving records from another MS SQL Database

    I'm working on a website, where I need to retrieve pricelists, from another database on the same MS SQL Server as my umbraco Database.

    it's a requirement that it has to be in a separate database.

    I have made a new connectionString "Pricelist" and used EF Database First.

    PriceList Repository:

    namespace UmbracoCMS.Repository{
    using System;
    using System.Collections.Generic;
    
    public partial class Prisliste
    {
        public string Kode { get; set; }
        public string Speciale { get; set; }
        public string Ydelsesgruppe { get; set; }
        public string Gruppe { get; set; }
        public string Ydelse { get; set; }
        public string Ydelsestekst { get; set; }
        public string Anaestesi { get; set; }
        public string Indlæggelse { get; set; }
        public Nullable<double> Listepris { get; set; }
        public Nullable<int> WebSort { get; set; }
        public string YdelsesTekstDK { get; set; }
        public string Frapris { get; set; }
        public Nullable<int> Sortering { get; set; }
      } 
    }
    

    Controller class:

    using System;
    using System.Linq;
    using System.Web.Mvc;
    
    using UmbracoCMS.Repository;
    
    namespace UmbracoCMS.Controllers{
    
      public class PriceListController : Umbraco.Web.Mvc.SurfaceController {
    
        [HttpGet]
        public PartialViewResult GetPriceList(string contentTitle){
    
            var db = new PricelistContext();
    
    
            var query = from b in db.Prislistes orderby b.Speciale select b;
    
            Console.WriteLine("records in the database:");
            foreach (var item in query)
            {
                Console.WriteLine(item.Speciale);
            }
    
    
            return PartialView("~/views/partials/PriceList.cshtml");
        }
      }
    }
    

    What I want is to load the prices for a treatment, based on a property on the document type. I'm just not sure how do this in umbraco since im fairly new a umbraco.

    So when a treatment page is requested, I need to take the property ContentTitle value. Use it to retrieve all record with the same "Speciale" and display it in a list/table.

    with a query .where(b.Speciale = contentTitle)

    It would be great if someone could help a litle, or lead me in the right direction.

    Also is it possible to do it in the same httpRequest? or should I use partialView or macros to both get the properties of the document type, from the umbraco database, and the records from the pricelist database at the same time when a user go to the treatmentpage?

    Or is there a better way to do this?

  • Amir Khan 1282 posts 2739 karma points
    Jul 02, 2014 @ 19:49
    Amir Khan
    0

    Hi Benjamin, just an FYI, you can write do SQL queries right in a partial view and (I think) handle all of your requirements with Razor, I did this at some point to integrate to grab some things from a companies legacy site.

    Here's something to reference: http://www.asp.net/web-pages/tutorials/data/5-working-with-data

    -Amir

Please Sign in or register to post replies

Write your reply to:

Draft