Exemplo n.º 1
0
 public void Create(CreateWashEntity entity)
 {
     switch (entity.WashType)
     {
             case WashType.CarpetWash:
         {
             CreateCarpetWash(entity);
             break;
         }
             case WashType.ContractedCarWash:
         {
             CreateContractedCarWash(entity);
             break;
         }
             case WashType.IndividualCarWash:
         {
             CreateIndividualCarWash(entity);
             break;
         }
     }
 }
Exemplo n.º 2
0
        private void CreateCarpetWash(CreateWashEntity entity)
        {
            if (!entity.Amount.HasValue)
            {
                throw new BusinessLayerException("Carpet wash has no amount.");
            }

            if (!entity.SquareArea.HasValue)
            {
                throw new BusinessLayerException("Carpet wash has no square area.");
            }

            var income = new Income(entity.WashType.Localize(), entity.Amount.Value, entity.Date);
            _operationRepository.Insert(income);

            var wash = new Wash(entity.Date, entity.SquareArea.Value, income);
            _washRepository.Insert(wash);

            income.Wash = wash;
            income.WashId = wash.Id;
            _operationRepository.Update(income);
        }
Exemplo n.º 3
0
        private void CreateContractedCarWash(CreateWashEntity entity)
        {
            if (!entity.ContractId.HasValue)
            {
                throw new BusinessLayerException("Contracted Car wash has no amount.");
            }

            var contract = _contractRepository.GetById(entity.ContractId.Value);

            if (contract == null)
            {
                throw  new BusinessLayerException("Selected contract does not exist.");
            }

            var wash = new Wash(entity.Date, entity.CarNumber, contract);
            _washRepository.Insert(wash);

            contract.Washes.Add(wash);
            _contractRepository.Update(contract);
        }
Exemplo n.º 4
0
        private void CreateIndividualCarWash(CreateWashEntity entity)
        {
            if (!entity.Amount.HasValue)
            {
                throw new BusinessLayerException("Individual Car wash has no amount.");
            }

            var income = new Income(entity.WashType.Localize(), entity.Amount.Value, entity.Date);

            var wash = new Wash(entity.Date, entity.CarNumber, income);
            _washRepository.Insert(wash);

            income.Wash = wash;
            income.WashId = wash.Id;
            _operationRepository.Insert(income);
        }