Esempio n. 1
0
        public async Task <IActionResult> CreateSpaceType([FromBody] SpaceTypeDTO spaceTypeDTO)
        {
            var spaceTypeToCreate = _mapper.Map <SpaceType>(spaceTypeDTO);

            if (spaceTypeToCreate == null)
            {
                return(BadRequest("SpaceType cannot be null"));
            }
            if (await _lineUpRepository.EntityExists(spaceTypeToCreate))
            {
                return(BadRequest("Space type already exists"));
            }
            _lineUpRepository.Add(spaceTypeToCreate);
            await _lineUpRepository.SaveAllChanges();

            return(Ok());
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateSpaceType(int spaceTypeId, [FromBody] SpaceTypeDTO spaceTypeDTO)
        {
            var spaceType = await _lineUpRepository.GetSpaceType(spaceTypeId);

            var spaceTypeToUpdate = _mapper.Map <SpaceTypeDTO, SpaceType>(spaceTypeDTO, spaceType);

            if (spaceTypeToUpdate == null)
            {
                return(BadRequest("Spacetype cannot be null"));
            }
            if (await _lineUpRepository.EntityExists(spaceTypeToUpdate) == false)
            {
                return(BadRequest("Spacetype does not exist"));
            }
            _lineUpRepository.Update(spaceTypeToUpdate);
            await _lineUpRepository.SaveAllChanges();

            return(Ok());
        }