Esempio n. 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));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([FromBody] SaveBuildingResource buildingResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            unitOfWork.Buildings.Add(building);
            await unitOfWork.CompleteAsync();

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

            return(Ok(buildingResource));
        }
Esempio n. 3
0
        public async Task <IActionResult> UpdateBuilding(int id, [FromBody] SaveBuildingResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var building = await unitOfWork.Buildings.Get(id);

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

            resource.Id = id;
            mapper.Map <SaveBuildingResource, Building>(resource, building);

            await unitOfWork.CompleteAsync();

            return(Ok(id));
        }