Connection String vs Data Service call - asp.net-mvc-3

I have 2 separate MVC 3 websites (A & B), both with their own SQL Azure databases which may or may not be on the same server. Both are using Code First Entity Framework and will be deployed to windows azure.
Website A is considered the master website and database. This holds data of the clients using our software along with usernames and passwords. I want website B to connect to website A's database when user logs in or registers. Website B will also need to hit website A's database in order to get some of the client's data after the user is logged in.
Right now I just have this one website B hitting website A's database, but in the future I will have more of these websites like website B hitting the main database for the same reasons.
My question is what is the best way to send and receive data between these smaller websites and the master database?
At first I was just using 2 connection strings in website B with two different contexts(one for each db). I liked this because the object types all flowed together, there wasn't any converting to do.However, I wasn't sure if this was the best and most secure way to go.
Another option I have been looking at is oData Services. I do like the idea of having everything separated and just calling the service when needing data from the master database. The issue I am having though is transferring the data from the service into my model's objects. I am having to do nasty things like this foreach statement:
public ActionResult GetMovies()
{
var ctx = new MovieODataService.MovieContext(new Uri("http://localhost:54274/MovieService.svc/"));
DataServiceQuery<MovieODataService.Movie> query = ctx.Movies;
var response = query.Execute() as QueryOperationResponse<MovieODataService.Movie>;
var model = new MovieModel();
model.Movies = new List<Movie>();
foreach (var item in response)
{
model.Movies.Add(new Movie
{
Title = item.Title,
ReleaseDate = item.ReleaseDate
});
}
return View(model);
}
I am also open to any other suggestions. Thanks in advance!

OData is great for a lot of things, but where it really shines is in exposing rich queryability over (preferably) schematized information. That doesn't really feel like a great fit for authentication calls.
Have you looked at the more traditional authentication protocols, such as OAuth? That seems like a much better fit for what you're trying to achieve.

Related

How to access View Template Properties for Revit and compare them in Real Time?

I am trying to list the view template’s properties so we can compare them with another old template.
For example what model elements are hidden or have overrides in a given template or which Revit links have been hidden or overridden in a given template.
View Template
(https://www.google.com/search?q=view+template+revit&rlz=1C1GGRV_enUS770US770&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjLndrd2cTbAhVESq0KHX1cAPwQ_AUICygC&biw=1536&bih=824#imgrc=Q0v-pV7Nxl4kfM:)
I’m looking to devise a View Template Compare tool and access to the owner and creator of them.
public void ApplyViewTemplateToActiveView()
{
Document doc = this.ActiveUIDocument.Document;
View viewTemplate = (from v in new FilteredElementCollector(doc)
.OfClass(typeof(View))
.Cast<View>()
where v.IsTemplate == true && v.Name == "MyViewTemplate"
select v)
.First();
using (Transaction t = new Transaction(doc,"Set View Template"))
{
t.Start();
doc.ActiveView.ViewTemplateId = viewTemplate.Id;
t.Commit();
}
}
With Revit API you can access with:
GetTemplateParameterIds Method / ViewTemplateId Property
The Revit API exposes almost all the ViewTemplate properties.
For instance this method returns all the Visibility/Graphic Overrides for a specific category:
https://apidocs.co/apps/revit/2019/ed267b82-56be-6e3b-0c6d-4de7df1ed312.htm
The only thing I couldn't get for a ViewTemplate are the "includes", but all the rest seems to be there.
Update:
The list or properties "not included" can be retrieved with GetNonControlledTemplateParameterIds().
Yes, and no.
Yes, I guess you can use Forge Model Derivative API to export RVT file and then build a dashboard around the View Templates data. That's assuming that View Templates data actually gets exported when the model is translated. That data is not attached to any geometry so I would not be surprised if it was skipped. The question here is why? This is like renting a 16-wheel truck to move a duffel bag across the street.
No, if your intention is to directly interact with the RVT model. Forge can view it, but to push anything back or request changes to the model, is not available yet. Then again, I am not even sure that the view template data is available via model derivative exports.
This brings me another alternative. Why not just collect the data using Revit API, the standard way and then push it out to a Database and build on top of that? There is no reason to employ Forge for any of that.
Thanks Jeremy, I had dig into your amazing website and also some solution that Konrad post in the Dynamo Forum about this. In Revit seems pretty achievable, you filter the View that is View Template and then extracts these properties, is it correct?.
I am wondering if someone can point me in the right direction with Forge.
Some amazing guys are developing a BQL https://www.retriever.works/.
BQL(Building Query Language) is a query language for buildings, similar to how SQL is a query language for databases. It is fast and flexible. BQL helps improve efficiency for QA/QC (quality assurance and quality control), and building data extraction without leaving Revit. I am also trying these and I would like to understand if there are some works where I could start with Forge next week about this.

How to structure Shopify data into a Firestore collection that can be queried efficiently

The Background
In an attempt to build some back-end services for my e-commerce (Shopify based) site I have set up a Firestore trigger that writes order details with every new order created which is updated by a web hook POST function provided by Shopify - (orders/Create webhook).
My current cloud function -
exports.saveOrderDetails = functions.https.onRequest((req, res) => {
var docRef = db.collection('orders').doc(req.body.name);
const details = req.body;
var setData = docRef.set(req.body).then( a =>{
res.status(200).send();
});
});
Which is able to capture the data from the webhook and store it in the order number's "name" document within my "orders" collection. This is how it looks in Firestore:
My question is - with the help of body-parser (already parsing out "name" which is represented as #9999 in my screenshot, to set my document name value) - how could I improve my cloud function to handle storing this webhook POST in a better data structure for Firestore and to query it later?
After reviewing the comments on this question, I moved this question over to Firebase-Talk and it appears the feature I am attempting here would be close to what is known as "collection group queries" and was informed I should adjust my data model approach since this feature is currently still on the road map - and perhaps look into the Firestore REST API as suggested by #jason-berryman
Besides the REST APi, #frank-van-puffelen made a great suggestion to look into working with Arrays, Lists, Sets for Firebase/Firestore
Another approach that could mitigate this in my scenario is to have my HTTP Firestore cloud trigger have multiple parsing arguments that create top more top level documents - however this could cause a point of scaling failure or an increase of cost factor due to putting more parsing processing logic in my cloud function and adding additional latency...
I will mark my question as answered for the time being to hopefully help others to understand how to work with documents in a single collection in Firestore and not attempt to query groups of collections before they get too far into modelling and need to restructure their app.

Sitefinity: Where can I find the master GUID for a content item?

I'm building a web service for a client that pulls data from the Sitefinity CMS. The problem is they want to pass in a Guid for the service and receive the info about this item. No problem except I only have been able to locate the "live" Guid for one Item (and that was by combing through the HTML in the back end).
I was going to look at the tables in SQL Server but I'm not sure which table to look at. The content items have several tables all related of course and there isn't any documentation on how to look at this. I can find plenty of documentation on querying the master Guid, but no place to find it.
Oh, and these are custom content types built by the Module Builder.
Any Help would be SOOOOO appreciated!
var master = DynamicModuleManager.GetManager().Lifecycle.GetMaster(<liveGuidHere>);
One of the biggest consumers of Sitefinity webservices is Sitefinity. The best place to start looking for that guid is to take a look at what web service calls are being made when you pull up your custom content item list in the backend. I used the chrome developer tools and check in the network tab.
One I found for a stores module made with module builder was something to the effect of http://www.testsite.com/Sitefinity/Services/DynamicModules/Data.svc/?managerType=Telerik.Sitefinity.DynamicModules.DynamicModuleManager&providerName=OpenAccessProvider&itemType=Telerik.Sitefinity.DynamicTypes.Model.Stores.Store&provider=OpenAccessProvider&sortExpression=LastModified%20DESC&skip=0&take=50
The json this returns is a list of all the masters with their ids (note in the list that the content items all have have a status of 0) http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/content-lifecycle
When you go to Administration / Module Builder / Your Module, you will see a link to the API on the top right corner.
This link goes to a page full of API examples for your particular module which is kind of cool.
Basically you would have to find your item first using LINQ and the GetValue extension method.
Once you have the item you can get its ID or any other property.
using Telerik.Sitefinity.Utilities.TypeConverters;
using Telerik.Sitefinity.DynamicModules;
using Telerik.Sitefinity.Model;
....
var mgr = DynamicModuleManager.GetManager();
var countrymasters = from ctry in mgr.GetDataItems(TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Destinations.Destination"))
where ctry.GetValue<string>("culture") == siteid &&
(ctry.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && ctry.Visible == true)
select new
{
airport_cd = ctry.GetValue<string>("airport_cd"),
country_master_cd = ctry.GetValue<string>("country_master_cd")
};

Entity Framework--Filter Data At Load Time

I’m building an MVC3 application with form authentication and a single hierarchical entity. The entity has a Region object as the “root” with several other objects. It looks something like:
Region->Language->objectA->objectB
Region->Application->….
Each user (other than administrators) is associated with single region. I'd like to limit the data loaded to the entity based on the user’s region. I’m not too familiar with EF. Is this appropriate or is there a better approach? How would I implement the best approach
You can certainly filter the data returned via Entity Framework. The code would look something like this:
using (MyContext ctx = new MyContext())
{
var filtered = (from r in ctx.Regions where SOME_CONDITIONS select r);
// Do stuff with filtered (which is an IEnumerable<Region>)
}
Note that you may need to use Include to load related objects, e.g.
ctx.Regions.Include("Language").Include("Application")
see http://msdn.microsoft.com/en-us/library/bb896272.aspx

Does Web Matrix (Or ASP.NET Web Pages) have a built in ORM?

What I know about web development I can count on one hand. In an effort to change that I have begun to look at asp.net web pages as this technology seems to have a low technical barrier to entry and sits nicely, in my view, above plain 'ol HTML.
I have been working through some samples and something has caught my eye. To create a connection and query a database you simply have to do this:
#{
var database = Database.Open("deanvmc");
var sqlQuery = "SELECT * FROM Articles";
var data = database.Query(sqlQuery);
}
From that I seem to be able to access the row data from the returned table in the following fashion:
#foreach(var row in data)
{
<article>
<h3>#row.Heading</h3>
<nav>
<ul>
<li>#row.DatePosted</li>
<li>#row.Category</li>
<li>0 Comments</li>
</ul>
</nav>
<p>#row.SubHeading</p>
</article>
}
Is this an ORM at work? Is it correct to assume that the object contained in row will always be mapped to the columns returned from the sqlQuery?
Also, is this a function of webmatrix as a stack or asp.net web pages as a library? I am a little confused about where one ends and the other begins.
The code above does not use an ORM - it is simply mapping fields returned from the database view to the row object returned by your query. So your assumption is correct - all of the object properties are mapped to the columns returned from the query.
WebMatrix itself is just a web development tool - it provides the editor, templates, and other dev tool type things. The libraries you're using (ASP.NET Web Pages with Razor & C#) are the stack on top of which your application is built. WebMatrix happens to also support non .NET technologies such as PHP, and may support more in the future.
I know this was kind of open ended, but hopefully I was some help. Happy Coding!

Resources