Esempio n. 1
0
        public async Task <ActionResult <StartDto[]> > Update([FromBody] StartDto start)
        {
            if (start == null)
            {
                return(BadRequest("Start not set"));
            }
            var entity = await dataContext.Starts.FindAsync(start.Id);

            if (entity == null)
            {
                return(NotFound());
            }
            var raceId = entity.RaceId;

            start.UpdateEntity(entity, dataContext);
            dataContext.Starts.Update(entity);
            await dataContext.SaveChangesAsync();

            return(await Get(raceId));
        }
Esempio n. 2
0
        public async Task <ActionResult <StartDto[]> > Add(int id, [FromBody] StartDto start)
        {
            if (start == null)
            {
                return(BadRequest("Start not posted"));
            }
            var race = await dataContext.Races.FindAsync(id);

            if (race == null)
            {
                return(NotFound());
            }
            var entity = start.UpdateEntity(
                new Start {
                Race = race, RaceId = race.Id
            }, dataContext
                );

            dataContext.Starts.Add(entity);
            await dataContext.SaveChangesAsync();

            return(await Get(id));
        }