working with MVP and creating a Filtered Detail List (1 Viewer)

Cowboy_BeBa

Registered User.
Local time
Today, 22:30
Joined
Nov 30, 2010
Messages
188
Hi All

Just a bit of background before getting started, ive been developing access databases for years and consider myself very proficient in them. Recently ive looked into rebuilding a DB i made for work into a web app and selling it off to other companies (work is cool with this as i made their entire db on my own from scratch).

Im okay with web design but wanted this to be perfect (especially in terms of security, wasnt confident i could create something that would keep my clients data secure). So i outsourced a lot of the coding to india. The devs over there did an excellent job, but they used an MVC framework (which i am completely unfamiliar with, i specified simple html pages linked to visual CS pages which i could then understand and alter as needed, this MVC stuff is confusing the hell outta me)

Was just wondering if someone could give me some basic pointers on MVC's and how they work (for instance i can see the model of my DB, based in mysql, wondering if i change a table or a query in the db, does the model need to be updated? if so how? am using the latest version of Visual Studios to develop if that makes a difference)

Secondly, in order to make this project much cheaper (they originally quoted 25k) i left out a few pages which i intend to design (i figured i'd give them the more complex ones and then i could use their code for reference to create some of the simpler ones, since they dropped the price down 10k it made things much more affordable). This is fine as im visual studios inbuilt scaffolding feature in order to generate new pages, then i just have to muck around with the HTML in order to get them to look similar to the other pages.

One of the pages i need to make is basically a list of one of my tables. Just a simple details list which the user can then edit or delete records if they need to. This is simple enough but the tricky part is that i need to allow the user to be able to filter each and every field they wish. For instance there is a "Stock" field, user should be able to select one (or more) products they wish to view records for, then theres a date field, user should be able to specify a date, or search for records between two dates. There are many such fields and i need each one to be filterable.
Have absolutely no idea how to accomplish this. I dont need to be given the exact solution (i like figuring these things out for myself, best way to learn), but i would appreciate someone pointing me in the right direction (not even sure what to call the type of page i wish to create)

Thank you all for reading :)
 

jleach

Registered User.
Local time
Today, 10:30
Joined
Jan 4, 2012
Messages
308
Hello,

The MVC pattern is very popular for web development (for good reason: it suits it very well). That said, it's not the easiest thing in the world to describe, but I'll give it a go:

MVC = Model View Controller
Model: contains data (like a recordset, sort of...)
View: contains the actual markup for the HTML
Controller: receives requests, gathers data, applies to view, sends response

So a request comes in to, say, mysite.com/Home/Tasks. The "Home" controller receives the request in the "Tasks" action, says "get me the latest tasks" from elsewhere in the system, then says "let's take this view, embed the data, and send that back"

So in C# ASP.NET Razor syntax, a View might be a template mixed with HTML and C#:

Code:
@model List<My.Namespace.TaskItem>

<html>blahblah
<ul>
@foreach(var ti in Model) {
  <li>@ti.TaskName</li>
}
<ul></html>

This would be a template that basically says: for a given list of task items, loop each item and print a listitem in the html.

The actionable controller method then might be something like this:

Code:
public ActionResult Tasks() {
   List<TaskItem> model = _dataRepo.GetActiveTasksList();
   return View("NameOfMyTemplateFromAbove.cshtml", model);
}

That says "ok, incoming request for Tasks page: let's get all the recent tasks as the model, and apply them to the View, then return the result of that merge"


That's MVC in a nutshell.

The more difficult part I think is that people don't often realize at first that MVC is a presentation level pattern only! That is, the data can come from anywhere. In fact, it shouldn't actually come direct from a database, but rather through some other model. In the controller example, I had a _dataRepo object in there that might have served as some sort of data repository. That's where you might have code that fetches your data (or just works up a simple test list without a database, etc).

As for listing tables and having them filterable, that's actually quite easy. Just find a decent javascript tables library that allows you to do so (I like the DevExtreme components myself, but there's plenty other free ones around)


Also, just to be clear: the MVC pattern is used by multiple development platforms: Spring, Swift, ASP.NET, Laravel, Angular, etc. Not sure which you're working with, but the core concepts (the pattern) are the same across all. Not to be confused with other presentation level patterns such as MVP or MVVM.

Not sure if that helps or not, but if you want some clarification just ask. Cheers
 
Last edited:

jleach

Registered User.
Local time
Today, 10:30
Joined
Jan 4, 2012
Messages
308
Here's a demo of the DevExtreme data grid. Telerik has a similar one as well. Use the nav on the left of the page to see demos of different modes and features:

https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/Overview/jQuery/Light/

You can see the datagrid configuration options here: https://js.devexpress.com/Documentation/ApiReference/UI_Widgets/dxDataGrid/

(note: stay away from the DevExpress MVC extentions: they're terrible, but the DevExtreme are all javascript based and have far better support than most open source libraries)
 

jleach

Registered User.
Local time
Today, 10:30
Joined
Jan 4, 2012
Messages
308
for instance i can see the model of my DB, based in mysql, wondering if i change a table or a query in the db, does the model need to be updated?

Generally speaking, yes. One thing we have to do a lot of in .NET is mapping. Map db fields to DTOs, DTOs to domain models, domain models to view models, etc. Gets old after a while, so you start looking at automapper tools.

Anyway, this is actually out of the scope of MVC itself (remember in my prior post I noted that many people confuse the fact that MVC is a presentation layer pattern only).

A common approach is a to have what's called a 3-tier architecture: a data layer, a "logic" layer (your basic classes), and a presentation layer. The presentation layer calls up objects from the logic layer, which are filled with data from the presentation layer. In such case, if you change a field name (why would you?), you would have to edit the appropriate mappings in the data layer.

With that said, there's about 1000 ways of doing this and just as many tools, libs and frameworks to help with it, so giving something definite is very difficult.

I would suggest using a dependency mapper of some sort to try and identify the core areas of the project and understand how they have the project architecture set up. You'll need to know that prior to being able to make appropriate changes, I think. If you want, expand everything in the solution explorer, post a snapshot of the solution explorer here and I can try to advise on what I can infer from it (also worth noting: overseas work isn't always the best quality, often the appropriate roles of each area are muddled and the nice clear lines between separations of concern don't end up being nice and clear, etc. - anyway, post the solution explorer snapshot (with all projects expanded) and I'll see what I can get from it)
 

Users who are viewing this thread

Top Bottom