As the question, the front-end is ultimately in contact with the data of the display layer, if divided according to the MVC model, it is only a V level, which is not conducive to the overall development and cultivation of the overall view, always out of the comfort zone, today we will try, out of the js comfort zone.

In business, we may encounter such a demand, is after click add to insert data into a form, click the add button after a pop-up window will appear first, then bring up a popup window can be alternative grid, the user choose one or several data after click ok, and then the data can be added into the list, but at this time because of business needs, Data provided by the new popup window is not detailed, so we will need to be in after the user to select the data, after click the select button to continue to call a backend interface, pass the selected data in an array to the background, the background data for our processing and then return to us, also not too concerned about this before, is simply to write the business logic, If you ask me why I called this interface, I can only describe the missing fields as mentioned above, which fields are missing, and why, I have no answer. Today we’re going to focus on what this interface does.

So, first of all, we know that this interface is called GetMoveLineForPdaAdd, which belongs to the stock_ItemMoveService controller, and then we can globally search the GetMoveLineForPdaAdd in the background project,

Not surprisingly, you’ll find this code

Come across c# code, but don’t panic, after all, we have a few years of js background, let’s take a look at what this code is doing. In fact, in general, similar to the method we often write in JS, is also used to call you.

First of all:

[HttpPost]
Copy the code

[HttpPost] [HttpGet] [HttpGet] [HttpPost] [HttpGet] [HttpGet] [HttpGet] [HttpGet] [HttpGet] [HttpGet] [HttpGet] [HttpGet] [HttpGet] [HttpGet]

And then:

public ApiResponseContent GetMoveLineForPdaAdd(JObject jo)
Copy the code

Define a method called GetMoveLineForPdaAdd that supports passing the parameter Jo.

And then:

string errMsg = string.Empty;
Copy the code

Initializes a variable errMsg and defaults to null.

Second:

if (jo == null)
    return Fail("Incoming parameter is empty!");
Copy the code

Non-null check is performed on the passed parameter Jo.

Third:

if (jo["data"] = =null)
    return Fail("Incoming data cannot be null!");
Copy the code

Here, we conclude that Jo is an object, which must have a data property, and that data will be non-null checked.

And then:

var userInfo = CurrentUser;
Copy the code

A local variable userInfo is defined to cache all variables CurrentUser.

Once again:

if (userInfo.EmpId == null)
{
    return Fail("Login expired, please log in again!");
}
Copy the code

Determine if the EmpId attribute of the userInfo cache is empty. If it is empty, the user login expires

Here’s the key:

var result = Stock_ItemMoveOperate.GetMoveLineForPdaAdd(JsonConvert.DeserializeObject<List<V_BasicItem_ItemViewDTO>>(jo["data"].ToString()),out errMsg)
Copy the code

Here we know that the data that we pass to the background is not processed here, but is transferred to this method, and then we select the method and press F12 to follow.

After going in, you will see a method roughly like this, and this method, which really shows us the detailed logic of processing this business in the background.At this time, we can actually summarize:

This code obtains the inventory data from the transmitted data, performs the business data assignment through the inventory data, and finally returns the obtained data, and finally successfully obtains the corrected complete inventory data.

Finally:

return string.IsNullOrEmpty(errMsg) ? Success(result) : Fail(errMsg);
Copy the code

Determine whether an error is reported. If no error is reported, the final data is returned. If an error is reported, an error message is returned