Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
public async Task<Member> AddMember(Member member)
        {
            var model = new Member();

            try
            {
                var retval = await _flurlClient.Request(Constants.AddMember)
                                               .PostJsonAsync(new Member()
                                               {
                                                   MemberId = member.MemberId,
                                                   SrNo = member.SrNo,
                                                   SeatNo = member.SeatNo,
                                                   Name = member.Name,
                                                   Gender = member.Gender,
                                                   FatherName = member.FatherName,
                                                   MotherName = member.MotherName,
                                                   HighestQualification = member.HighestQualification,
                                                   PreparingFor = member.PreparingFor,
                                                   PreferredBookName = member.PreferredBookName,
                                                   PermanentAddress = new Address()
                                                   {
                                                       Id = member.PermanentAddress.Id,
                                                       Village_Mohalla = member.PermanentAddress.Village_Mohalla,
                                                       PoliceStation = member.PermanentAddress.PoliceStation,
                                                       PostOffice = member.PermanentAddress.PostOffice,
                                                       District = member.PermanentAddress.District,
                                                       PinCode = member.PermanentAddress.PinCode,
                                                       AddressType = member.PermanentAddress.AddressType,
                                                       Description = member.PermanentAddress.Description,
                                                       IsActive = true
                                                   },
                                                   LocalAddress = new Address()
                                                   {
                                                       Id = member.LocalAddress.Id,
                                                       Village_Mohalla = member.LocalAddress.Village_Mohalla,
                                                       PoliceStation = member.LocalAddress.PoliceStation,
                                                       PostOffice = member.LocalAddress.PostOffice,
                                                       District = member.LocalAddress.District,
                                                       PinCode = member.LocalAddress.PinCode,
                                                       AddressType = member.LocalAddress.AddressType,
                                                       Description = member.LocalAddress.Description,
                                                       IsActive = true
                                                   },
                                                   FatherMobileNo = member.FatherMobileNo,
                                                   MobileNo = member.MobileNo,
                                                   FormPath = member.FormPath,
                                                   DocumentPath = member.DocumentPath,
                                                   ExitDate = member.ExitDate,
                                                   IsActive = true,
                                                   CreatedBy = 0
                                               });
            }
            catch (FlurlHttpException ex)
            {
                var error = await ex.GetResponseJsonAsync();
                //logger.Write($"Error returned from {ex.Call.Request.Url}: {error.SomeDetails}");
            }
            return member;
        }


What I have tried:

var retval = await _flurlClient.Request(Constants.AddMember)
                                               .PostJsonAsync(objMember)


In postman same api is working fine with below request

{
  "memberId": 0,
  "srNo": 0,
  "seatNo": 0,
  "name": "string",
  "gender": 0,
  "fatherName": "string",
  "motherName": "string",
  "highestQualification": "string",
  "preparingFor": "string",
  "preferredBookName": "string",
  "permanentAddress": {
    "addressId": 0,
    "village_Mohalla": "string",
    "policeStation": "string",
    "postOffice": "string",
    "district": "string",
    "pinCode": 0,
    "addressType": 0,
    "description": "string",
    "isActive": 0
  },
  "localAddress": {
    "addressId": 0,
    "village_Mohalla": "string",
    "policeStation": "string",
    "postOffice": "string",
    "district": "string",
    "pinCode": 0,
    "addressType": 0,
    "description": "string",
    "isActive": 0
  },
  "fatherMobileNo": "string",
  "mobileNo": "string",
  "formPath": "string",
  "documentPath": "string",
  "exitDate": "string",
  "isActive": 0,
  "createdBy": 0
}
Posted
Updated 20-Jan-23 13:13pm

1 solution

Not familiar with that library.

When working with REST endpoints, you need to use debugging tools to view what is going on. My favorite is Fiddler[^]. You can capture the data and see exactly what is happening.

Capture the Postman post, then your post, and compare. You will see what the differences are and adjust your code accordingly.
 
Share this answer
 
Comments
itsathere 21-Jan-23 12:09pm    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900