public object Post(CreateTopic request)
        {
            IDbTransaction transaction = Db.OpenTransaction();

            try
            {
                CreatingTopic.Create(request);
            }
            catch (TopicAlreadyExistsException)
            {
                return(new HttpError(HttpStatusCode.Conflict, $"Topic {request.Name} already exists"));
            }
            catch (BadRequestException)
            {
                return(new HttpError(HttpStatusCode.BadRequest, "BadRequest"));
            }
            finally
            {
                transaction.Commit();
            }

            return(new HttpResult(new CreateQueueResponse())
            {
                StatusCode = HttpStatusCode.Created,
                Headers =
                {
                    { HttpHeaders.Location, base.Request.AbsoluteUri.CombineWith(request.Name) }
                }
            });
        }
示例#2
0
        public void Create(CreateTopic request)
        {
            var requestToSend = new RestRequest("topics", Method.POST);

            requestToSend.AddParameter("Name", request.Name);

            if (TopicsQueries.TopicExists(DBConnection, request.Name))
            {
                throw new TopicAlreadyExistsException();
            }
            else
            {
                Worker worker, coworker;
                CalculateTopicWorkers(request.Name, out worker, out coworker);
                var topic = TopicsQueries.CreateTopic(DBConnection, request.Name, worker.Id, coworker.Id);

                PropageteRequestToWorkers(requestToSend, topic, worker, coworker);
            }
        }