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; } } }
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); }
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); }
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); }