public async Task <IActionResult> Add([FromBody] ClosedWaterSupplyInstallation closedWaterSupplyInstallation) { StateOfTheSystem stateOfTheSystem = new StateOfTheSystem(); stateOfTheSystem.ClosedWaterSupplyInstallation = closedWaterSupplyInstallation; stateOfTheSystem.Temperature = 0f; stateOfTheSystem.OxygenLevel = 0f; stateOfTheSystem.DateOfLastCheck = DateTime.Now; await this.repository.AddAsync <StateOfTheSystem>(stateOfTheSystem); StateOfTheSystem oldStateOfTheSystem = await this.repository.GetAsync <StateOfTheSystem>(true, x => x.ClosedWaterSupplyInstallation == closedWaterSupplyInstallation); int stateOfTheSystemId = oldStateOfTheSystem.StateOfTheSystemId; closedWaterSupplyInstallation.StateOfTheSystemId = stateOfTheSystemId; closedWaterSupplyInstallation.StateOfTheSystem = stateOfTheSystem; await this.repository.AddAsync <ClosedWaterSupplyInstallation>(closedWaterSupplyInstallation); Organization organization = await this.repository.GetAsync <Organization>(true, x => x.OrganizationId == closedWaterSupplyInstallation.OrganizationId); organization.ClosedWaterSupplyInstallations.Add(closedWaterSupplyInstallation); await this.repository.UpdateAsync <Organization>(organization); return(this.Ok()); }
public async Task <IActionResult> Update([FromBody] ClosedWaterSupplyInstallation closedWaterSupplyInstallation) { var currentClosedWaterSupplyInstallation = await this.repository.GetAsync <ClosedWaterSupplyInstallation>(true, x => x.ClosedWaterSupplyInstallationId == closedWaterSupplyInstallation.ClosedWaterSupplyInstallationId); if (currentClosedWaterSupplyInstallation == null) { throw new Exception("ClosedWaterSupplyInstallation not found."); } currentClosedWaterSupplyInstallation.OrganizationId = closedWaterSupplyInstallation.OrganizationId; currentClosedWaterSupplyInstallation.Location = closedWaterSupplyInstallation.Location; await this.repository.UpdateAsync <ClosedWaterSupplyInstallation>(currentClosedWaterSupplyInstallation); return(this.Ok()); }