How check value of List item in IF statement

  • Thread starter Thread starter zleug
  • Start date Start date
Z

zleug

Guest
Hi All.

I'm in C#. I have Address class

public class AddressDt
{
[DataMember]
public string Address1 { get; set; }
[DataMember]
public string Address2 { get; set; }
[DataMember]
public string City { get; set; }
[DataMember]
public string State { get; set; }
[DataMember]
public int Zip { get; set; }
}


and API controller

public class DemographicController : ApiController
{
[HttpPost]
public IHttpActionResult Test1(Demographic somevalue)
{
if (string.IsNullOrEmpty(somevalue.Address.Address1) || string.IsNullOrEmpty(somevalue.Address.City) || string.IsNullOrEmpty(somevalue.Address.State) || somevalue.Address.Zip <= 0)
{
throw new ArgumentNullException("The Address is not completed");
}

HttpResponseMessage responseMessage = Request.CreateResponse(somevalue);
return new ResponseMessageResult(responseMessage);
}

public class Demographic
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
public string OtherName { get; set; }
public DateTime DOB { get; set; }
public string Gender { get; set; }
public string EyeColor { get; set; }
public int HeightInches { get; set; }
public string PreferredLanguage { get; set; }
public string SecondLanguag { get; set; }
public List<AddressDt> Address { get; set; }
}
}


How to fix code in IF statement?

Thanks

Continue reading...
 
Back
Top