how can we save taxes values to subitems?
for eaxmple if we insert Name values on text box that can be properly inserted to table(item)
In item we have Id and Name fields
Id can be automatically incremented on database
coming to subitem1
we have aid ,RAI_id and text fields
aid ->auto increment
RAI_id ->Id it's coming form item table(i have mapped item table to subitem1)
text -> the values what ever we have inserted in taxes(value field values) popup coming to here
Final output in database should be saved like this
Item(table in database) subitem1((table in database) )
Id Name aid RAI_Id text
1 mahesh 1 1 abd
2 laxman 2 1 abdb
3 2 ejje
CREATE TABLE [dbo].[AutoPopList](
[id] [int] IDENTITY(1,1) NOT NULL,
[value] [numeric](18, 0) NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Item](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Item] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[subitem1](
[aid] [int] IDENTITY(1,1) NOT NULL,
[RAI_Id] [int] NOT NULL,
[text] [nvarchar](50) NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[subitem1] WITH CHECK ADD CONSTRAINT [FK_subitem1_Item] FOREIGN KEY([RAI_Id])
REFERENCES [dbo].[Item] ([Id])
GO
ALTER TABLE [dbo].[subitem1] CHECK CONSTRAINT [FK_subitem1_Item]
GO
@{
Layout = null;
}
<html>
<head>
<title></title>
</head>
<body>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', [])
app.controller('MyController', function ($scope, $http, $window, RegistrationService) {
//Loads all Employee records when page loads
loadEmployees();
function loadEmployees() {
var EmployeeRecords = RegistrationService.gettaxes();
EmployeeRecords.then(function (d) {
//success
$scope.taxes = d.data;
},
function () {
alert("Error occured while fetching employee list...");
});
}
$scope.Save = function () {
loadEmployees();
var User = {};
//User["Name"] = $scope.OrderName;
User["Customer"] = $scope.Customers;
alert(JSON.stringify(User));
$http({
method: "Post",
url: "/dynamicaalyaddremove/SaveOrder",
data: User,
}).success(function (data) {
alert(data);
$scope.Customers = [];
}).error(function (err) {
$scope.Message = err.Message;
})
};
});
app.service("RegistrationService", function ($http) {
//get All taxes
this.gettaxes = function () {
return $http.get("/dynamicaalyaddremove/getAll1");
};
});
</script>
<div ng-app="MyApp" ng-controller="MyController">
<table cellpadding="0" cellspacing="0">
<tr>
<th>Name</th>
<th>taxes</th>
<th> </th>
</tr>
<tbody ng-repeat="m in Customers">
<tr>
<td>{{m.Name}}"</td>
<td>{{m.Country}}</td>
@*<td value="{{m.subitems}}"><button type="button" data-ng-model="subitems" data-toggle="modal" data-target="#popup">Click</button></td>*@
<td value="{{m.subitems1}}">
<button type="button" class="btn btn-primary" ng-init="clicked=false" ng-click="clicked=!clicked">
View Orders
</button>
<div class="modal fade in" aria-hidden="false" style="display: block;" ng-show="clicked">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" ng-click="clicked=false">
×
</button>
<h4 class="modal-title">
Order Details
</h4>
</div>
<div class="modal-body" style="overflow: scroll; max-height: 85%; margin-top: 50px; margin-bottom: 50px;">
<table class="table table-condensed">
<thead>
<tr style="padding-left: 10px; padding-right: 10px;" class="active">
<th class="thick-line" style="padding-left: 10px; padding-right: 20px; padding-top: 6px;
padding-bottom: 6px;">
id
</th>
<th style="padding-left: 10px; padding-right: 10px;" class="thick-line">
Value
</th>
<th style="padding-left: 10px; padding-right: 10px;" class="thick-line">
Action
</th>
</tr>
</thead>
<tbody ng-repeat="o in m.taxes">
<tr>
<td>
{{o.id}}
</td>
<td>
<span ng-show="editOrder != true">{{o.checkbox}}</span>
<input ng-show="editOrder" type="checkbox" name="vehicle1" ng-model="o.checkbox">
</td>
<td>
<span ng-show="editOrder != true">{{o.value}}</span>
<input ng-show="editOrder" type="text" ng-model="o.value" class="form-control" />
</td>
<td>
<button class="btn btn-primary" type="button" ng-show="editOrder != true && editingOrder != true"
id="Button1" ng-click="editOrder = true; EditOrder(o)">
<i class="fa fa-fw fa-pencil"></i>
</button>
<button class="btn btn-primary" type="button" ng-show="editOrder" id="Button2" ng-click="editOrder = false; SaveOrder($index)">
<i class="fa fa-save"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" ng-click="clicked=false">
Ok
</button>
</div>
</div>
</div>
</div>
</td>
<td>
<input type="button" ng-click="Remove($index)" value="Remove" />
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td><input type="text" ng-model="Name" /></td>
<td><button type="button" ng-model="subitems1" data-toggle="modal" data-target="#popup1">Click</button></td>
<td><input type="button" ng-click="Add()" value="Add" /></td>
</tr>
</tfoot>
</table>
<div class="modal fade" id="popup1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<div class="s2vk-container">
<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<table class="table table-condensed">
<thead>
<tr style="padding-left:10px; padding-right:10px;" class="active">
<th class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">Id</th>
<th class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">Checkbox</th>
<th style="padding-left:10px; padding-right:10px;" class="thick-line">Value</th>
<th style="padding-left:10px; padding-right:10px;" class="thick-line">Action</th>
</tr>
</thead>
<tbody>
<tr style="padding-left:20px; padding-right:20px;" ng-model="myData3" ng-repeat="subitem in taxes">
<td>{{subitem.id}}</td>
<td><input type="checkbox" name="vehicle1" ng-model="checkbox" >
</td>
<td>
<span ng-show="editOrder != true">{{subitem.value}}</span>
<input ng-show="editOrder" type="text" ng-model="subitem.value" class="form-control" />
</td>
<td>
<button class="btn btn-primary" type="button" ng-show="editOrder != true && editingOrder != true"
id="Button1" ng-click="editOrder = true; EditOrder(subitem)">
<i class="fa fa-fw fa-pencil"></i>
</button>
<button class="btn btn-primary" type="button" ng-show="editOrder" id="Button2" ng-click="editOrder = false; SaveOrder($index)">
<i class="fa fa-save"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div style="padding:10px 0;">
<input id="submit" type="button" value="Save" name="add" ng-click="Save()" class="btn btn-success" />
</div>
</div>
</body>
</html>
namespace Readanddisplayexcelfile.Controllers
{
public class DynamicaalyAddRemoveController : Controller
{
private InvoiceEntities db = new InvoiceEntities();
// GET: DynamicaalyAddRemove
public ActionResult Index()
{
return View();
}
public JsonResult getAll1()
{
List<AutoPopList> Emp = db.AutoPopLists.ToList();
return Json(Emp, JsonRequestBehavior.AllowGet);
}
[HttpPost]
public ActionResult SaveOrder(Item[] Customer)
{
string result = "Error! Order Is Not Complete!";
if (Customer != null)
{
foreach (var item in Customer)
{
//var orderId = Guid.NewGuid();
Item O = new Item();
//O.RAI_Id = orderId;
O.Name = item.Name;
O.subitem1= item.subitem1;
//O.subitem1 = item.subitem1;
db.Items.Add(O);
}
db.SaveChanges();
result = "Success! Order Is Complete!";
}
return Json(result, JsonRequestBehavior.AllowGet);
}
}
}