MVC design for archived data view - sql-server

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.

Related

Where should I manage advanced algorithms/services on the server side in my project structure?

I'm working with nodejs, expressjs, mongodb and angular with RESTful API.
Here is my project structure.
-- config
-- models
-- public
---- css
---- js
------ controllers
------ services
---- views
-- routes // API route
Everything was ok because my API calls were simple and most of the logic is managed by angular with services.
But now I have to implement advanced algorithms and some logic server side and I don't know where to do it.
Should I add another services folder server side? How would you manage it?
Depends on your application. Since you application has a node.js backend. and you want to implement advanced algorithms, it should be on the server side. Its always wise to keep the front-end light as possible because you don't want the user to be waiting.
Keep some weight on the back-end, but again it all depends on what type of application you are talking about. All your advanced algorithms should be written in the Controllers or the .js files.
Example server side structure for a shopping cart application :
Note how the categories.js, product.js, models.js, api.js are broken down to.
In summary:
If your advanced algorithms comes in pricing of a product in reference to the example shopping cart application, its better to write it in the product.js and if its related to sorting categories, or showing categories according to user, then better write that logic in the category.js. This will be handy for the existing and a new developer coming into the application. Remember, organized applications are fun to upgrade.
Yes, I would recommend that you add a services folder that holds server-side js files that do some biz, and those files could be in turn organized according to your biz models, for example you can have services/products.js that handles some biz operations on the products collection/table.
In turn you can inject those files into your controllers/routes using something like
var productsBiz = require('./services/products.js');
and use that productsBiz by calling any of its exposed members.
BTW, I see some other folks out there do those biz stuff by adding custom functions on the db models themselves, that would be a good idea but that is logically valid only for functions related to this specific db model, for example doing some custom validation or altering values before saving, but for biz related to the whole app and not specifically for a db model, for example handling orders which will involve several db models like products, orders, shipping, invoices, etc., in such case I recommend doing such biz in a services/*file*.js.

Best practice for loading non model data in ExtJS

Let's assume that I have 2 tables in my database, a user table and a folder table. They are matched by two models (beans) in my backend java code and similarly by to models in my extjs client side. Using viewmodel architecture, I want to create a form that shows the username and the amount of folders they have created using viewmodel bindings. Each folder in the database has a CREATE_USER_ID field that contains the id of the user that created the folder. How do I go about loading the required data?
Viewmodels are not designed to load data directly (and not designed to load non model data at all). You've got two options:
Go model (recommended). Two sub-options:
Add folder_amount field to your client side user model. On the server side this does not necessarily need to be added as well as you can adjust your API feeding data to client to add that field dynamically.
If you want to keep your client models exactly matching their server mates, use viewmodel in conjunction with associations (see example here, scroll down to Associations) to load folders themselves, though in the UI only show the amount of them. Mind that you don't need to load all folder fields but just their IDs.
Stick to your own fancy non model approach, but this won't have anything to do with viewmodel bindings. This may be, for example, making an AJAX call to retrieve the number of folders when user data is rendered in the UI.

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

Dynamic MVC Routing Removing Id With Efficient Database Lookup

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,

Data conflict resolution in Silverlight with WCF Service

When using Silverlight together with a WCF Services library how do you solve the age old possibility of two different users loading a record, making different changes to that record and then updating. In other words when updating how does the WCF service know that the data it retrieved is the same as the data it fetched before applying an update?
Do you need to check the original loaded values against the values in the database (i.e. recall the original query before updating)?
I was hoping that there would be a more out-of-the-box answer.
Do you mean using EntityFramework? If so, here is the strategy I used :
When retrieving data on the client side you see that the "RowState" property of the entity is gone. What I did is I added the property on the client side using the "partial class" feature. And I manage locally the value of that RowState value.
When the data goes back to the server for update only send what has been modified filtering by the "RowState" property.
On your Update method, call the ApplyCurrentValues() method of the object.
Maybe there is a better solution for that, but that's what I am using on my project; and it works well on my case :)
Good luck

Resources