Пример #1
0
        public bool AssociateProjectSubscription(AssociateProjectSubscriptionEvent associateSubscription)
        {
            var toBeAssociated = GetExistingProjectSubscription(associateSubscription.SubscriptionUID);

            if (toBeAssociated == null)
            {
                throw new Exception("Invalid ProjectSubscriptionUID");
            }

            toBeAssociated.fk_ProjectUID = associateSubscription.ProjectUID;
            toBeAssociated.UpdateUTC     = DateTime.UtcNow;

            var kafkaMessage = new KafkaMessage()
            {
                Key     = associateSubscription.SubscriptionUID.ToString(),
                Message = new { AssociateProjectSubscriptionEvent = associateSubscription }
            };

            var actions = new List <Action>();

            actions.Add(() => transaction.Upsert(toBeAssociated));
            actions.Add(() => topics.ToList().ForEach(topic =>
            {
                kafkaMessage.Topic = topic;
                transaction.Publish(kafkaMessage);
            }));

            return(transaction.Execute(actions));
        }
Пример #2
0
        public ActionResult AssociateProjectSubscription(
            [FromBody] AssociateProjectSubscriptionEvent associateProjectSubscription)
        {
            try
            {
                associateProjectSubscription.EffectiveDate =
                    associateProjectSubscription.EffectiveDate.ToMySqlDateTimeOverflowCorrection();
                associateProjectSubscription.ReceivedUTC = DateTime.UtcNow;

                if (subscriptionService.AssociateProjectSubscription(associateProjectSubscription))
                {
                    return(Ok());
                }

                logger.LogInformation("Unable to save to db. Make sure request is not duplicated and all keys exist");
                return(BadRequest("Unable to save to db. Make sure request is not duplicated and all keys exist"));
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Invalid ProjectSubscriptionUID"))
                {
                    logger.LogInformation("Invalid ProjectSubscriptionUID");
                    return(BadRequest("Invalid ProjectSubscriptionUID"));
                }

                logger.LogError(ex.Message + ex.StackTrace);
                return(StatusCode(500));
            }
        }