Пример #1
0
        public async Task <IActionResult> CreateRoomService(RoomServiceForCreationDto roomServiceForCreationDto)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (currentUserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var roomServiceToCreate = _mapper.Map <RoomService>(roomServiceForCreationDto);

            _repo.Add(roomServiceToCreate);

            if (await _repo.SaveAll())
            {
                var roomServiceToReturn = _mapper.Map <RoomServiceToReturnDto>(roomServiceToCreate);
                return(CreatedAtRoute("GetRoomService", new { id = roomServiceToCreate.Id }, roomServiceToReturn));
            }
            throw new Exception("Creating the Room Service failed on save");
        }