How to create CRUD asp.net mvc application without using a database - asp.net-mvc

I am relatively new to asp.net mvc and Ihave been trying to create a simple CRUD application without using a database and consequently without using DbContext. However, it seems as no feasible. Should I consider DI to address that?
Any ideas would be very welcome.

You will need object persistent framework of some type or can create your own. This can all be done without a database but will use persistent theory.
Really the only way to start doing this is with persistent software programming theory. You would create an object inside an object and inside another object. The objects are stored via an array. You would then need to iterate through the arrays to find the particular item to remove the object from the array.
For example, you would create object of country and then store objects of a state in the country. Then inside of the state array you would store people in another array.
Could create Universe, inside universe would be constellations, and inside constellations would be the star object. All this is stored using arrays.
To save the state you would store all this to a bin file using serializable class that that country array would read to restart the state of all the objects. I have wrote software like this for desktop applications in VB.
I am thinking you would do the same thing using C# and simply create your objects.
Is this the type of thing you had in mind?
This same theory can be used instead of using cookies to track a users progress on a site, but seems like most people just use a cookie.

you could use a static dictionary if you want to do this just for learning purposes,
note you'll loose all the data on app stop,
here's a tutorial for asp.net mvc basics which does a bit of crud at the end without DB: http://youtu.be/fsfOFL4bXXA

Related

Workflow with MVC 4 - EF 5 - SimpleMembershipProvider

So I want to build an application with MVC 4 and Entity Framework 5. I've build simple applications before, but now I need some security around my current effort... I have some confusion / questions that I was hoping someone could answer;
First... Using the MVC 4 Internet Application Template it implements SimpleMembershipProvider. I have read every primary article about modification, implementation... However, this uses a Code-First implementation...
Problem: I have an existing database that I would like to import the scheme for to an EDMX database first approach... How do I implement the MVC 4 Simple membership provider when my database ties tightly and directly into the user table (userid)?... I know I can use my own user table as long as i designate the userid and username fields as documented... Will this affect the provider, or the existing "AccountController" code? Will these need to be modified?
Second, what I am looking for is a workflow with this architecture... I am "old school" mostly database first approach... My project is a huge WIP (work in progress). I have a foundation, but will need to expand as needed... Can someone provide some insight into database first vs other approaches when there will be quite a bit of change management occurring?
you can still use Code First to map to an existing database. You may need to explicitly map properties to table columns because the mappings do not follow the default conventions, but that doesn't prevent you from using Code First.
When transitioning from DB first to another mindset. Focus on how the objects interact with each other. then, at some point you will save the state of the objects after they interacted. This is where the ORM comes into play. detects changes and executes the necessary SQL statements to persist the current state of the objects.
Think of the database as just another storage container. In theory it could be replaced by another persistent storage mechanism (document db, file, persistent hash table, in memory list, etc.). In reality it's not that simple, but the idea of treating the DB as just a simple storage container helps to break away from the monolithic database concept that is/was ingrained into most devs.
But don't loose perspective of the design either. If it's a simple forms-over-data app where you will be adding features in the future than keep the design simple. than don't try to totally abstract the DB away. you know it's there and the relationship to the UI is almost 1:1, so take advantage of that.
In it's simplest form separation of concerns can be achieved by using the MVC controller to manage the interaction between the model (mapped to the DB via ORM) and the view (razor templates) my personal preference is to keep ORM out of the views so I typically query the database, map the domain model to a viewmodel and then pass the viewmodel to the view.
Again if it's a simple application and screens map directly to the database than viewmodel are probably overkill.

What’s the best approach to work with in memory domain objects in Grails?

I’m working on a Grail’s project that has some Domain objects not persisted on the database. They are managed thru a REST API, so all their CRUD operations will be done with this API instead of the database.
The point is to still be able to use some interesting Grails plug-ins (like searching using Compass).
For instance, the administration the Domain objects Users is going to be managed with the REST API, so when the Users list is displayed a the REST method to retrieve the list of users will be invoked on the remote server. I hope this use case is clear enough :)
I can think on several ways to design that but I'm not sure what’s the best:
Should I create the Domain Objects in the controller (and delete the
previous Users stored in memory)?
It seems it’s possible to define a Domain Class not persistable (with
mapping I think) but I’m not sure if this is the best approach or
where to load the data.
It is better not to model as a Grails the User as Domain object?
Thanks in advance!
I would wrap the REST interactions in a service, and call the service from a controller. In that case, the service would get the response and create its objects, passing the list back to the controller. Controllers should just handle incoming requests, invoke application components, and return responses.
It seems you want models to represent the data in the other application, which is a good idea. Since you don't need GORM, you might want to define them in the 'groovy' folder of your app instead of the domain models folder. Then I think they will just be objects.
I'd go with non-domain objects in src folder - though, need to check if it's possible to use the mentioned plugins with them.
I wonder what domain class functionality you wish to get out of non-persistent classes?

Editing heirarchical data in ASP.NET MVC 2

Can anyone point me to some good resources that can help me understand the best way to work with hierarchical data in ASP.NET MVC 2?
I have an application under development that requires an interface allowing users to add, remove and modify children and grand-children of my root object. The user can make multiple changes without persistance. Only when they click "Save" will the entire object graph be saved.
I've seen one article that serialized the object and stored the data in a hidden field on the form but that seems really cludgy and I am dealing with a lot of data.
If I was doing this in standard ASP.NET, I'd be looking at using child windows and the like to display the edit pages and maintain an instance of the object being edited in Session - which is bad in and of itself. But I've been told we are using MVC as we are standardizing our platforms (but not moving up to MVC 3 yet).
Essentially I need that app to display the properties of my root which includes a child collection of objects. The UI should allow the user to add new items to the collection, remove existing items and 'open' an item for editing. These child items also contain their own list of grandchildren that is editable as well. All of this needs to go on without round-trips across the wire to persist data (its a distributed architecture with all data access behind a WCF service interface).
The examples on www.asp.net all persist the data each time a single change is made, i.e. each postback. But, that would require major schema changes and extra code to deal with temporary objects versus committed objects plus the overhead of the service calls each time. I'm looking for a better solution.
Have you considered looking at any client side libraries like Knockout.JS? I've found that it is excellent at manipulating collections and posting the final version as JSON. Here is an example of what you can do with it. Here is an article about how to integrate it with MVC 2. This is my absolute favorite JS library.

Use MVC Custom Model Binder?

I have an MVC app I'm writing. There will be the need for multiple instances of the same page to be open, each accessing different records from a database, these record objects will also need to be passed through a flow of pages, before finally being updated.
What's the best, and most correct, way of acheiving this - should/can I create a custom model binder that links to an object via it's unique ID and then create each record-object in the session, updating them as I go through each one's page flow and then finally calling the update method? Or is there a better way of dealing with this?
Cheers
MH
Technically, that would be possible, but I don't think it is advisable. When you look at the signature of IModelBinder, you will have to jump through some hoops related to the ControllerContext if you want to be able to access the rest of your application's context (such as how to dehydrate objects based on IDs).
It's possible, but so clunky that you should consider whether it's the right approach. In my opinion, a ModelBinder's responsibility is to map HTTP request data to strongly typed objects. Nothing more and nothing less - it is strictly a mapper, and trying to make it do more would be breaking the Single Responsibility Principle.
It sounds to me like you need an Application Controller - basically, a class that orchestrates the Views and the state of the underlying Model. You can read more about the Application Controller design pattern in Patterns of Enterprise Application Architecture.
Since a web application is inherently stateless, you will need a place to store the intermediate state of the application. Whether you use sessions or a custom durable store to do that depends on the application's requirements and the general complexity of the intermediate data.

Global state in asp.net mvc application

Problem: Our web console shows a list of all computers on which our application is installed. Each machine has some identification information that can be associated with it. Simple strings like department name, team name etc. We need to make it such that the user can change the name of these identification fields and add/remove as many as he wants. How can we best implement this?
Initially i thought that i could implement this as a singleton. In the application start, i could read the last set identity field names from the db and create a singleton instance of a list of strings. This could be passed around to all functions that need to display or access the identity information. The appeal in this option is that if the user changes the identity fields name from the ui or adds or removes the fields, i can simple modify the singleton object and the change will be reflected.
However i feel there must be a better way to achieve what i want. Because there a lot of such information that the user can modify at will and we need to track them.
Any suggestions?
Just use the objects from your ORM to maintain and use this information in the application. Many ORMs have the ability to cache this sort of thing, so it's not like you will lose any speed over it.
I'm not a big fan of using a Singleton to do this. It's hard to unit test, and you'll still have to persist it to the database eventually.

Resources