public async Task <IActionResult> Add(Measurement measurement) { if (measurement == null) { return(BadRequest("The measurement is null")); } await _measurementRepository.Add(measurement); return(CreatedAtAction(nameof(Get), new { id = measurement.Id }, measurement)); }
public async Task <IActionResult> Post([FromBody] Measurement measurment) { if (measurment == null) { return(BadRequest("Measrument is null")); } await _measurmentRepository.Add(measurment); return(CreatedAtAction(nameof(Post), new { id = measurment.Id, measurment })); }
public void createMeasurement(MeasurementModel measurement) { try { mrepo.Add(measurement); mrepo.Save(); log.Info("Measurement von RestService wurde gespeichert."); } catch (BLException exp) { log.Error("Measurement von RestService konnte nicht gespeichert werden."); throw new BLException("Measurement von RestService konnte nicht gespeichert werden.", exp); } }
public async Task <IActionResult> Post(int aquariumId, [FromBody] MeasurementModel model) { try { var measurement = _mapper.Map <Measurement>(model); if (measurement == null) { return(UnprocessableEntity()); } // User URL values over model values measurement.UserId = UserId; measurement.AquariumId = aquariumId; // Measurement Type measurement.MeasurementType = _measurementManager.LookupFromName(measurement.MeasurementType); var results = _validationManager.Validate(measurement); if (results.Count != 0) { return(UnprocessableEntity(results)); } // Lookup unit measurement.Unit = await _unitManager.LookUpByName(measurement.Unit); await _repository.Add(measurement); AddETag(measurement.RowVersion); var url = Url.Link("MeasurementGet", new { UserId, aquariumId, ((Measurement)measurement).Id }); return(Created(url, _mapper.Map <MeasurementModel>(measurement))); } catch (Exception ex) { _logger.Error(ex, "An error occured whilst trying to create Measurement."); } return(BadRequest("Could not create Measurement")); }
public IHttpActionResult Add(MeasurementModel measureModel) { if (measureModel == null) { var errorMessage = _messages.GetMessage(Generic.NullObject); return(BadRequest(errorMessage)); } if (_measureRep.GetAll().Any(m => m.UnitOfMeasure == measureModel.UnitOfMeasure)) { var errorMessage = _messages.GetMessage(Custom.Conflict, "Measurement", "Unit Of Measure"); return(Conflict(errorMessage)); } var newMeasure = _mapper.Map <Measurement>(measureModel); _measureRep.Add(newMeasure); var createdMeasure = _mapper.Map <MeasurementModelGet>(newMeasure); return(CreatedAtRoute("GetMeasurement", new { id = newMeasure.Id }, createdMeasure)); }
public async Task Add(MeasurementDto entity, UserDto userDto) { await _iMeasurementRepository.Add(MeasurementMapper.DtoMeasurementMapper(entity, userDto)); }