public CustomerAppService(IBrandRepository brandRepository
                           , IBrandPolicy brandPolicy
                           , IObjectMapper objectMapper
                           , IRepositoryAsync <Brand> rep) : base(rep, objectMapper)
 {
     this._brandRepository = brandRepository ?? throw new ArgumentNullException(nameof(brandRepository));
     this._brandPolicy     = brandPolicy ?? throw new ArgumentNullException(nameof(brandPolicy));
 }
 public CustomerAppService(IBrandRepository brandRepository
                           , IBrandPolicy brandPolicy
                           , IObjectMapper objectMapper
                           , IRepositoryAsync <Brand, int> rep
                           , ICache cacheServ
                           , ILog log
                           , IUnitOfWorkAsync unitofWorkAsync) : base(rep, objectMapper, unitofWorkAsync)
 {
     this._brandRepository = brandRepository ?? throw new ArgumentNullException(nameof(brandRepository));
     this._brandPolicy     = brandPolicy ?? throw new ArgumentNullException(nameof(brandPolicy));
     this._cacheServ       = cacheServ ?? throw new ArgumentNullException(nameof(cacheServ));
     this._log             = log ?? throw new ArgumentNullException(nameof(log));
 }
Beispiel #3
0
        public async Task <int> ChangeBrand(int brandId, IBrandPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }
            var result = await policy.CheckAssignment(brandId);

            if (!result)
            {
                throw new CustomerDomainException($"{brandId} Brand is Invalid or in Blacklist cannot be assigned!!! ");
            }
            this.BrandId = brandId;
            return(this.BrandId);
        }
Beispiel #4
0
        // Policy is a pattern. Conceptual rules known as Strategy design also. You could wrap this policy within Service also
        public Merchant AddMerchant(string name, string surname, int brandId, int limitId
                                    , IBrandPolicy policy, string gsm = default)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            if (this.Merchants.Count() >= policy.MaxAmountofMarchantperBrand)
            {
                throw new CustomerDomainException($"Maximum amount of Merchant exceed for this Brand !!! ");
            }

            var merchant = Merchant.Create(name, surname, brandId, limitId, gsm);

            _merchants.Add(merchant);
            return(merchant);
        }
Beispiel #5
0
        public void ChangeMerchantName(string name, Merchant merchant, IBrandPolicy policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            var existingMerchantforBrand = this._merchants.Where(x => x.BrandId == merchant.Id)
                                           .SingleOrDefault();

            if (existingMerchantforBrand != null)
            {
                existingMerchantforBrand.ChangeName(merchant.Name);
                existingMerchantforBrand.SyncObjectState(ObjectState.Modified);
            }
            else
            {
                this.AddMerchant(merchant.Name, merchant.Surname, merchant.BrandId, merchant.LimitId, policy, merchant.Gsm);
            }
        }