Exemplo n.º 1
0
        public IActionResult GetHorsesByBreed(string HorseBreed)
        {
            var model = IHorseService.GetHorsesByBreed(HorseBreed);
            List <HorseResultJson> res = new List <HorseResultJson>();

            foreach (var itm in model)
            {
                res.Add(new HorseResultJson
                {
                    BirthDay = itm.DateOfBirth.ToString(),
                    Breed    = itm.HorseBreed.ToString(),
                    Breeder  = itm.HorseBreeder.ToString(),
                    Name     = itm.HorseName.ToString()
                });
            }

            JsonSerializerSettings jsSettings = new JsonSerializerSettings();

            jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            var converted = JsonConvert.SerializeObject(res, null, jsSettings);

            return(Content(converted, "application/json"));
        }