public bool UpdateProjectSubscription(UpdateProjectSubscriptionEvent updateSubscription) { var dbProject = GetExistingProjectSubscription(updateSubscription.SubscriptionUID.Value); if (dbProject == null) { throw new Exception("Project Subscription not exists!"); } if (string.IsNullOrEmpty(updateSubscription.SubscriptionType) && !updateSubscription.CustomerUID.HasValue && !updateSubscription.StartDate.HasValue && !updateSubscription.EndDate.HasValue) { throw new Exception("Update Project Subscription Request should have atleast one field to update"); } if (string.IsNullOrEmpty(updateSubscription.SubscriptionType)) { updateSubscription.SubscriptionType = _projectSubscriptionTypeCache .FirstOrDefault(x => x.Value == dbProject.fk_ServiceTypeID).Key; } else if (_projectSubscriptionTypeCache.ContainsKey(updateSubscription.SubscriptionType)) { dbProject.fk_ServiceTypeID = _projectSubscriptionTypeCache[updateSubscription.SubscriptionType]; } else { throw new Exception("Invalid Project Subscription Type"); } if (!FieldHelper.IsValidValuesFilled(updateSubscription, dbProject, logger)) { logger.LogError("Second Parameter expects typeOf IDbTable"); } dbProject.UpdateUTC = DateTime.UtcNow; var kafkaMessage = new KafkaMessage() { Key = updateSubscription.SubscriptionUID.ToString(), Message = new { UpdateProjectSubscriptionEvent = updateSubscription } }; var actions = new List <Action>(); actions.Add(() => transaction.Upsert(dbProject)); actions.Add(() => topics.ToList().ForEach(topic => { kafkaMessage.Topic = topic; transaction.Publish(kafkaMessage); })); return(transaction.Execute(actions)); }
public ActionResult UpdateProjectSubscription([FromBody] UpdateProjectSubscriptionEvent projectSubscription) { try { projectSubscription.StartDate = projectSubscription.StartDate.ToMySqlDateTimeOverflowCorrection(); projectSubscription.EndDate = projectSubscription.EndDate.ToMySqlDateTimeOverflowCorrection(); projectSubscription.ReceivedUTC = DateTime.UtcNow; if (subscriptionService.UpdateProjectSubscription(projectSubscription)) { 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("Project Subscription not exists!")) { logger.LogInformation("Project Subscription not exists!"); return(BadRequest("Project Subscription not exists!")); } if (ex.Message.Contains("Invalid Project Subscription Type")) { logger.LogInformation("Invalid Project Subscription Type"); return(BadRequest("Invalid Project Subscription Type")); } if (ex.Message.Contains("Update Project Subscription Request should have atleast one field to update")) { logger.LogInformation( "Update Project Subscription Request should have atleast one field to update"); return(BadRequest("Update Project Subscription Request should have atleast one field to update")); } logger.LogError(ex.Message + ex.StackTrace); return(StatusCode(500)); } }