This commit is contained in:
Halil İbrahim Kalkan 2015-12-13 19:10:14 +02:00
Родитель 2facf05315
Коммит dd357a4f84
4 изменённых файлов: 51 добавлений и 35 удалений

Просмотреть файл

@ -5,10 +5,12 @@ namespace MultipleDbContextDemo.Services
{
public interface ITestAppService : IApplicationService
{
List<string> GetFromFirstDb();
List<string> GetPeople();
List<string> GetFromSecondDb();
List<string> GetCourses();
List<string> GetFromBothDbs();
List<string> GetPeopleAndCourses();
void CreatePerson(string name);
}
}

Просмотреть файл

@ -6,38 +6,44 @@ namespace MultipleDbContextDemo.Services
{
public class TestAppService : MultipleDbContextDemoAppServiceBase, ITestAppService
{
private readonly IRepository<Person> _persons;
private readonly IRepository<Course> _courseRepository;
private readonly IRepository<Person> _personRepository; //in the first db
private readonly IRepository<Course> _courseRepository; //in the second db
public TestAppService(IRepository<Person> persons, IRepository<Course> courseRepository)
public TestAppService(IRepository<Person> personRepository, IRepository<Course> courseRepository)
{
_persons = persons;
_personRepository = personRepository;
_courseRepository = courseRepository;
}
public List<string> GetFromFirstDb()
public List<string> GetPeople()
{
var peopleNames = _persons.GetAllList().Select(p => p.PersonName).ToList();
var peopleNames = _personRepository.GetAllList().Select(p => p.PersonName).ToList();
return peopleNames;
}
public List<string> GetFromSecondDb()
public List<string> GetCourses()
{
var courseNames = _courseRepository.GetAllList().Select(p => p.CourseName).ToList();
return courseNames;
}
public List<string> GetFromBothDbs()
//a sample method uses both databases concurrently
public List<string> GetPeopleAndCourses()
{
List<string> names = new List<string>();
var peopleNames = _persons.GetAllList().Select(p => p.PersonName).ToList();
var peopleNames = _personRepository.GetAllList().Select(p => "Person: " + p.PersonName).ToList();
names.AddRange(peopleNames);
var courseNames = _courseRepository.GetAllList().Select(p => p.CourseName).ToList();
var courseNames = _courseRepository.GetAllList().Select(p => "Course: " + p.CourseName).ToList();
names.AddRange(courseNames);
return names;
}
public void CreatePerson(string name)
{
_personRepository.Insert(new Person(name));
}
}
}

Просмотреть файл

@ -1,27 +1,18 @@
<div ng-controller="app.views.home as vm">
<h1>@L("WellcomeMessage")</h1>
<p class="lead">@L("Home_ThisIsATemplate")</p>
<div class="row">
<div class="col-md-4">
<h3>ASP.NET MVC</h3>
<p>
@L("Home_AspNetDescription")
</p>
<a class="btn btn-primary btn-sm" href="http://asp.net/mvc">@L("LearnMore")..</a>
<div class="col-md-6">
<h2>List of People and Courses</h2>
<ul>
<li ng-repeat="item in vm.items">
{{item}}
</li>
</ul>
</div>
<div class="col-md-4">
<h3>ASP.NET Boilerplate</h3>
<p>
@L("Home_AspNetBoilerplateDescription")
</p>
<a class="btn btn-primary btn-sm" href="http://aspnetboilerplate.com">@L("LearnMore")..</a>
</div>
<div class="col-md-4">
<h3>Angularjs</h3>
<p>
@L("Home_AngularDescription")
</p>
<a class="btn btn-primary btn-sm" href="http://angularjs.org/">@L("LearnMore")..</a>
<div class="col-md-6">
<h2>Create New Person</h2>
<input class="form-control" type="text" ng-model="vm.name"/>
<button class="btn btn-default" ng-click="vm.createPerson()">Submit</button>
</div>
</div>
</div>

Просмотреть файл

@ -1,9 +1,26 @@
(function() {
var controllerId = 'app.views.home';
angular.module('app').controller(controllerId, [
'$scope', function($scope) {
'$scope', 'abp.services.app.test',
function ($scope, testService) {
var vm = this;
//Home logic...
vm.items = [];
vm.name = '';
function loadPeopleAndCourses() {
testService.getPeopleAndCourses().success(function (result) {
vm.items = result;
});
}
vm.createPerson = function () {
testService.createPerson(vm.name).success(function() {
loadPeopleAndCourses();
});
}
loadPeopleAndCourses();
}
]);
})();