コード例 #1
0
        public async Task <ActionResult <Makerspace> > CreateMakerspace(
            [FromBody] SaveMakerspaceResource saveMakerspaceResource)
        {
            //TODO: Add validation code

            var makerspaceToCreate = _mapper.Map <SaveMakerspaceResource, Makerspace>(saveMakerspaceResource);
            var newMakerspace      = await _makerspaceService.CreateMakerspace(makerspaceToCreate);

            var makerspace = await _makerspaceService.GetMakerspaceWithOwnerById(newMakerspace.Id);

            var makerspaceResource = _mapper.Map <Makerspace, MakerspaceResource>(makerspace);

            return(Ok(makerspaceResource));
        }
コード例 #2
0
        public async Task <ActionResult <Makerspace> > UpdateMakerspace(int id,
                                                                        [FromBody] SaveMakerspaceResource saveMakerspaceResource)
        {
            //TODO: Add validation code

            var makerspaceToBeUpdated = await _makerspaceService.GetMakerspaceWithOwnerById(id);

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

            var makerspace = _mapper.Map <SaveMakerspaceResource, Makerspace>(saveMakerspaceResource);

            await _makerspaceService.UpdateMakerspace(makerspaceToBeUpdated, makerspace);

            var updatedMakerspace = await _makerspaceService.GetMakerspaceWithOwnerById(id);

            var updatedMakerspaceResource = _mapper.Map <Makerspace, SaveMakerspaceResource>(updatedMakerspace);

            return(Ok(updatedMakerspaceResource));
        }