Exemple #1
0
        public bool UpdateCustomerSubscription(UpdateCustomerSubscriptionEvent updateSubscription)
        {
            var dbCustomer = GetExistingCustomerSubscription(updateSubscription.SubscriptionUID.Value);

            if (dbCustomer == null)
            {
                throw new Exception("Customer Subscription not exists!");
            }

            if (!updateSubscription.StartDate.HasValue && !updateSubscription.EndDate.HasValue)
            {
                throw new Exception("Update Customer Subscription Request should have atleast one field to update");
            }

            if (!FieldHelper.IsValidValuesFilled(updateSubscription, dbCustomer, logger))
            {
                logger.LogError("Second Parameter expects typeOf IDbTable");
            }

            dbCustomer.UpdateUTC = DateTime.UtcNow;

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

            var actions = new List <Action>();

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

            return(transaction.Execute(actions));
        }
Exemple #2
0
        public ActionResult UpdateCustomerSubscription([FromBody] UpdateCustomerSubscriptionEvent customerSubscription)
        {
            try
            {
                customerSubscription.StartDate   = customerSubscription.StartDate.ToMySqlDateTimeOverflowCorrection();
                customerSubscription.EndDate     = customerSubscription.EndDate.ToMySqlDateTimeOverflowCorrection();
                customerSubscription.ReceivedUTC = DateTime.UtcNow;

                if (subscriptionService.UpdateCustomerSubscription(customerSubscription))
                {
                    return(Ok());
                }

                logger.LogInformation(
                    "SubscriptionUID not Found in Db.Make Sure Create Subscription request comes before Update Subscription");
                return(BadRequest(
                           "SubscriptionUID not Found in Db.Make Sure Create Subscription request comes before Update Subscription"));
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Customer Subscription not exists!"))
                {
                    logger.LogInformation("Customer Subscription not exists!");
                    return(BadRequest("Customer Subscription not exists!"));
                }

                if (ex.Message.Contains("Update Customer Subscription Request should have atleast one field to update"))
                {
                    logger.LogInformation(
                        "Update Customer Subscription Request should have atleast one field to update");
                    return(BadRequest("Update Customer Subscription Request should have atleast one field to update"));
                }

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