Пример #1
0
        public void ThenNewBrandIsSuccessfullyAdded()
        {
            var licensee = BrandTestHelper.CreateLicensee();

            var data = new AddBrandRequest()
            {
                Code                   = TestDataGenerator.GetRandomString(),
                InternalAccounts       = 1,
                EnablePlayerPrefix     = true,
                PlayerPrefix           = TestDataGenerator.GetRandomString(3),
                Licensee               = licensee.Id,
                Name                   = TestDataGenerator.GetRandomString(),
                PlayerActivationMethod = PlayerActivationMethod.Automatic,
                TimeZoneId             = TestDataGenerator.GetRandomTimeZone().Id,
                Type                   = BrandType.Integrated,
                Email                  = TestDataGenerator.GetRandomEmail(),
                SmsNumber              = TestDataGenerator.GetRandomPhoneNumber(useDashes: false),
                WebsiteUrl             = TestDataGenerator.GetRandomWebsiteUrl()
            };

            var result = AdminApiProxy.AddBrand(data);

            result.Should().NotBeNull();
            result.Success.Should().BeTrue();
            result.Data.Should().NotBeNull();
        }
Пример #2
0
        public async Task <ServiceResponse <Brand> > Create(AddBrandRequest request)
        {
            try
            {
                var brand = new Brand
                {
                    Code        = GenerateCode(8),
                    Description = request.Description,
                    Name        = request.Name
                };

                var exist = await _baseRepository.GetByIdAndCode(brand.Id, brand.Code);

                if (exist != null)
                {
                    return(new ServiceResponse <Brand>($"A Brand With the Provided Code and or Id Already Exist"));
                }

                var exist2 = await _baseRepository.FindOneByConditions(x => x.Name.ToLower().Equals(brand.Name.ToLower()));

                if (exist2 != null)
                {
                    return(new ServiceResponse <Brand>($"A Brand With the Provided Name Already Exist"));
                }

                await _baseRepository.Create(brand);

                return(new ServiceResponse <Brand>(brand));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <Brand>($"An Error Occured While Creating The Brand. {ex.Message}"));
            }
        }
Пример #3
0
        public async Task <ActionResult> Create(AddBrandViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var addBrandRequest = new AddBrandRequest {
                    Name = request.Name, Description = request.Description
                };
                var result = await _brandService.Create(addBrandRequest);

                if (!result.Success)
                {
                    Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }
                Alert($"Brand Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
Пример #4
0
        public async Task <ActionResult <BrandViewModel> > CreateBrandAsync([FromBody] AddBrandRequest request)
        {
            var brandViewModel = await _brandService.AddAsync(request);

            var uri = $"{RoutePattern}/{brandViewModel.Id}";

            return(Created(uri, brandViewModel));
        }
Пример #5
0
        public Guid AddBrand(AddBrandRequest addBrandRequest)
        {
            var validationResult = ValidateThatBrandCanBeAdded(addBrandRequest);

            if (!validationResult.IsValid)
            {
                throw new RegoValidationException(validationResult);
            }

            var brand = new Interface.Data.Brand
            {
                Id                     = addBrandRequest.Id ?? Guid.NewGuid(),
                LicenseeId             = addBrandRequest.Licensee,
                Licensee               = _repository.Licensees.Single(x => x.Id == addBrandRequest.Licensee),
                Code                   = addBrandRequest.Code,
                Name                   = addBrandRequest.Name,
                Email                  = addBrandRequest.Email,
                SmsNumber              = addBrandRequest.SmsNumber,
                WebsiteUrl             = Uri.EscapeUriString(addBrandRequest.WebsiteUrl),
                Type                   = addBrandRequest.Type,
                TimezoneId             = addBrandRequest.TimeZoneId,
                EnablePlayerPrefix     = addBrandRequest.EnablePlayerPrefix,
                PlayerPrefix           = addBrandRequest.PlayerPrefix,
                PlayerActivationMethod = addBrandRequest.PlayerActivationMethod,
                Status                 = BrandStatus.Inactive,
                CreatedBy              = _actorInfoProvider.Actor.UserName,
                DateCreated            = DateTimeOffset.Now.ToBrandOffset(addBrandRequest.TimeZoneId)
            };

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _repository.Brands.Add(brand);
                _repository.SaveChanges();

                _adminCommands.AddBrandToAdmin(_actorInfoProvider.Actor.Id, brand.Id);
                _eventBus.Publish(new BrandRegistered
                {
                    Id                     = brand.Id,
                    Code                   = brand.Code,
                    Name                   = brand.Name,
                    Email                  = brand.Email,
                    SmsNumber              = brand.SmsNumber,
                    WebsiteUrl             = brand.WebsiteUrl,
                    LicenseeId             = brand.Licensee.Id,
                    LicenseeName           = brand.Licensee.Name,
                    TimeZoneId             = brand.TimezoneId,
                    BrandType              = brand.Type,
                    Status                 = brand.Status,
                    PlayerPrefix           = brand.PlayerPrefix,
                    InternalAccountsNumber = brand.InternalAccountsNumber,
                    EventCreated           = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });
                scope.Complete();
            }

            return(brand.Id);
        }
Пример #6
0
        public AddBrandResponse Add(AddBrandRequest request)
        {
            VerifyPermission(Permissions.Create, Modules.BrandManager);

            var validationResult = _brandCommands.ValidateThatBrandCanBeAdded(request);

            if (!validationResult.IsValid)
            {
                return(ValidationErrorResponse <AddBrandResponse>(validationResult));
            }

            var id = _brandCommands.AddBrand(request);

            return(new AddBrandResponse {
                Success = true, Data = new BrandId {
                    Id = id
                }
            });
        }
Пример #7
0
        public ValidationResult ValidateThatBrandCanBeAdded(AddBrandRequest request)
        {
            var validator = new AddBrandValidator(_repository);

            return(validator.Validate(request));
        }
Пример #8
0
 public AddBrandResponse AddBrand(AddBrandRequest request)
 {
     return(WebClient.SecurePostAsJson <AddBrandRequest, AddBrandResponse>(Token, _url + AdminApiRoutes.AddBrand, request));
 }