コード例 #1
0
        public async Task <ActionResult <GearDTO> > GetGear(long id)
        {
            var gear = await _repository.GetByIdAsync(id);

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

            return(Gear.GearToDTO(gear));
        }
コード例 #2
0
        public async Task <ActionResult <GearDTO> > CreateGear(GearDTO gearDTO)
        {
            Gear gear = new Gear
            {
                Name        = gearDTO.Name,
                Description = gearDTO.Description,
                Brand       = gearDTO.Brand,
                WeightGrams = gearDTO.WeightGrams,
                LengthMM    = gearDTO.LengthMM,
                WidthMM     = gearDTO.WidthMM,
                DepthMM     = gearDTO.DepthMM,
                Locking     = gearDTO.Locking,
            };

            await _repository.AddAsync(gear);

            return(CreatedAtAction(nameof(GetGear), new { id = gear.Id }, Gear.GearToDTO(gear)));
        }
コード例 #3
0
 public Task <List <GearDTO> > DTOListAsync()
 {
     return(_dbContext.Gear
            .Select(x => Gear.GearToDTO(x))
            .ToListAsync());
 }