I have a problem in my project using Angularjs. Here is my code:

Controller

     // GET: api/CustomerLists/5


    [ResponseType(typeof(CustomerList))]
    public IHttpActionResult GetCustomerList(int id)
    {

        var data = (from cust in db.CustomerLists
            join call24 in db.CallingList4
                on cust.CustID equals call24.CustID

            where cust.CustID == id

            select new CustomerVM
            {
                CustID = cust.CustID,
                Customer = cust.Customer,
                Call4ID = call24.Call4ID,
                Wk1WebID = call24.Wk1WebID,
                Wk1OrdID = call24.Wk1OrdID



            }).First();

        return Ok(data);

    }



  // PUT: api/CustomerLists/5
    [ResponseType(typeof(void))]
    public IHttpActionResult PutCustomerList(CustomerVM vm)
    {

        if (ModelState.IsValid)
        {
            var cust = db.CustomerLists.Find(vm.CustID);
            var call4 = db.CallingList4.Find(vm.Call4ID);

            cust.Customer = vm.Customer;
            cust.ContactName = vm.ContactName;

            call4.Wk1OrdID = vm.Wk1OrdID;
            call4.Wk1WebID = vm.Wk1WebID;


            db.CustomerLists.Attach(cust);
            db.Entry(cust).State = EntityState.Modified;
            db.CallingList4.Attach(call4);
            db.Entry(call4).State = EntityState.Modified;

            db.SaveChanges();
        }


        return StatusCode(HttpStatusCode.NoContent);


    }

JS

  var EditCtrl = function ($scope, $routeParams, $location, data, $http) {

var id = $routeParams.editId;
$scope.lis = data.get({ id: id });

$scope.selectTest = null;
$scope.testTest = [];

$http({
    method: 'GET',
    url: '/api/OrderStatus/',
    data: { OrderStatID: 1 }
}).success(function(result) {
    $scope.testTest = result;
});


$scope.selectTest1 = null;
$scope.testTest1 = [];

$http({
    method: 'GET',
    url: '/api/WebStatus/',
    data: { WebStatID: 1 }
}).success(function (result1) {
    $scope.testTest1 = result1;
});


$scope.save = function () {
    data.update({ id: id }, $scope.lis, function () {
        $location.path('/');
    });
};

Template

<select class="form-control" ng-model="selectTest" ng-model="lis.OrderStatID">
                <option ng-repeat="s in testTest" value="{{s.OrderStatID}}">{{s.OrderStatus}}</option>
            </select>

View Model

public class CustomerVM
{
    public int CustID { get; set; }
    public string Customer { get; set; }
    public int? Priority { get; set; }
    public string ContactName { get; set; }
    public string ContactNumber { get; set; }
    public int Call4ID { get; set; }
    public int? Wk1WebID { get; set; }
    public int? Wk1OrdID { get; set; }
    public int? OrderStatId { get; set; }
    public string OrderStatus { get; set; }
}

}

When I try to update, the CustomerList details update just fine, but the CallingList4 details return null when I select a status and I try to save an ID. How do I save the ID from another table to the main table which is callingList24? please help

Related posts

Recent Viewed