Exemplo n.º 1
0
        public async Task <ActionResult <RaceCategoryDto> > Update([FromBody] RaceCategoryDto category)
        {
            if (category == null)
            {
                return(BadRequest("Category not set"));
            }
            var entity = await dataContext.RaceCategories.FindAsync(category.Id);

            if (entity == null)
            {
                return(NotFound());
            }
            category.UpdateEntity(entity);
            dataContext.RaceCategories.Update(entity);
            await dataContext.SaveChangesAsync();

            return(Ok(new RaceCategoryDto(entity)));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <int> > Add(int id, [FromBody] RaceCategoryDto category)
        {
            var race = await dataContext.Races.FindAsync(id);

            if (race == null)
            {
                return(NotFound());
            }
            if (category == null)
            {
                return(BadRequest("Category not posted"));
            }
            var entity = category.UpdateEntity(new RaceCategory());

            entity.Race = race;
            dataContext.RaceCategories.Add(entity);
            await dataContext.SaveChangesAsync();

            return(Ok(entity.Id));
        }