Ejemplo n.º 1
0
        private List <HorseDto> ExtractHorsesData(Meeting meeting)
        {
            List <HorseDto> HorseList = new List <HorseDto>();

            try
            {
                foreach (var horseXML in meeting.Races.Race.Horses.Horse)
                {
                    HorseDto horse = new HorseDto();
                    horse.Id   = horseXML.Number;
                    horse.Name = horseXML.Name;
                    foreach (var horseXMLPrice in meeting.Races.Race.Prices.Price.Horses.Horse)
                    {
                        if (horseXMLPrice._Number == horse.Id)
                        {
                            horse.Price = Convert.ToDouble(horseXMLPrice.Price);
                            HorseList.Add(horse);
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error while parsing XML file: " + e.Message);
            }
            return(HorseList);
        }
        public async Task <ActionResult <Horse> > AddHorseAsync([FromForm] HorseDto horseDto)
        {
            var horse = _mapper.Map <Horse>(horseDto);

            _context.Horses.Add(horse);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       "GetHorses",
                       null,
                       _mapper.Map <HorseDto>(horse)
                       ));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateHorse(HorseDto horseDto)
        {
            if (horseDto.Name == null || horseDto.OwnerID <= 0)
            {
                return(BadRequest());
            }

            var horse = new Horse
            {
                Name    = horseDto.Name,
                BoxID   = horseDto.BoxID,
                OwnerID = horseDto.OwnerID
            };

            await _context.Horses.AddAsync(horse);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetHorse), new { id = horse.ID }, horse));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateHorse(int id, HorseDto horseDto)
        {
            if (horseDto.Name == null || horseDto.OwnerID <= 0)
            {
                return(BadRequest());
            }

            var horse = await _context.Horses
                        .FindAsync(id);

            if (horse == null)
            {
                return(NotFound());
            }

            horse.Name    = horseDto.Name;
            horse.BoxID   = horseDto.BoxID;
            horse.OwnerID = horseDto.OwnerID;

            await _context.SaveChangesAsync();

            return(Ok());
        }
Ejemplo n.º 5
0
        private static HorseDto HorseToDto(Horse horse)
        {
            var ret = new HorseDto
            {
                ID            = horse.ID,
                BoxID         = horse.BoxID,
                OwnerID       = horse.OwnerID,
                OwnerFullName = new string(horse.Owner.Name + " " + horse.Owner.Surname),
                Name          = horse.Name,
                MedicEntryIDs = new List <int>()
            };

            if (horse.MedicEntries == null)
            {
                return(ret);
            }
            foreach (var me in horse.MedicEntries)
            {
                ret.MedicEntryIDs.Add(me.ID);
            }

            return(ret);
        }
Ejemplo n.º 6
0
        private List <HorseDto> ExtractHorsesData(RootObject JsonRace)
        {
            List <HorseDto> ParticipantsList = new List <HorseDto>();

            try
            {
                foreach (var market in JsonRace.RawData.Markets)
                {
                    foreach (var selection in market.Selections)
                    {
                        HorseDto participant = new HorseDto(selection.Tags.participant, selection.Tags.name,
                                                            selection.Price);
                        ParticipantsList.Add(participant);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error while parsing JSON file: " + e.Message);
            }

            return(ParticipantsList);
        }