How to check data stored in c # class

I have the following class in a C # ASMX web service, and not in MVC or web forms.

public class Hotel { public int HotelId {get;set;} public string Name {get;set;} public Room[] Room { get; set; } [Range(0, 12, ErrorMessage = "Rating must be between 1 and 5")] public int Rating {get;set:} } public class Room { [Required] public int RoomId {get;set;} [Required] [StringLength(175)] public string Name {get; set;} } 

Using System.ComponentModel.DataAnnotations, so how can I proceed as above? If so, how do I get a response from a validation error?

Also, when the service starts, I read in the Json data object, as shown below.

  oHotelRequest = JsonConvert.DeserializeObject<Hotel>(sJson); HotelResponse oHotelResponse = BookingAPI.Hotel.Get(oHotelRequest); return JsonConvert.SerializeObject(oHotelResponse); 

Or can I do validation when de-serializing an object?

+4
source share

Source: https://habr.com/ru/post/1494039/


All Articles