How i will return status code & message depend on condition in API?
[HttpGet("{id:int}")]
public ActionResult <VillaDTO> GetVilla(int id)
{
if (id == 0) {
return BadRequest(); //return 400
}
var villa = VillaStore.villasList.FirstOrDefault(u => u.Id == id);
if (villa == null) {
return NotFound(); //return 404 not found
}
return Ok(villa); //return 200 success
}
Here when user try to get data entering id. If user enter id zero(0) then it’s called BadRequest which return 400. If user enter any id which is not exist in list then user will get 404 code which means data not found. If data exist then user will get 200 code with success message.

Excellent post. I absolutely appreciate this website. Continue the good work!
Pingback: RUAY เว็บหวยออนไลน์
Pingback: helen88
Pingback: รักษาสิว
Pingback: โบท็อกราคา
You’ve written terrific content on this topic, which goes to show how knowledgable you are on this subject. I happen to cover about Cosmetic Treatment on my personal blog QH8 and would appreciate some feedback. Thank you and keep posting good stuff!
Pingback: dark168
Pingback: funny videos
Pingback: nova8899 พนันออนไลน์ เว็บตรง
Pingback: ft lauderdale boat rental
Pingback: โรงงานผลิตสายรัดพลาสติก
Pingback: รถรับส่งสนามบินในญี่ปุ่น
Pingback: Jaxx Liberty
Pingback: som777
Pingback: slot true wallet
Pingback: ผลิตเสื้อยืด
Pingback: ขอขึ้นทะเบียน อย
Pingback: hop over to this site
Pingback: pgslot
Pingback: SHOPEE สล็อต
Pingback: disposable thc vape carts near me
Pingback: Massage
Pingback: lost mary vapes near me
HjI8enGnjKUKisIR http://www.yandex.ru
Pingback: เค้กด่วน
Pingback: fox888
Pingback: slot99
Pingback: lazywin888
Pingback: best cams
Pingback: สกรีนแก้ว
Pingback: ทัวร์ยุโรป
Pingback: xbet99 เว็บพนันครบวงจร
Pingback: Al Yarmouk University College
Pingback: 789bet
Pingback: KC9 คาสิโนออนไลน์ อันดับ 1
Pingback: Diaphragm Husky
Pingback: https://salud10medellin.com/2025/03/02/pocket-option-traders-strategies-and-insights/
Pingback: y2k168
Pingback: ยาตราใบห่อ
Pingback: check here
Pingback: ufabet777
Pingback: mmabet
Pingback: Law firm Facebook ads
Pingback: นำเข้าสินค้าจากจีน