Can any one please explain this lines of code?
bool status = datacontext.tblTransactionDetails.Where(x => x.AdvertID == app.AdvertID && x.IsActive == true).FirstOrDefault() == null ? false : true;
Can any one please explain this lines of code?
bool status = datacontext.tblTransactionDetails.Where(x => x.AdvertID == app.AdvertID && x.IsActive == true).FirstOrDefault() == null ? false : true;
It means take the first item from the collection where AdvertID == app.AdvertID && IsActive == true. If it's null return false, otherwise return true.
The ? : syntax is known as the ternary operator and is used as a shorthand for if/else.
Instead you could use
.Any(x => x.AdvertID == app.AdvertID && x.IsActive == true)
this returns true if any meet the conditions, otherwise false.
The full line of code would be:
bool status = datacontext.tblTransactionDetails.Any(x => x.AdvertID == app.AdvertID && x.IsActive == true);