I want to pass some data from a html form using a angularjs, to a sql database. This is my form
<form class="form-group">
<div class="col-md-6 col-lg-6">
<div class="row ">
<div class="form-group col-xs-5 col-lg-6">
<label>Background color for views</label>
<input type="text" name="background_color" id="background_color" color-picker ng-model="selectedLayout.background_color" class="form-control"/>
</div>
</div>
</div>
</form>
<button class="btn btn-primary" id="saveChanges-button" ng-click="saveChanges(selectedLayout)">Save</button>
This is my controller
(function () {
'use strict';
angular.module('routerApp').controller('LayoutController', function ($scope,$rootScope,layoutRepository) {
$scope.saveChanges = function (selectedLayout) {
layoutRepository.saveLayoutInfo(selectedLayout);
};
});
}());
And this is my repository
(function () {
'use strict';
angular.module('routerApp').factory('layoutRepository', function ($http) {
return {
saveLayoutInfo: function (selectedLayout) {
console.log(selectedLayout);
$http({
method: 'POST',
url: '/api/LayoutSettings',
data: selectedLayout,
cache: false
});
}
};
});
}());
So I want that information to be sent to a sql database which have this connection string: Data Source=PC-RPASNICE\SQLEXPRESS;Initial Catalog=DatabaseSample.Program+LayoutContext;Integrated Security=True, And only have this fields:
public class LayoutOptions
{
[Key]
public string Name { get; set; }
public string Value { get; set; }
public DateTime LastModifiedDate { get; set; }
}
How to do this?