Beispiel #1
0
        public async Task <ToggleBonusStatusResponse> ChangeStatus(ToggleBonusStatus model)
        {
            VerifyPermission(Permissions.Activate, Modules.BonusManager);
            VerifyPermission(Permissions.Deactivate, Modules.BonusManager);

            var bonus = await _bonusApiProxy.GetBonusOrNull(model.Id);

            if (bonus != null)
            {
                CheckBrand(bonus.BrandId);
            }

            return(await _bonusApiProxy.ChangeBonusStatusAsync(model));
        }
        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));
        }