public async Task <IActionResult> PutEquipment([FromRoute] Guid id, [FromBody] VmEquipment vmEquipment, CancellationToken cancellationToken) { if (id != vmEquipment.Id) { return(BadRequest()); } var equipmentView = _mapper.Map <EquipmentView>(vmEquipment); await _equipmentService.UpdateEquipmentAsync(equipmentView, cancellationToken); try { await _equipmentService.CommitAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { if (!await EquipmentExists(id, cancellationToken)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <VmEquipment> > PostEquipment([FromBody] VmEquipment vmEquipment, CancellationToken cancellationToken) { var equipmentView = _mapper.Map <EquipmentView>(vmEquipment); var dbEquipment = await _equipmentService.AddEquipmentAsync(equipmentView, cancellationToken); await _equipmentService.CommitAsync(cancellationToken); vmEquipment.Id = dbEquipment.Id; return(CreatedAtAction("GetEquipment", new { id = dbEquipment.Id }, vmEquipment)); }