public Data.Bonus MapModelToBonus(CreateUpdateBonus model) { var bonus = Mapper.Map <Data.Bonus>(model); var template = _bonusQueries.GetCurrentVersionTemplates().Single(a => a.Id == model.TemplateId); bonus.Template = template; var timezoneId = template.Info.Brand.TimezoneId; bonus.ActiveFrom = bonus.DurationStart = model.ActiveFrom.ToBrandDateTimeOffset(timezoneId); bonus.ActiveTo = bonus.DurationEnd = model.ActiveTo.ToBrandDateTimeOffset(timezoneId); if (model.DurationType == DurationType.Custom) { bonus.DurationStart = model.DurationStart.ToBrandDateTimeOffset(timezoneId); bonus.DurationEnd = model.DurationEnd.ToBrandDateTimeOffset(timezoneId); } else if (model.DurationType == DurationType.StartDateBased) { var durationLength = new TimeSpan(model.DurationDays, model.DurationHours, model.DurationMinutes, 0); bonus.DurationEnd = bonus.ActiveFrom.Add(durationLength); } return(bonus); }
public Core.Data.Bonus CreateBonus(Template bonusTemplate, bool isActive = true) { var now = DateTimeOffset.Now.ToBrandOffset(bonusTemplate.Info.Brand.TimezoneId).Date; var model = new CreateUpdateBonus { Id = Guid.Empty, Name = TestDataGenerator.GetRandomString(5), Code = TestDataGenerator.GetRandomString(5), Description = TestDataGenerator.GetRandomString(20), TemplateId = bonusTemplate.Id, ActiveFrom = now, ActiveTo = now.AddDays(1), DurationStart = now, DurationEnd = now.AddDays(1) }; var bonusId = BonusManagementCommands.AddUpdateBonus(model); if (isActive) { BonusManagementCommands.ChangeBonusStatus(new ToggleBonusStatus { Id = bonusId, IsActive = true }); } return(BonusRepository.GetCurrentVersionBonuses().Single(b => b.Id == bonusId)); }
public async Task <Bonus.Core.Models.Data.Bonus> CreateBonus(Template bonusTemplate, bool isActive = true) { var brand = _brandQueries.GetBrand(bonusTemplate.Info.BrandId); var now = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId).Date; var model = new CreateUpdateBonus { Id = Guid.Empty, Name = TestDataGenerator.GetRandomString(5), Code = TestDataGenerator.GetRandomString(5), TemplateId = bonusTemplate.Id, ActiveFrom = now, ActiveTo = now.AddDays(1), DurationStart = now, DurationEnd = now.AddDays(1) }; var response = await _bonusApiProxy.CreateUpdateBonusAsync(model); if (response.Success == false) { throw new Exception(response.Errors.First().ErrorMessage); } if (isActive) { await _bonusApiProxy.ChangeBonusStatusAsync(new ToggleBonusStatus { Id = response.BonusId.Value, IsActive = true }); } return(await _bonusApiProxy.GetBonusOrNull(response.BonusId.Value)); }
public void Updated_bonus_is_correctly_saved_to_DB() { var template = CreateFirstDepositTemplate(mode: IssuanceMode.AutomaticWithCode); var baseBonus = CreateFirstDepositBonus(isActive: false, mode: IssuanceMode.AutomaticWithCode); var model = new CreateUpdateBonus { Name = TestDataGenerator.GetRandomString(), Code = TestDataGenerator.GetRandomString(), Description = TestDataGenerator.GetRandomString(), TemplateId = template.Id, Id = baseBonus.Id, Version = baseBonus.Version, DurationType = DurationType.None, ActiveFrom = DateTimeOffset.Now.ToBrandOffset(template.Info.Brand.TimezoneId).Date, ActiveTo = DateTimeOffset.Now.AddDays(1).ToBrandOffset(template.Info.Brand.TimezoneId).Date }; var bonusId = _bonusManagementCommands.AddUpdateBonus(model); var updatedBonus = BonusRepository.GetCurrentVersionBonuses().Single(a => a.Id == bonusId); Assert.AreEqual(1, updatedBonus.Version); Assert.AreEqual(model.Code, updatedBonus.Code); }
public void Qualified_bonuses_list_contain_current_bonus_version() { var bonusManagementCommands = Container.Resolve <BonusManagementCommands>(); var template = CreateFirstDepositTemplate(mode: IssuanceMode.AutomaticWithCode); var now = DateTimeOffset.Now.ToBrandOffset(template.Info.Brand.TimezoneId).Date; var uiModel1 = new CreateUpdateBonus { Id = Guid.Empty, TemplateId = template.Id, Name = TestDataGenerator.GetRandomString(), Code = TestDataGenerator.GetRandomString(), Description = TestDataGenerator.GetRandomString(), ActiveFrom = now, ActiveTo = now.AddDays(1) }; var bonusId = bonusManagementCommands.AddUpdateBonus(uiModel1); bonusManagementCommands.ChangeBonusStatus(new ToggleBonusStatus { Id = bonusId, IsActive = true }); bonusManagementCommands.ChangeBonusStatus(new ToggleBonusStatus { Id = bonusId, IsActive = false }); var uiModel2 = new CreateUpdateBonus { Id = bonusId, Version = 2, TemplateId = template.Id, Name = TestDataGenerator.GetRandomString(), Code = TestDataGenerator.GetRandomString(), Description = TestDataGenerator.GetRandomString(), ActiveFrom = now, ActiveTo = now.AddDays(1) }; bonusManagementCommands.AddUpdateBonus(uiModel2); bonusManagementCommands.ChangeBonusStatus(new ToggleBonusStatus { Id = bonusId, IsActive = true }); BonusQueries .GetDepositQualifiedBonuses(PlayerId) .Single() .Code .Should() .Be(uiModel2.Code); }
public Guid AddUpdateBonus(CreateUpdateBonus model) { var validationResult = _bonusQueries.GetValidationResult(model); if (validationResult.IsValid == false) { throw new RegoException(string.Join("/n", validationResult.Errors.Select(failure => failure.ErrorMessage))); } var bonus = _bonusMapper.MapModelToBonus(model); return(model.Id == Guid.Empty ? AddBonus(bonus) : UpdateBonus(bonus)); }
public async Task <AddEditBonusResponse> CreateUpdate(CreateUpdateBonus model) { VerifyPermission(Permissions.Create, Modules.BonusManager); VerifyPermission(Permissions.Update, Modules.BonusManager); var template = await _bonusApiProxy.GetTemplateOrNull(model.TemplateId); if (template != null) { CheckBrand(template.Info.BrandId); } return(await _bonusApiProxy.CreateUpdateBonusAsync(model)); }
public override void BeforeEach() { base.BeforeEach(); var brand = BonusRepository.Brands.First(); var template = new Template { Status = TemplateStatus.Complete, Info = new TemplateInfo { TemplateType = BonusType.ReloadDeposit, Name = TestDataGenerator.GetRandomString(), Brand = brand, WalletTemplateId = brand.WalletTemplates.First().Id }, Availability = new TemplateAvailability(), Rules = new TemplateRules { RewardTiers = new List <RewardTier> { new RewardTier { CurrencyCode = brand.Currencies.First().Code, BonusTiers = new List <TierBase> { new TierBase { Reward = 100 } } } } }, Wagering = new TemplateWagering(), Notification = new TemplateNotification() }; BonusRepository.Templates.Add(template); _brandTimezoneId = brand.TimezoneId; _model = new CreateUpdateBonus { Name = TestDataGenerator.GetRandomString(), Code = TestDataGenerator.GetRandomString(), Description = TestDataGenerator.GetRandomString(), TemplateId = template.Id, ActiveFrom = DateTimeOffset.Now.ToBrandOffset(_brandTimezoneId).Date, ActiveTo = DateTimeOffset.Now.ToBrandOffset(_brandTimezoneId).AddDays(1).Date, DurationType = DurationType.None }; }
public AddEditBonusResponse CreateUpdate(CreateUpdateBonus model) { var validationResult = _bonusQueries.GetValidationResult(model); if (!validationResult.IsValid) { return(ValidationErrorResponse <AddEditBonusResponse>(validationResult)); } var bonusId = _bonusCommands.AddUpdateBonus(model); return(new AddEditBonusResponse { Success = true, BonusId = bonusId }); }
public override void BeforeEach() { base.BeforeEach(); var template = CreateFirstDepositTemplate(); _model = new CreateUpdateBonus { Name = TestDataGenerator.GetRandomString(), Code = TestDataGenerator.GetRandomString(), TemplateId = template.Id, ActiveFrom = DateTimeOffset.Now.Date, ActiveTo = DateTimeOffset.Now.AddDays(1).Date, DurationType = DurationType.None }; _bonusMapper = Container.Resolve <BonusMapper>(); }
public AddEditBonusResponse CreateUpdateBonus(CreateUpdateBonus request) { return(WebClient.SecurePostAsJson <CreateUpdateBonus, AddEditBonusResponse>(Token, _url + AdminApiRoutes.CreateUpdateBonus, request)); }
public Task <AddEditBonusResponse> CreateUpdateBonusAsync(CreateUpdateBonus request) { return(SecurePostAsJson <CreateUpdateBonus, AddEditBonusResponse>(Routes.CreateUpdateBonus, request)); }
public ValidationResult GetValidationResult(CreateUpdateBonus model) { return(new BonusValidator(_repository, this).Validate(model)); }