Beispiel #1
0
            public void DoesInactiveChargeExistReturnsTrueWhenChargeExists()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";
                const string CHARGE_NAME = "Whiskey";
                const long BUSINESS_ID = 501;

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateChargeTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    Charge chargeToSetAsInactive = chargeDao.GetChargesByBusinessId(BUSINESS_ID, CULTURE_CODE).FirstOrDefault(x => x.Name == CHARGE_NAME);
                    chargeToSetAsInactive.IsActive = false;

                    chargeDao.Modify(chargeToSetAsInactive);

                    var charge = new Charge
                    {
                        Name = CHARGE_NAME,
                        ChargeCategory = new ChargeCategory { Id = chargeToSetAsInactive.ChargeCategory.Id },
                        ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                        ChargeCostType = new ChargeCostType { Type = ChargeCostTypeEnum.Variable }
                    };

                    // Act
                    bool result = chargeDao.DoesInactiveChargeExist(charge);

                    // Assert
                    Assert.IsTrue(result, "Inactive charge should exist.");
                    Assert.AreEqual(chargeToSetAsInactive.Id, charge.Id, "Charge id was not set.");
                }
            }
Beispiel #2
0
            public void CreateInvalidChargeThrowsException()
            {
                // Arrange
                const int INVALID_CHARGE_CATEGORY_ID = 0;

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateChargeTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var charge = new Charge
                    {
                        Name = "Rum",
                        ChargeCategory = new ChargeCategory { Id = INVALID_CHARGE_CATEGORY_ID },
                        ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                        ChargeCostType = new ChargeCostType { Type = ChargeCostTypeEnum.Variable }
                    };

                    // Act
                    chargeDao.Create(charge);
                }
            }
Beispiel #3
0
            public void CreateExistingChargeThrowsException()
            {
                // Arrange
                const long BUSINESS_ID = 501;

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateChargeTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var chargeCategoryId = chargeCategoryDao.GetChargeCategoriesByBusinessId(BUSINESS_ID).FirstOrDefault(x => x.Name == "Bar").Id;
                    
                    var charge = new Charge
                    {
                        Name = "Whiskey",
                        ChargeCategory = new ChargeCategory { Id = chargeCategoryId },
                        ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                        ChargeCostType = new ChargeCostType { Type = ChargeCostTypeEnum.Variable }
                    };

                    // Act
                    chargeDao.Create(charge);
                }
            }
Beispiel #4
0
            public void InsertIsSuccessful()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";
                const long BUSINESS_ID = 501;
                const string CHARGE_NAME = "testchargename";

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateChargeTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var chargeCategoryId = chargeCategoryDao.GetChargeCategoriesByBusinessId(BUSINESS_ID).FirstOrDefault(x => x.Name == "Bar").Id;

                    var charge = new Charge
                    {
                        Name = CHARGE_NAME,
                        ChargeCategory = new ChargeCategory { Id = chargeCategoryId },
                        ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                        ChargeCostType = new ChargeCostType { Type = ChargeCostTypeEnum.Variable },
                        ChargePriceType = new ChargePriceType { Type = ChargePriceTypeEnum.Value },
                        ChargeRulesType = new ChargeRulesType { Type = ChargeRulesTypeEnum.EntireBill },
                        ChargeClassType = new ChargeClassType { Type = ChargeClassTypeEnum.Specials },
                        IsActive = true
                    };

                    // Act
                    chargeDao.Upsert(charge);

                    // Assert
                    Charge addedCharge = chargeDao.GetChargesByBusiness(BUSINESS_ID, CULTURE_CODE).FirstOrDefault(x => x.Name == CHARGE_NAME);

                    Assert.IsNotNull(addedCharge, "Charge was not added");
                    Assert.AreEqual(charge.Name, addedCharge.Name, "Name was not added correctly.");
                    Assert.AreEqual(charge.ChargeCategory.Id, addedCharge.ChargeCategory.Id, "Charge Category was not added correctly.");
                    Assert.AreEqual(charge.ChargeType.Type, addedCharge.ChargeType.Type, "Charge Type was not added correctly.");
                    Assert.AreEqual(charge.ChargeCostType.Type, addedCharge.ChargeCostType.Type, "Charge Cost Type was not added correctly.");
                    Assert.AreEqual(charge.ChargePriceType.Type, addedCharge.ChargePriceType.Type, "Charge Cost Type was not added correctly.");
                    Assert.AreEqual(charge.ChargeRulesType.Type, addedCharge.ChargeRulesType.Type, "Charge Cost Type was not added correctly.");
                }
            }
Beispiel #5
0
            public void CreateIsSuccessful()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";
                const long BUSINESS_ID = 501;

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateChargeTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var chargeCategoryId = chargeCategoryDao.GetChargeCategoriesByBusinessId(BUSINESS_ID).FirstOrDefault(x => x.Name == "Bar").Id;

                    var charge = new Charge
                        {
                            Name = "Rum",
                            ChargeCategory = new ChargeCategory { Id = chargeCategoryId },
                            ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                            ChargeCostType = new ChargeCostType { Type = ChargeCostTypeEnum.Variable },
                            IsActive = true
                        };

                    // Act
                    chargeDao.Create(charge);

                    // Assert
                    Charge addedCharge = chargeDao.GetChargesByBusinessId(BUSINESS_ID, CULTURE_CODE).FirstOrDefault(x => x.Id == charge.Id);

                    Assert.IsNotNull(addedCharge, "Charge was not added");
                    Assert.AreEqual(charge.Name, addedCharge.Name, "Name was not added correctly.");
                    Assert.AreEqual(charge.ChargeCategory.Id, addedCharge.ChargeCategory.Id, "Charge Category was not added correctly.");
                    Assert.AreEqual(charge.ChargeType.Type, addedCharge.ChargeType.Type, "Charge Type was not added correctly.");
                    Assert.AreEqual(charge.ChargeCostType.Type, addedCharge.ChargeCostType.Type, "Charge Cost Type was not added correctly.");
                }
            }
Beispiel #6
0
        /// <summary>
        /// Create a new charge
        /// </summary>
        /// <param name="charge">The charge to create</param>
        public void Create(Charge charge)
        {
            SqlParameter outputKey;
            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeCategoryId, charge.ChargeCategory.Id),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.Name, charge.Name),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeTypeCode, charge.ChargeType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.Reference, charge.Reference),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeCostTypeCode, charge.ChargeCostType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.TaxRate, charge.TaxRate),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.IsActive, charge.IsActive),
                };

            SetChargeDefaultValues(parameters, charge);

            parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(ChargeMapper.Parameters.Id, SqlDbType.Int));
          
            string fixedFields = string.Empty;
            string fixedValues = string.Empty;

            // Only insert currency and amount if the cost type is fixed
            if (charge.ChargeCostType.Type == ChargeCostTypeEnum.Fixed)
            {
                fixedFields = @"
                        CurrencyCode,
                        Amount,";

                fixedValues = @"
                        @CurrencyCode,
                        @Amount,";


                parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.CurrencyCode, charge.CurrencyCode));
                parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.Amount, charge.Amount));
            }

            string sqlStatement = string.Format(@"
                INSERT INTO Pricing.Charge
                (
                        ChargeCategoryId,
                        Name,
                        ChargeTypeCode,
                        Reference,
                        ChargeCostTypeCode, 
                        {0}
                        TaxRate,
                        IsActive,
                        ChargePriceTypeCode,
                        ChargeRulesTypeCode,
                        ChargeClassTypeCode,
                        ChargeFrequencyTypeCode,
                        MaxPerRoom,
                        UpdatedByUserId
                )
                VALUES
                (
                        @ChargeCategoryId,
                        @Name,
                        @ChargeTypeCode,
                        @Reference,
                        @ChargeCostTypeCode,
                        {1}

                        @TaxRate,
                        @IsActive,
                        @ChargePriceTypeCode,
                        @ChargeRulesTypeCode,
                        @ChargeClassTypeCode,
                        @ChargeFrequencyTypeCode,
                        @MaxPerRoom,
                        @UpdatedByUserId
                )
                SELECT @Id = SCOPE_IDENTITY()", fixedFields, fixedValues);
            
            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            DbHelper.ExecuteNonQueryCommand(sqlStatement, parameters: parameters);
            charge.Id = DbHelper.ParameterValue<int>(outputKey);
        }
Beispiel #7
0
            public void ModifyChargeAndCreateCategoryCallsCorrectMethods()
            {
                // Arrange
                const long BUSINESS_ID = 501;

                var chargeDaoMock = MockRepository.GenerateMock<IChargeDao>();
                var chargeCategoryDaoMock = MockRepository.GenerateMock<IChargeCategoryDao>();
                var eventTrackingManagerMock = MockRepository.GenerateMock<IEventTrackingManager>();

                settingsManager.ChargeDao = chargeDaoMock;
                settingsManager.ChargeCategoryDao = chargeCategoryDaoMock;
                settingsManager.EventTrackingManager = eventTrackingManagerMock;

                var chargeCategory = new ChargeCategory
                    {
                        BusinessId = BUSINESS_ID,
                        Name = "Room Stuff"
                    };

                var charge = new Charge
                    {
                        Id = 1,
                        ChargeCategory = chargeCategory,
                        ChargeType = new ChargeType {Type = ChargeTypeEnum.Charge},
                        ChargeCostType = new ChargeCostType {Type = ChargeCostTypeEnum.Variable},
                        Name = "TV"
                    };

                chargeDaoMock.Expect(c => c.Modify(charge));
                chargeDaoMock.Expect(c => c.GetChargesByBusinessId(Arg<long>.Is.Anything, Arg<string>.Is.Anything)).Return(new List<Charge>());
                chargeCategoryDaoMock.Expect(c => c.Create(chargeCategory)).WhenCalled(delegate { chargeCategory.Id = 1; });


                eventTrackingManagerMock.Expect(be => be.CreateBusinessEventAsync(Arg<long>.Is.Anything, Arg<BusinessEventTypesEnum>.Matches(ev => ev == BusinessEventTypesEnum.ChargeModified), Arg<string>.Is.Anything, Arg<string>.Is.Anything));
                eventTrackingManagerMock.Expect(be => be.CreateBusinessEventAsync(Arg<long>.Is.Anything, Arg<BusinessEventTypesEnum>.Matches(ev => ev == BusinessEventTypesEnum.ChargeCategoryAdded), Arg<string>.Is.Anything, Arg<string>.Is.Anything));

                // Act
                settingsManager.ModifyCharge(charge);

                // Assert
                chargeDaoMock.VerifyAllExpectations();
                chargeCategoryDaoMock.VerifyAllExpectations();
                eventTrackingManagerMock.VerifyAllExpectations();
            }
Beispiel #8
0
        /// <summary>
        /// Check if a charge already exists for a charge category
        /// </summary>
        /// <param name="charge">The charge to check</param>
        /// <returns>True if charge exists for the category</returns>
        private bool DoesChargeAlreadyExist(Charge charge)
        {
            Charge matchedCharge = GetChargesByBusinessId(charge.ChargeCategory.BusinessId, string.Empty).FirstOrDefault(x => x.ChargeCategory.Id == charge.ChargeCategory.Id && x.Name == charge.Name);

            if (matchedCharge != null && charge.Id != matchedCharge.Id)
            {
                return true;
            }

            return false;
        }
Beispiel #9
0
            public void CreateChargeWithInvalidChargeCategoryThrowsException()
            {
                // Arrange
                var chargeDaoMock = MockRepository.GenerateMock<IChargeDao>();

                settingsManager.ChargeDao = chargeDaoMock;

                var charge = new Charge
                {
                    ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                    ChargeCostType = new ChargeCostType { Type = ChargeCostTypeEnum.Variable },
                    Name = "TV"
                };

                // Act
                settingsManager.CreateCharge(charge);
            }
Beispiel #10
0
        /// <summary>
        /// Create or Update a Charge
        /// </summary>
        /// <param name="charge">The charge to create or update</param>
        public void Upsert(Charge charge)
        {
            using (var tx = new BusinessTransaction())
            {
                var existingChargeCategory =
                    chargeCategoryDao.GetChargeCategoriesByBusinessId(charge.ChargeCategory.BusinessId).FirstOrDefault(
                        x => string.Equals(x.Name, charge.ChargeCategory.Name, StringComparison.CurrentCultureIgnoreCase));

                if (existingChargeCategory == null)
                {
                    chargeCategoryDao.Create(charge.ChargeCategory);

                }
                else
                {
                    charge.ChargeCategory.Id = existingChargeCategory.Id;
                    chargeCategoryDao.Modify(charge.ChargeCategory);
                }

                // Activate if charge is inactive
                if (charge.Id == default(int))
                {
                    if (chargeDao.DoesInactiveChargeExist(charge))
                    {
                        // Id is set by check
                        charge.IsActive = true;
                    }
                }

                chargeDao.Upsert(charge);
                tx.Commit();
            }
        }
Beispiel #11
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 }));
                }
            }
        }
Beispiel #12
0
        private void SetChargeDefaultValues(List<SqlParameter> parameters, Charge charge)
        {
            // default values for charge/discount
            parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChargePriceTypeCode, ChargePriceTypeEnum.Value.GetCode()));
            parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeFrequencyTypeCode, ChargeFrequencyTypeEnum.OnDemand.GetCode()));
            parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.MaxPerRoom, 1));

            // default values for Charge only
            if (charge.ChargeType.Type == ChargeTypeEnum.Charge)
            {
               parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeRulesTypeCode, ChargeRulesTypeEnum.PerItem.GetCode()));
               parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeClassTypeCode, ChargeClassTypeEnum.Extras.GetCode()));
            }
            // default values for discount only
            else if (charge.ChargeType.Type == ChargeTypeEnum.Discount)
            {
               parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeRulesTypeCode, ChargeRulesTypeEnum.EntireBill.GetCode()));
               parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeClassTypeCode, ChargeClassTypeEnum.Specials.GetCode()));
            }
        }
Beispiel #13
0
        /// <summary>
        /// Update or Insert charge
        /// Update charge if it exists otherwise create a new one
        /// </summary>
        /// <param name="charge">Charge</param>
        public void Upsert(Charge charge)
        {
            SqlParameter outputKey;

            #region  Create parameters for Create and Update

            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeCategoryId, charge.ChargeCategory.Id),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.Name, charge.Name), 
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeTypeCode, charge.ChargeType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeClassTypeCode, charge.ChargeClassType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeRulesTypeCode, charge.ChargeRulesType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargePriceTypeCode, charge.ChargePriceType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeCostTypeCode, charge.ChargeCostType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.Reference, charge.Reference),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.TaxRate, charge.TaxRate),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.IsActive, charge.IsActive)
                };

            if (charge.Id == default(int))
            {
                parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(ChargeMapper.Parameters.Id, SqlDbType.Int)); 
            }
            else
            {
                parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.Id, charge.Id));
            }

            #endregion

            #region Create sql statements for Create and Update
            
            string sqlStatement;

            if (charge.Id == default(int))
            {
                var additionalFields = new StringBuilder();
                var additionalValues = new StringBuilder();

                // Only insert currency and amount if the cost type is fixed
                if (charge.ChargeCostType.Type == ChargeCostTypeEnum.Fixed)
                {
                    additionalFields.Append(@"
                        CurrencyCode,
                        Amount,
                        ChildAmount,
                        ");

                    additionalValues.Append(@"
                        @CurrencyCode,
                        @Amount,
                        @ChildAmount,");
                    
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.CurrencyCode, charge.CurrencyCode));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.Amount, charge.Amount));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChildAmount, charge.ChildAmount));
                }

                // Only insert fields for Extras
                if (charge.ChargeClassType.Type == ChargeClassTypeEnum.Extras)
                {
                    additionalFields.Append(@"
                        ChargeFrequencyTypeCode,
                        MaxPerRoom,
                        IsOnlineDisplay,
                        OnlineName,
                        OnlineDescription,
                        ApplicationDays,
                        BookLeadTimeDays,
                        ");

                    additionalValues.Append(@"
                        @ChargeFrequencyTypeCode,
                        @MaxPerRoom,
                        @IsOnlineDisplay,
                        @OnlineName,
                        @OnlineDescription,
                        @ApplicationDays,
                        @BookLeadTimeDays,
                        ");

                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeFrequencyTypeCode, charge.ChargeFrequencyType.Type.GetCode()));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.MaxPerRoom, charge.MaxPerRoom));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.IsOnlineDisplay, charge.IsOnlineDisplay));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.OnlineName, charge.OnlineName));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.OnlineDescription, charge.OnlineDescription));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ApplicationDays, charge.ApplicableDays));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.BookLeadTimeDays, charge.BookLeadTimeDays));
                }

                sqlStatement = string.Format(@"
                    INSERT INTO Pricing.Charge
                    (
                            ChargeCategoryId,
                            Name,
                            ChargeTypeCode,
                            Reference,
                            ChargeClassTypeCode,
                            ChargeCostTypeCode,
                            ChargePriceTypeCode,
                            ChargeRulesTypeCode,
                            {0}
                            TaxRate,
                            IsActive,
                            UpdatedByUserId
                    )
                    VALUES
                    (
                            @ChargeCategoryId,
                            @Name,
                            @ChargeTypeCode,
                            @Reference,
                            @ChargeClassTypeCode,
                            @ChargeCostTypeCode,
                            @ChargePriceTypeCode,
                            @ChargeRulesTypeCode,
                            {1}
                            @TaxRate,
                            @IsActive,
                            @UpdatedByUserId
                    )
                    SELECT @Id = SCOPE_IDENTITY()", additionalFields, additionalValues);
            }
            else
            {
                var additionalUpdates = new StringBuilder();
               
                // Only update currency and amount if the cost type is fixed
                if (charge.ChargeCostType.Type == ChargeCostTypeEnum.Fixed)
                {
                    additionalUpdates.Append(@" CurrencyCode = @CurrencyCode,
                                                Amount = @Amount,
                                                ChildAmount = @ChildAmount,");

                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.CurrencyCode, charge.CurrencyCode));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.Amount, charge.Amount));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChildAmount, charge.ChildAmount));
                }

                // Only update fields for Extras
                if (charge.ChargeClassType.Type == ChargeClassTypeEnum.Extras)
                {
                    additionalUpdates.Append(@" ChargeFrequencyTypeCode = @ChargeFrequencyTypeCode,
                                                MaxPerRoom = @MaxPerRoom,
                                                IsOnlineDisplay = @IsOnlineDisplay,
                                                OnlineName = @OnlineName,
                                                OnlineDescription = @OnlineDescription,
                                                ApplicationDays = @ApplicationDays,
                                                BookLeadTimeDays = @BookLeadTimeDays,
                                              ");

                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeFrequencyTypeCode, charge.ChargeFrequencyType.Type.GetCode()));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.MaxPerRoom, charge.MaxPerRoom));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.IsOnlineDisplay, charge.IsOnlineDisplay));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.OnlineName, charge.OnlineName));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.OnlineDescription, charge.OnlineDescription));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.ApplicationDays, charge.ApplicableDays));
                    parameters.Add(DbHelper.CreateParameter(ChargeMapper.Parameters.BookLeadTimeDays, charge.BookLeadTimeDays));
                }

                sqlStatement = string.Format(@"
                    UPDATE  Pricing.Charge
                    SET     ChargeCategoryId = @ChargeCategoryId,
                            Name = @Name,
                            ChargeTypeCode = @ChargeTypeCode,
                            Reference = @Reference,
                            ChargeClassTypeCode = @ChargeClassTypeCode,
                            ChargeCostTypeCode = @ChargeCostTypeCode,
                            ChargePriceTypeCode = @ChargePriceTypeCode,
                            ChargeRulesTypeCode = @ChargeRulesTypeCode,
                            {0}
                            TaxRate = @TaxRate,
                            IsActive = @IsActive,
                            UpdatedByUserId = @UpdatedByUserId
                    WHERE   Id = @Id", additionalUpdates);
            }

            #endregion

            // Create auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            DbHelper.ExecuteNonQueryCommand(sqlStatement, parameters: parameters);
        }
Beispiel #14
0
        /// <summary>
        /// Check if an inactive charge already exists
        /// </summary>
        /// <param name="charge">Charge to check</param>
        /// <returns>True if charge exists</returns>
        public bool DoesInactiveChargeExist(Charge charge)
        {
            const string QUERY = @"
                    SELECT Id
                    FROM   Pricing.Charge
                    WHERE  ChargeCategoryId = @ChargeCategoryId 
                    AND    Name = @Name 
                    AND    IsActive = 0 ";

            var parameters = new List<SqlParameter>
            {
                DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeCategoryId, charge.ChargeCategory.Id),
                DbHelper.CreateParameter(ChargeMapper.Parameters.Name, charge.Name)
            };
            
            int? chargeId = DbHelper.ExecuteScalar<int?>(QUERY, CommandType.Text, parameters);

            if (chargeId != null)
            {
                charge.Id = chargeId.Value;
                return true;
            }

            return false;
        }
Beispiel #15
0
            public void DoesInactiveChargeExistReturnsFalseWhenChargeDoesNotExist()
            {
                // Arrange
                const string CHARGE_NAME = "Gin";

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateChargeTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var charge = new Charge
                    {
                        Name = CHARGE_NAME,
                        ChargeCategory = new ChargeCategory { Id = 1 },
                        ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                        ChargeCostType = new ChargeCostType { Type = ChargeCostTypeEnum.Variable }
                    };

                    // Act
                    bool result = chargeDao.DoesInactiveChargeExist(charge);

                    // Assert
                    Assert.IsFalse(result, "Inactive charge should not exist.");
                }
            }
Beispiel #16
0
            public void CreateChargeWithInvalidChargeCostTypeThrowsException()
            {
                // Arrange
                const long BUSINESS_ID = 501;

                var chargeDaoMock = MockRepository.GenerateMock<IChargeDao>();

                settingsManager.ChargeDao = chargeDaoMock;

                var chargeCategory = new ChargeCategory
                {
                    Id = 1,
                    BusinessId = BUSINESS_ID
                };

                var charge = new Charge
                {
                    ChargeCategory = chargeCategory,
                    ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                    Name = "TV"
                };

                // Act
                settingsManager.CreateCharge(charge);
            }
Beispiel #17
0
            public void GetActiveOrAllChargesByBusinessIsSuccessful()
            {
                // Arrange
                const string CULTURE_CODE = "en-GB";
                const long BUSINESS_ID = 501;
                const string CHARGE_NAME = "InactiveChargeTest";

                using (new TestDataHelper(GetTestQuery(TestQuery.PopulateChargeTestData), GetTestQuery(TestQuery.CleanupUnitTestData)))
                {
                    var chargeCategoryId = chargeCategoryDao.GetChargeCategoriesByBusinessId(BUSINESS_ID).FirstOrDefault(x => x.Name == "Bar").Id;
                    var charge = new Charge
                    {
                        Name = CHARGE_NAME,
                        ChargeCategory = new ChargeCategory { Id = chargeCategoryId },
                        ChargeType = new ChargeType { Type = ChargeTypeEnum.Charge },
                        ChargeCostType = new ChargeCostType { Type = ChargeCostTypeEnum.Variable },
                        ChargePriceType = new ChargePriceType { Type = ChargePriceTypeEnum.Value },
                        ChargeRulesType = new ChargeRulesType { Type = ChargeRulesTypeEnum.EntireBill },
                        ChargeClassType = new ChargeClassType { Type = ChargeClassTypeEnum.Specials },
                        IsActive = false
                    };

                    // Act
                    chargeDao.Upsert(charge);

                    // Get all charges
                    List<Charge> allCharges = chargeDao.GetChargesByBusiness(BUSINESS_ID, CULTURE_CODE, false).OrderBy(x => x.UpdatedDateTime).ToList();

                    Assert.AreEqual(allCharges.Count, 4);

                    // Get active charges
                    List<Charge> activeCharges = chargeDao.GetChargesByBusiness(BUSINESS_ID, CULTURE_CODE).OrderBy(x => x.UpdatedDateTime).ToList();
                    Assert.AreEqual(activeCharges.Count, 3);
                }
                
            }
Beispiel #18
0
        /// <summary>
        /// Modify an existing charge
        /// </summary>
        /// <param name="charge">The charge to modify</param> 
        public void Modify(Charge charge)
        {
            // Only insert currency and amount if the cost type is fixed
            if (charge.ChargeCostType.Type == ChargeCostTypeEnum.Variable)
            {
                charge.CurrencyCode = null;
                charge.Amount = null;
            }

            string sqlStatement = @"
                UPDATE  Pricing.Charge
                SET     ChargeCategoryId = @ChargeCategoryId,
                        Name = @Name,
                        ChargeTypeCode = @ChargeTypeCode,
                        Reference = @Reference,
                        ChargeCostTypeCode = @ChargeCostTypeCode,
                        ChargePriceTypeCode = @ChargePriceTypeCode,
                        ChargeRulesTypeCode = @ChargeRulesTypeCode,
                        ChargeClassTypeCode = @ChargeClassTypeCode,
                        ChargeFrequencyTypeCode = @ChargeFrequencyTypeCode,
                        MaxPerRoom = @MaxPerRoom,
                        CurrencyCode = @CurrencyCode,
                        Amount = @Amount,
                        TaxRate = @TaxRate,
                        IsActive = @IsActive,
                        UpdatedByUserId = @UpdatedByUserId
                WHERE   Id = @Id";

            var parameters = new List<SqlParameter>
                {
                    DbHelper.CreateParameter(ChargeMapper.Parameters.Id, charge.Id),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeCategoryId, charge.ChargeCategory.Id),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.Name, charge.Name),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeTypeCode, charge.ChargeType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.Reference, charge.Reference),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.ChargeCostTypeCode, charge.ChargeCostType.Type.GetCode()),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.CurrencyCode, charge.CurrencyCode),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.Amount, charge.Amount),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.TaxRate, charge.TaxRate),
                    DbHelper.CreateParameter(ChargeMapper.Parameters.IsActive, charge.IsActive)
                };
            SetChargeDefaultValues(parameters, charge);
            // Add auditing parameters
            AuditFieldsHelper.PopulateAuditFields(parameters);

            int rowsAffected = DbHelper.ExecuteNonQueryCommand(sqlStatement, parameters: parameters);

            // Check if the update was successful
            if (rowsAffected == 0)
            {
                throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30027,"ChargeDao.Modify",
                    additionalDescriptionParameters: (new object[] { charge.GetType().Name, charge.Id }),
                    arguments: new object[] { charge.GetType().Name, charge.Id }));
            }
        }