0

I have an input field where employee can enter one or more Customer number and when they hit button it will get values of input field and it will put values into an array and than post data to contorller and in the end it will retrieves some data based on customer numbers to employee.

Lets say employee enter following customer numbers: 10883,10886,10888 and than it will put values in an array: items[10883,10886,10888]

and it will retrieves data for only: 10883,10886

as you see there is no data for: 10888

Her is my Question, when data retrieves to employee how can i make a condtions to check and see if there is no data for one of customer numbers tell employee for example:. there is no data for 10888

HTML:

    <label>Enter Customer number</label>
    <input name="CustomerNumber" id="CustomerNumber">
    <button type="button" onclick="BtnAddCustomers();">Add</button>

JavaScript:

function BtnAddCustomers() {
var holderHTML = '';

var items = [];
items = $("#CustomerNumber").val().split(",");

$.ajax({
  type: "GET",
  url: "/User/GetCustomerContactInfo",
  data: { ids: items },
  traditional: true,
  dataType: 'json',
  success: function (values) {

  for (var i = 0; i < values.length; i++) {
                  value = values[i]

  if (value != null) {

  holderHTML += '<tr id="row' + value.CustomerNo + '">';
  holderHTML += '<td><input  type="text" id="NameOfCompany"  name="[' + i + '].NameOfCompany" value="' + value.NameOfCompany + '" /></td>';
  holderHTML += '<td><input type="text" id="CustomerNo"  name="[' + i + '].CustomerNo" value="' + value.CustomerNo + '" /></td>';
  holderHTML += '</tr>';
     }
 $('#output').html(holderHTML);
                    }
                 }

              })
          };

Controller:

    [HttpGet]
    public JsonResult GetCustomerContactInfo(string[] ids)
    {

        var CustomerContactInfo = db.SomeTable
                      .Join(db.SomeTable, v => v.No_, g => g.No_, (v, g) => new { g, v })
                      .Select(t => new CreateCustomers
                      {

                          CustomerNo = t.v.No_,
                          NameOfCompany = t.g.Name,

                      })

                      .Where(s => ids.Contains(s.CustomerNo))
                      .ToList();


        return Json(CustomerContactInfo, JsonRequestBehavior.AllowGet);


    }

Can anyone please help me or point me into the right direction ?! :)

  • You'd need to debug. Is the right info going to getcustomercontactinfo, is it returning a json with all the data in.. etc – BugFinder Aug 07 '19 at 09:55
  • @BugFinder Not problem with dat right info going to action and it will return data if customer number exist and ofcurse it retrieve nothing if dont as i say in my question i will get data for 10883,10886 but i dont get data for 10886 becuase its not exist and i want employe know about dat. – The Professor and the Madman Aug 07 '19 at 10:03
  • then you need to check you got data back for all the things you submitted... – BugFinder Aug 07 '19 at 10:05

1 Answers1

0

I'm not a JavaScript person so I can't give you a code sample, but if I understood correctly, you receive customer number with data for every customer that exists in the database.

If so, you could, for example, extract client numbers from a response and do a subtraction of numbers collections (providedNumbers - numbersFromResponse). What you will get will be a collection of client numbers that don't exist in the response.

Check this question to see how to do subtraction in JavaScript. You can also use .difference() from Underscore.js library.

MadTiger2409
  • 91
  • 1
  • 10