public async Task InvokeAsync(HttpContext context, ITopicsRepository topicsRepository, IMapper mapper, DefaultEventGridEventHandler eventHandler, IOptions <AwesomeEventGridOptions> options)
        {
            try
            {
                ModelState.Reset();

                using (var reader = new StreamReader(context.Request.Body, Encoding.UTF8))
                {
                    var topicToCreate = JsonConvert.DeserializeObject <TopicModel>(await reader.ReadToEndAsync(), options.Value.SerializerSettings);
                    if (topicToCreate == null)
                    {
                        ModelState.AddError("", "Request body is required");
                    }

                    Validate(topicToCreate);

                    if (!ModelState.IsValid)
                    {
                        await BadRequest(context);

                        return;
                    }

                    if (topicsRepository.FindByName(topicToCreate.Name) != null)
                    {
                        ModelState.AddError("name", "Topic does already exists");
                        await BadRequest(context);

                        return;
                    }

                    var topic = mapper.Map <Topic>(topicToCreate);
                    topic = topicsRepository.Add(topic);

                    var topicModel = mapper.Map <TopicModel>(topic);
                    //todo fix url:
                    await CreatedAt(context, "http://foo", topicModel);
                }
            }
            catch (JsonException ex)
            {
                ModelState.AddError("", ex.Message);
                await BadRequest(context);
            }
        }
        public async Task InvokeAsync(HttpContext context, ISubscriptionsRepository subscriptionsRepository, IMapper mapper, DefaultEventGridEventHandler eventHandler, IOptions <AwesomeEventGridOptions> options)
        {
            ModelState.Reset();
            var routeData    = context.GetRouteData();
            var topic        = (string)routeData.Values["topic"];
            var name         = (string)routeData.Values["name"];
            var subscription = subscriptionsRepository.FindByName(topic, name);

            if (subscription == null)
            {
                ModelState.AddError("name", $"Subscription with this name not found for topic '{topic}'");
                await NotFound(context);

                return;
            }

            var model = mapper.Map <SubscriptionModel>(subscription);

            await Ok(context, model);
        }