How to use a local database with a SPA hot towel template on ASP.NET MVC 4

I am probably the most inexperienced person at MVC, not to mention the Hot Towel SPA, but nonetheless I expect to create a system based on these technologies.

I read the Breeze website and all the John Papa documentation, but I just don't know how to create interactions with my database and retrieve data and display data, add or edit data, including deleting data.

I need to create a dashboard with approximately 5 grids on the screen, displaying real-time data when it comes with some time calculations.

All I have for 2 days is the Hot Towel template, modified to display my project name, and I changed the hot towel icon. I just can’t plunge into this topic ... For two years I was the developer of the ASP.NET website with a 3-tier architecture.

Can someone give me recommendations on how to transfer data through this template?

+5
source share
1 answer

I started with Hot Towel SPA, but used other links, such as the Durandal MovieApp sample, which you can find here. http://stephenwalther.com/archive/2013/02/08/using-durandal-to-create-single-page-apps.aspx . I also downloaded and reviewed the breezejs runtime, which included samples.

SQL Entity Frameworks WEBAPI breezejs. .

 [BreezeController]
public class ProjectBillingController : ApiController
{
    readonly EFContextProvider<ProjectBillingContext> _contextProvider =
   new EFContextProvider<ProjectBillingContext>();

    // ~/api/todos/Metadata 
    [HttpGet]
    public string Metadata()
    {
        return _contextProvider.Metadata();
    }


    [HttpPost]
    public SaveResult SaveChanges(JObject saveBundle)
    {
        return _contextProvider.SaveChanges(saveBundle);
    }

    [HttpGet]
    public IQueryable<Client> Clients()
    {
        return _contextProvider.Context.Clients;
    }
    ...

Durandal Movie APP

/App 
/App/respositories 
/App/repositories/repository.js
/App/viewmodels 
/App/viewmodels/clients
/App/viewmodels/clients/show.js 
/App/viewmodels/clients/edit.js
/App/viewmodels/clients/create.js 
/App/views/clients
/App/views/clients/show.html 
/App/views/clients/edit.html
/App/views/clients/create.html

, - , .

breezejs 1 . ,

// repository.js
function getRecordLists(modelsListsObservable, errorObservable, entity) {

    return breeze.EntityQuery
    .from(entity)
    .using(manager).execute()
    .then(querySucceeded)
    .fail(queryFailed);

    function querySucceeded(data) {
        modelsListsObservable(data.results);
        logger.log('Fetched ' + entity, null, null, true);

    }

    function queryFailed(error) {
        errorObservable("Error retrieving" + entity + " : " + error.message);
        logger.error("Error retrieving" + entity + " : " + error.message, null, null, true);

    }
};


function getRecord(id, clientObservable, errorObservable, entity, entityKey) {
    return breeze.EntityQuery.from(entity)
    .where(entityKey, "==", id)
    .using(manager).execute()
    .then(querySucceeded)
    .fail(queryFailed);

    function querySucceeded(data) {
        clientObservable(data.results[0]);
        logger.log('Fetched a record from ' + entity, null, null, true);
    }

    function queryFailed(error) {
        errorObservable("Error retrieving a record from " + entity + ": " + error.message);
        logger.error("Error retrieving a record from " + entity + ": " + error.message, null, null, true);
    }

};

// show.js
define(function (require) {

    var repository = require("repositories/repository");
    var app = require('durandal/app');
    var router = require("durandal/plugins/router");
    var logger = require('services/logger');
    var models = ko.observableArray();
    var error = ko.observable();

    return {
        models: models,
        error: error,
        deleteRecord: deleteRecord,

        activate: function (data) {
            return repository.getRecordLists(models, error, "Resources");
        }
    };

, . , , , .

+6

All Articles