public async Task <IActionResult> UpdateRackGear(long rackId, long gearId, RackGear putRackGear) { if (rackId != putRackGear.RackId || gearId != putRackGear.GearId) { return(BadRequest()); } var gear = await _repository.GetRackGearByIdsAsync(rackId, gearId); if (gear == null) { return(NotFound()); } gear.Quantity = putRackGear.Quantity; try { await _repository.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!RackExists(rackId)) { return(NotFound()); } return(NoContent()); }
public async Task <ActionResult <RackGearDTO> > CreateRackGear(RackGear rackGear) { if (!RackExists(rackGear.RackId)) { return(NotFound()); } await _repository.AddRackGearAsync(rackGear); return(NoContent()); }
private RackGearDTO RackGearToRackGearDTO(RackGear rackGear) { var rackGearDto = new RackGearDTO { RackId = rackGear.RackId, GearId = rackGear.GearId, Name = rackGear.Gear.Name, Quantity = rackGear.Quantity, Description = rackGear.Gear.Description, Brand = rackGear.Gear.Brand, WeightGrams = rackGear.Gear.WeightGrams, LengthMM = rackGear.Gear.LengthMM, WidthMM = rackGear.Gear.WidthMM, DepthMM = rackGear.Gear.DepthMM, Locking = rackGear.Gear.Locking }; return(rackGearDto); }
public Task DeleteRackGearAsync(RackGear rackGear) { _dbContext.RackGear.Remove(rackGear); return(_dbContext.SaveChangesAsync()); }
public Task AddRackGearAsync(RackGear rackGear) { _dbContext.RackGear.Add(rackGear); return(_dbContext.SaveChangesAsync()); }