locked
My application is not working RRS feed

  • Question

  • User-35580265 posted

    This is the adminProductController.js

    angular.module("sportsstoreAdmin").constant("producturl", "/api/Data/").config(function($httpProvider) {
    $httpProvider.defaults.withCredentials = true;
    }).controller("productctrl", function ($scope, $resource, producturl) {
    $scope.productresource = $resource(producturl + ":id", { id: '@id' }, { query: { method: 'GET', url: '/api/Data/GetAllData/', isArray: true }, delete: { method: 'DELETE', url: '/api/Data/Delete/' }, save: { method: 'POST', url: '/api/Data/Put/' } });
    $scope.edittedproduct = {};
    $scope.listproducts = function ()
    {
    $scope.products = $scope.productresource.query();
    }
    $scope.deleteproduct = function (product)
    {
    product.$delete({id:product.Id}).then(function () {
    $scope.products.splice($scope.products.indexOf(product),1);
    });
    }
    $scope.createproduct = function (product)
    {
    product.$save().then(function (newproduct) {
    $scope.products.push(newproduct);
    $scope.edittedproduct = null;
    });
    }
    $scope.updateproduct = function (product)
    {
    product.$save();
    $scope.edittedproduct = null;
    }
    $scope.startedit = function (product) {
    $scope.edittedproduct = product;
    }
    $scope.canceledit = function () {
    $scope.edittedproduct = null;
    }
    $scope.listproducts();
    });

    DataController  


    public class DataController : ApiController
    {
    EFDbRepository repository = new EFDbRepository();
    [HttpGet]
    public IEnumerable<ComDataModel> GetAllData()
    {
    return repository.Products;
    }
    [HttpPost]
    public object Put(ComDataModel com)
    {
    if(com.Id==0)
    {
    ComDataModel cd= repository.Create(com);
    return cd;
    }
    else
    {
    repository.Update(com);
    return null;
    }
    }
    // DELETE api/values/5
    [HttpDelete]
    public void Delete(int id)
    {
    repository.Delete(id);
    }

    }

    adminproducts.cshtml

    <style>
    #productTable{ width:auto;}
    #productTable td
    {
    max-width:150px;
    text-overflow:ellipsis;
    overflow:hidden;
    white-space:nowrap;
    }
    #productTable td input{
    max-width:125px;
    }
    </style>
    <div ng-controller="productctrl">
    <table id="productTable" class="table table-bordered table-bordered table-hover table-striped">
    <thead>
    <tr><th>Name</th><th>Description</th><th>Category</th><th>Price</th></tr>
    </thead>
    <tbody>
    <tr ng-repeat="item in products" ng-hide="item.Id == edittedproduct.Id">
    <td>{{item.Name}}</td>
    <td class="description">{{item.Description}}</td>
    <td>{{item.Category}}</td>
    <td>{{item.Price | currency}}</td>
    <td>
    <button class="btn btn-xs btn-primary" ng-click="startedit(item)">Edit</button>
    <button class="btn btn-xs btn-primary" ng-click="deleteproduct(item)">Delete</button>
    </td>
    </tr>
    <tr ng-class="{danger:edittedproduct != null}">
    <td><input ng-model="edittedproduct.Name" required /></td>
    <td><input ng-model="edittedproduct.Description" required /></td>
    <td><input ng-model="edittedproduct.Category" required /></td>
    <td><input ng-model="edittedproduct.Price" required /></td>
    <td>
    <button ng-hide="edittedproduct.Id != null" ng-click="createproduct(edittedproduct)" class="btn btn-xs btn-primary">Create</button>
    <button ng-show="edittedproduct.Id != null" ng-click="updateproduct(edittedproduct)" class="btn btn-xs btn-primary">Save</button>
    <button ng-show="edittedproduct != null" ng-click="canceledit()" class="btn btn-xs btn-primary">Cancel</button>
    </td>
    </tr>
    </tbody>
    </table>

    </div>

    When I press the crete button product is not creating. Delete and query are working. So the problem should in the way I configured $resource. Do you guys have any idea regarding this?

    Friday, March 13, 2015 3:16 AM

Answers

  • User1508394307 posted

    I think there is no any server side exception.

    In this case this is off-topic here.

    I'd suggest to debug createproduct() - put breakpoint or alert() to that function and see step by step what you get there.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 13, 2015 9:28 AM

All replies

  • User1508394307 posted

    You need to

    a) see if you don't have any js-error in the browser (open Developer Tools F12 and go to console)
    b) run project in Debug mode and see if you have no any server side exception.

    Friday, March 13, 2015 3:23 AM
  • User-35580265 posted

    I think there is no any server side exception. But I found this in the browser.

    I have no clear idea what it is...

    Friday, March 13, 2015 3:41 AM
  • User1508394307 posted

    I think there is no any server side exception.

    In this case this is off-topic here.

    I'd suggest to debug createproduct() - put breakpoint or alert() to that function and see step by step what you get there.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 13, 2015 9:28 AM
  • User1711366110 posted

    When I press the crete button product is not creating. Delete and query are working. So the problem should in the way I configured $resource. Do you guys have any idea regarding this?

      As per your case, I believe that the issue belongs to angular JS.
    so I suggest you to post this thread to the corresponding forum.
    Thanks for understanding.
    --
    with regards,
    Edwin

    Monday, March 16, 2015 3:05 AM