public async Task <ActionResult <EquipmentForReturnDto> > CreateNewEquipmentAsync([FromBody] EquipmentForCreationDto equipmentCreationDto) { var equipment = mapper.Map <Equipment>(equipmentCreationDto); equipmentRepository.Add(equipment); var saveResults = await equipmentRepository.SaveAllAsync(); if (!saveResults) { return(BadRequest(new ProblemDetailsWithErrors("Failed to create the equipment.", 400, Request))); } var eqReturn = mapper.Map <EquipmentForReturnDto>(equipment); return(CreatedAtRoute("GetSingleEquipment", new { id = equipment.Id }, eqReturn)); }
public async Task <ActionResult <EquipmentForReturnDto> > PutEquipmentAsync(int id, [FromBody] EquipmentForCreationDto dto) { var equipment = await equipmentRepository.GetByIdAsync(id); if (equipment == null) { return(NotFound()); } this.mapper.Map(dto, equipment); var saveResult = await equipmentRepository.SaveAllAsync(); if (!saveResult) { return(BadRequest("Could not apply changes.")); } var equipmentToReturn = mapper.Map <EquipmentForReturnDto>(equipment); return(Ok(equipmentToReturn)); }