Dynamic MVC Routing Removing Id With Efficient Database Lookup - sql-server

I have an MVC 3 application where I want dynamic Urls which do not contain a controller or key name. A good example of this would be if I had a blog, and users add in new posts.
Say a user creates a post called
My Blog Post
I have a method that creates a url SLUG and stores it in the database with the entry, so I want the Url to be
/my-blog-post
This has no controller or key name in the url now? How do I achieve this with MVC routing? Currently I'm doing it by matching the Url with an ID like /my-blog-post_1234 and using that ID as the DB lookup key using fluent nhibernate but I'm a little lost once I remove the ID?
As I can still get the string/slug, but that means I now have to do a SQL lookup based on the string 'my-blog-post'? I have read this is not efficient and could compromise speed, and some of these titles could be pretty long.
I've heard people saying things about custom route tables? Would this help me or not? I suppose the main thing is getting the data from the database in the quickest most efficient way.
any help/pointers greatly appreciated.

The MVC framework isn't going to provide any help here. Your requirement is to query by slug, so that's what you'll need to do in the DB.
You just need to make sure you have an index on this column in the DB to make sure the query doesn't need to do a table scan.

Sounds like what you really want is a document database. Coupled with MVC. I would highly recommend ravendb,

Related

2sxc - Getting URL path from DNN link parameter / Tab ID

I am working on integrating a 2sxc content WebAPI feed into a ReactJS application.
I have managed to get a JSON feed of data into the application, and am in the process of mapping out the data.
I'm wondering what the best practice would be to "resolve" a URL which is coming through as a DNN Page/ Tab ID.
Below I will showcase the various points this is referenced...
First the Setup of the entity / data types...
Then this is an example entry with the data filled out... The page link / URL is set up to point to another internal page on the DNN website:
Finally you can see this data item come through as a JSON feed via the 2sxc API:
What is the best way to convert this piece of data into a URL which can be used in a SPA type application?
There isn't any "server-side" code going on, just reading a JSON feed on the client side...
My initial idea would be to parse this piece of data in JS, to extract the number then use something like this:
http://www.dotnetnuke.com/tabid/85/default.aspx
http://www.dotnetnuke.com/default.aspx?tabid=85
I was hoping someone with more experience would be able to suggest a better / cleaner approach.
Thanks in advance
If you were server-side in Razor you'd be doing something like this:
#using DotNetNuke.Common
View List
XXXX = Dnn.Tab.TabID or define a string with the tab id you want
I seem to have a vague memory that I saw somewhere that Daniel (2sxc) has a way to use Globals.NavigateUrl() or similar on the client side, but I have no idea where or if I did see that.
The Default.aspx?tabid=xx format will certainly work, as it's the oldest DNN convention and is still used in fallbacks. The urls aren't nice, but it's ok.
The reason you're seeing this is because the query doesn't perform the automatic lookup with the AsDynamic(...) does for you. There is an endpoint to look them up, but they are not official, so they could change and therefor I don't want to suggest that you use them.
So if you really want a nicer url, you should either see if DNN has a REST API for this, or you could create a small own 2sxc-api endpoint (in the api folder) just to look that up, then using the NavigateURL. Would be cool if you shared your work.

How to add a powerful search functionality to my web app

I am building an app to browse events. The front end uses angular framework and the backend uses laravel.
How do I add a powerful search functianlity, wherein the user enter his query using an input element and I pass the same to laravel controller.
I now need to return relevant events based on the query.
As of now I am using a very basic algorithm - each word in a query is pushed into an array. Article's are discarded. Based on the length of the array, I try to match each words to some fileds in the table and return unique events.
Is there a better, faster and more efficient way of doing this.
You could use laravel-search
It has support for a few advanced search methods.
I recommend you to use Elastic search for your goals. You can find tutorial here: http://www.fullstackstanley.com/read/simple-search-with-laravel-and-elasticsearch. Also you can use good wrapper https://github.com/mmanos/laravel-search for elastic and another search engines.
Well you added the tag elasticSearch so I guess that's what you are interested in. ElasticSearch has no authentication system so the best way is to create a controller in Laravel that comunicates with elasticSearch a returns the JSON response.
A basic setup will not be hard to do, anything beyond that will need you to learn more advanced concepts of ElasticSearch.
ElasticSearch will handle the search algorithm for you, you just need to pass the value the user is searching and that's it.

How to build sets of entity records using Breeze and local storage

I'm trying to create an off-line data collection app, using AngularJS.
I think, adding Breeze.js should help with saving and querying data to and from the browser local storage:
1) present the user with angular data entry form
2) when the "save" button is clicked - create a new Breeze entity and store it locally
3) the next time this form is used - create a second entity, and add/save it as a part of the same collection
I was wandering if anyone have tried to do something similar and could give me some pointers of how this is done.
I think it's viable and these links should help you to get started:
http://www.breezejs.com/documentation/querying-locally
You also might want to check this Angular sample aswell:
http://www.breezejs.com/samples/todo-angular
One caveat you have to have in mind is that Breeze will need to load the model's metadata from somewhere. Typically you hit a Web API asynchronously and get the metadata from there. However, on your particular scenario you should give a look at trying to load your metadata from a script file. Here's an how-to and discussion about it:
http://www.breezejs.com/documentation/load-metadata-script

MVC design for archived data view

Implementation of a standard archive process in ASP.Net MVC. Backend SQL Server 2005
We've an existing web app built in MVC. We've an Entity "Claim" and it has some child entities like ClaimDetails, Files, etc... A pretty standard setup in DB. Each entity has its own table and are linked via FK. Now, we need to have an "Archive" feature in web app which will allow admin to archive a Claim and its child entities. An archived Claim shud become readonly when visited again.
Here're some points on which I need your valued opinion -
To keep it simple and scalable (for a few million records) for now we plan to simply add a bit field "Archived" to the Claim table in db.
And change the behavior accordingly in the web app.
We've a 'Manage claim' page which renders a bunch of diff views for Claim and its child entities. Now, for a readonly view we can either
use the same views or have a separate set of views. What do you
suggest?
At controller level, we can identify archived claim and select which view to render.
At model level, though it'd be great to be able to use the same model used for Manage Claim - but it might not get us the "text" of
some lookup fields. For example, Claim.BrandId is rendered as a
dropdown in Manage claim (requires only BrandId) but for readonly view
we need 'BrandText'.
Any existing ref or architecture level example would be great.
Here's my prev SO post but its more about db level changes: Design a process to archive data (SQL Server 2005)
Thank you.
I ended up using a duplicate of the existing view with some edits and archive specific changes. I was able to use the same backend model and data fetch structure in a different action.
My entity table has an archived flag which helps identify the status so the rest of the fetch implementation stays the same only a new view (mostly replicated) and a new action (replicated from the existing one) got me the archived view.

DotNetNuke -- Inserting URL parameters in forms

We are migrating our website to DotNetNuke and are looking to replicate the functionality of our survey page. Currently, on the bottom of every e-mail we send through our CRM system, there is a link to a satisfaction survey along with some parameters to pre-populate some of the fields. So the URL looks something like like:
/survey.aspx?ticketID=1234&userName=John+Doe
I found the custom module "helferlein_Form" which seems okay for actually creating the form that the user fills in, but I don't see a way to pre-populate the fields. DotNetNuke does let you insert tokens(ex: [Date:now], [User:username]), but I don't see a way to grab individual parameters from the URL. Is there something I'm missing that will let me do that?
I'm not familiar with that module either, but I would strongly recommend using Xmod for customized forms that allow you to easily grab url parameters.
I'm not sure about the module you reference.
However, in my experience Dynamic Forms from Data Springs would fit the bill perfect. It has the ability to pre-fill and even run custom SQL queries to get data.
You should definitely try our My Tokens module.
It allows you to access the URL parameters using [Get:ticketID] or [QueryString:tickedID]. You can also build SQL tokens that use these parameters to return a list of items for example to populate a dropdown.
Also try our Action Form module which integrates very nice with My Tokens.
If you have a module you like and want to use you can always write a little javascript to grab the variables out of the URL and pre-populate your form fields using javascript.

Resources