Post to asp.net web api

  • Replies:0
Mohammad Komaei
  • Forum posts: 1

Apr 17, 2018, 2:06:00 PM via Website

Hi all
I have an asp.net web api:
[Action]
public virtual async Task AddCustomer(Customer customer, CancellationToken cancellation)
{
Customer existingCustomer = (await Repository.GetAllAsync(cancellation)).Where(cu => cu.NationalCode == customer.NationalCode).FirstOrDefault();
if (existingCustomer != null)
throw new Exception("you registered before. please login");

        return await Repository.AddAsync(customer, cancellation);
    }

I could post to this api in react native by this code :
var url = '/Sanaap.Api/odata/Sanaap/Customers/Sanaap.LoginCustomer';
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
FirstName: '',
LastName: '',
NationalCode: this.state.ncode.toString(),
Mobile: this.state.mobile.toString(),
})
}).then((response) => {

        if (response.status == 500) {
            alert('500');
            Toast.show({
                text: "not found",
                position: 'bottom', duration: 5000, type: 'danger'
            });
            return;
        }
        if (response.status == 200) {
            alert('200');
            this.props.navigation.navigate("EvalReq");
        }
    });

what is equal code in android studio instead of fetch for post a customer and get inserted customer id?

Be the first to answer