예제 #1
0
        public async Task <Space> Create(SpaceCreate data, User user)
        {
            // Check if name is available.
            Space?existing = await repo.FindByName(data.Name);

            if (existing != null)
            {
                throw new SpaceNameAlreadyInUseException($"{data.Name} is unavailable.");
            }

            Space s = factory.Create(data, user);

            await repo.Add(s);

            await bus.Dispatch(new SpaceCreateEvent(s));

            return(s);
        }
예제 #2
0
        protected override async Task <SpaceView> HandleInput(SpaceCreateParams input)
        {
            using (var connection = database.GetConnection()) {
                ISpaceRepo spaceRepo = database.GetRepo <ISpaceRepo>(connection);
                Space?     existing  = await spaceRepo.FindByName(input.Name);

                if (existing != null)
                {
                    throw new InvalidOperationException($"Space name {input.Name} is already taken.");
                }

                Space s = new Space()
                {
                    Name         = input.Name,
                    Description  = input.Description,
                    User         = input.User,
                    CreationDate = DateTime.UtcNow
                };

                await spaceRepo.Add(s);

                return(spaceMapper.Map(s));
            }
        }