コード例 #1
0
        public async Task <IActionResult> UpdateBuilding(int id, [FromBody] SaveBuildingResource buildingResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var building = await repository.GetBuilding(id);

            if (building == null)
            {
                return(NotFound());
            }

            mapper.Map <SaveBuildingResource, Building>(buildingResource, building);

            var nameExist = await repository.EditBuildingExist(building);

            if (nameExist != null)
            {
                return(Conflict("Building name already exists"));
            }

            await unitOfWork.CompleteAsync();

            building = await repository.GetBuilding(building.Id);

            var result = mapper.Map <Building, BuildingResource>(building);

            return(Ok(result));
        }