public async Task <IActionResult> Put([FromBody] EcologicalMeasurementDTO dto) { if (dto == null) { return(BadRequest("Measurement information formatted incorrectly.")); } var ecologicalMeasurement = new EcologicalMeasurement { Date_taken = dto.Date_taken, EcologicalFootprint = dto.EcologicalFootprint, Transport = dto.Transport, Diet = dto.Diet, Electronics = dto.Electronics, Clothing = dto.Clothing, Footwear = dto.Footwear }; var result = await _userRepository.UpdateEcologicalMeasurement(dto.UserId, ecologicalMeasurement); if (result == 1) { return(Ok()); } else if (result == -8) { // return HTTP 404 as ecologicalMeasure with date cannot be found in DB return(NotFound("User with ID '" + dto.UserId + "' does not have ecological measure on " + dto.Date_taken)); } else { // return HTTP 404 as user cannot be found in DB return(NotFound("User with ID '" + dto.UserId + "' does not exist.")); } }
public async Task <IActionResult> Post([FromBody] EcologicalMeasurementDTO dto) { if (dto == null) { return(BadRequest("Measurement information formatted incorrectly.")); } var ecologicalMeasurement = new EcologicalMeasurement { Date_taken = dto.Date_taken, EcologicalFootprint = dto.EcologicalFootprint, Transport = dto.Transport, Diet = dto.Diet, Electronics = dto.Electronics, Clothing = dto.Clothing, Footwear = dto.Footwear }; int result = await _userRepository.AddEcologicalMeasurement(dto.UserId, ecologicalMeasurement); if (result == 1) { /*** HERE MIGHT CAL Collective_EF ***/ // return HTTP 201 Created with user object in body of return and a 'location' header with URL of newly created object return(CreatedAtAction("Get", new { id = dto.UserId, date = dto.Date_taken }, ecologicalMeasurement)); } else if (result == -7) { // return HTTP 409 as ecologicalMeasure with date already exists - conflict return(Conflict("User with ID '" + dto.UserId + "' already has an ecological measure on " + dto.Date_taken)); } else if (result == -9) { // return HTTP 404 as user cannot be found in DB return(NotFound("User with ID '" + dto.UserId + "' does not exist.")); } else { return(BadRequest("An internal error occurred. Please contact the system administrator.")); } }