Ejemplo n.º 1
0
        /// <summary>
        /// Modify an existing charge and create a new charge category if required
        /// </summary>
        /// <param name="charge">The charge to modify</param>
        /// <param name="existanceChecked">True if existance of charge has been checked</param>
        public void ModifyCharge(Charge charge, bool existanceChecked = false)
        {
            if (charge.IsValid())
            {
                if (!DoesChargeAlreadyExist(charge))
                {
                    using (var tx = new BusinessTransaction())
                    {
                        var chargeCategory = charge.ChargeCategory;

                        // Create a new charge category if it doesn't exist
                        if (chargeCategory.Id == default(int) && chargeCategory.IsValid())
                        {
                            CreateChargeCategory(chargeCategory);
                        }

                        // Reactivate charge if it already exists
                        if (existanceChecked || chargeDao.DoesInactiveChargeExist(charge))
                        {
                            charge.IsActive = true;
                        }

                        chargeDao.Modify(charge);

                        tx.Commit();
                    }

                    // Record business event
                    eventTrackingManager.CreateBusinessEventAsync(charge.ChargeCategory.BusinessId, BusinessEventTypesEnum.ChargeModified, charge.Id.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30105, "SettingsManager.ModifyCharge", 
                        additionalDescriptionParameters: new object[] { charge.ChargeCategory.Name, charge.Name }, 
                        descriptionParameters:  new object[] { charge.ChargeCategory.Name, charge.Name },
                        arguments: new object[] { this }));
                }
            }
        }