public InvoiceItemCommand(decimal quantity, decimal fee, Good good, GoodUnit goodUnit, string description) { Quantity = quantity; Fee = fee; Good = good; GoodId = good.Id; GoodUnit = goodUnit; GoodUnitId = goodUnit.Id; Description = description; }
internal OffhireDetail(decimal quantity, decimal feeInVoucherCurrency, decimal feeInMainCurrency, Good good, GoodUnit unit, Tank tank, Offhire offhire, IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) : this() { this.validateOffhire(offhire, offhireDomainService); this.validateValues(quantity, feeInVoucherCurrency, feeInMainCurrency, good, unit, tank, offhire, offhireDomainService, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); this.Quantity = quantity; this.FeeInVoucherCurrency = feeInVoucherCurrency; this.FeeInMainCurrency = feeInMainCurrency; this.Good = good; this.Unit = unit; this.Tank = tank; this.Offhire = offhire; }
internal ScrapDetail(double rob, double price, Currency currency, Good good, GoodUnit unit, Tank tank, Scrap scrap, IScrapDomainService scrapDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) : this() { this.validateScrap(scrap, scrapDomainService); this.validateValues(rob, price, currency, good, unit, tank, scrap, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); this.ROB = rob; this.Price = price; this.Currency = currency; this.Good = good; this.Unit = unit; this.Tank = tank; this.Scrap = scrap; }
//================================================================================ private OffhireDetail( decimal quantity, decimal feeInVoucherCurrency, decimal feeInMainCurrency, Good good, GoodUnit unit, Tank tank, Offhire offhire) : this() { //This constructor added to be used for insert into DB. this.Quantity = quantity; this.FeeInVoucherCurrency = feeInVoucherCurrency; this.FeeInMainCurrency = feeInMainCurrency; this.Good = good; this.Unit = unit; this.Tank = tank; this.Offhire = offhire; }
//================================================================================ private ScrapDetail( double rob, double price, Currency currency, Good good, GoodUnit unit, Tank tank, Scrap scrap) { //This constructor added to be used for insert into DB. this.ROB = rob; this.Price = price; this.Currency = currency; this.Good = good; this.Unit = unit; this.Tank = tank; this.Scrap = scrap; this.isScrapSubmitRejected = new IsScrapSubmitRejected(); //this.InventoryOperations = new List<InventoryOperation>(); }
//================================================================================ private void validateGoodUnitInCompany(Company company, Good good, GoodUnit unit) { if (!(good.CompanyId == company.Id && good.GoodUnits.Count(gu => gu.Id == unit.Id) == 1)) throw new BusinessRuleException("", string.Format("Selected Good '{0}' and Unit is not defined for Company.", good.Name)); }
//================================================================================ private void validateGoodToBeUniqueInDetails(Good good, Scrap scrap) { if (scrap.ScrapDetails.Count(sd => sd.Good.Id == good.Id && sd.Id != this.Id) != 0) throw new BusinessRuleException("", string.Format("The Good '{0}' has other records in Scrap Details.", good.Name)); }
//================================================================================ private void validateGoodInTank(Tank tank, Good good, Scrap scrap) { if (good == null) throw new InvalidArgument("Good"); if (tank != null) { var registeredTanksForGoodCount = scrap.ScrapDetails.Count(sd => sd.Id != this.Id && sd.Tank != null && sd.Tank.Id == tank.Id && sd.Good.Id == good.Id); if (registeredTanksForGoodCount > 0) throw new BusinessRuleException("", string.Format("The same Good '{0}' in Tank is already defined.", good.Name)); } }
//================================================================================ private void validateGood(Good good, IGoodDomainService goodDomainService) { if (good == null) throw new BusinessRuleException("", "Good must be selected."); if (goodDomainService.Get(good.Id) == null) throw new ObjectNotFound("Good", good.Id); }
//================================================================================ private void validateGoodInTank(Tank tank, Good good, Offhire offhire) { if (good == null) throw new InvalidArgument("Good"); if (tank != null) { var registeredTanksForGoodCount = offhire.OffhireDetails.Count(od => (od.Id != this.Id || (od.Id == NOT_REGISTERED_ID && this.Id == NOT_REGISTERED_ID)) && od.Tank != null && od.Tank.Id == tank.Id && od.Good.Id == good.Id); if (registeredTanksForGoodCount > 0) throw new BusinessRuleException("", string.Format("The same Good '{0}' in Tank is already defined.", good.Name)); } }
//================================================================================ public PricingValue GetPricingValue(Company introducer, VesselInCompany vesselInCompany, DateTime startDateTime, Good good, Currency currency, DateTime currencyDateTime) { decimal? feeInNewCurrency = null; var pricingValue = GetPricingValue(introducer, vesselInCompany, startDateTime, good); if (pricingValue.Fee.HasValue && pricingValue.Currency != null) feeInNewCurrency = currencyDomainService.ConvertPrice(pricingValue.Fee.Value, pricingValue.Currency, currency, currencyDateTime); return new PricingValue() { Good = good, Currency = currency, Fee = feeInNewCurrency }; }
public void TestInitialize() { _scope = new UnitOfWorkScope(new EFUnitOfWorkFactory(() => new DataContainer())); basicInfoDomainServiceObjects = new BasicInfoDomainServiceObjectsContainer(_scope); scrapTestObjects = new ScrapTestObjectsContainer(_scope); var orderConfigurator = new OrderConfigurator ( new OrderStateFactory ( new InventoryOperationDomainService(new InventoryOperationRepository(_scope), scrapTestObjects.ScrapDomainService))); var client = new WebClientHelper(new HttpClient()); _orderRepository = new OrderRepository(_scope, orderConfigurator, new EFRepository<OrderItem>(_scope)); _orderRepository.GetAll(); _tr = new TransactionScope(); var hostAdapter = new ExternalHostAddressHelper(); var vesselService = new VesselInCompanyDomainService (new VesselInCompanyRepository(_scope, null), new VoyageRepository(_scope)); //var goodPartyService = new GoodPartyAssignmentDomainService // (new GoodPartyAssignmentAntiCorruptionAdapter(new GoodAssignmentAntiCorruptionServiceWrapper(client, hostAdapter))); var goodService = new GoodDomainService ( new GoodAntiCorruptionAdapter(new GoodAntiCorruptionServiceWrapper(client, hostAdapter), new GoodAntiCorruptionMapper()), new EFRepository<Good>(_scope), basicInfoDomainServiceObjects.CompanyDomainService, new EFRepository<GoodUnit>(_scope)); var goodUnitService = new GoodUnitDomainService ( new BaseAntiCorruptionAdapter<GoodUnit, GoodUnitDto> (new BaseAntiCorruptionServiceWrapper<GoodUnitDto>(client), new BaseAntiCorruptionMapper<GoodUnit, GoodUnitDto>()), new EFRepository<GoodUnit>(_scope)); var companyService = new CompanyDomainService ( new CompanyAntiCorruptionAdapter(new CompanyAntiCorruptionServiceWrapper(client, hostAdapter), new CompanyAntiCorruptionMapper()), new CompanyRepository(_scope)); //_target = new OrderApplicationService // ( // _orderRepository, _scope, new UserRepository(_scope), vesselService, goodService, // new OrderFactory(new OrderCodeGenerator(_orderRepository), orderConfigurator, new WorkflowRepository(_scope)), companyService, // new OrderItemDomainService(new EFRepository<OrderItem>(_scope)), orderConfigurator); //_sapid = FakeDomainService.GetCompanies().Single(c => c.Id == 1); //_imsemCo = FakeDomainService.GetCompanies().Single(c => c.Id == 3); //_hafiz = FakeDomainService.GetCompanies().Single(c => c.Id == 2); this.sapidVesselInCompany = FakeDomainService.GetVesselsInCompanies().First(c => c.CompanyId == 1); _sapidVessel2 = FakeDomainService.GetVesselsInCompanies().Last(c => c.CompanyId == 1); this.hafizVesselInCompany = FakeDomainService.GetVesselsInCompanies().First(c => c.CompanyId == 2); _good = FakeDomainService.GetGoods().Single(c => c.Id == 1); _good2 = FakeDomainService.GetGoods().Single(c => c.Id == 2); _unit = FakeDomainService.GetCompanyGoodUnits().Single(c => c.Id == 1); _unit2 = FakeDomainService.GetCompanyGoodUnits().Single(c => c.Id == 2); _unit3 = FakeDomainService.GetCompanyGoodUnits().Single(c => c.Id == 4); //_goodPartAssignment = FakeDomainService.GetGoodPartyAssignments().Single(c => c.Id == 1); //_goodPartAssignment2 = FakeDomainService.GetGoodPartyAssignments().Single(c => c.Id == 2); }
public static List<Good> GetGoods() { var res1 = new Good(1, "Heavy Fuel Oil", "HFO", 1, 1); //res1.GoodUnit = new GoodUnit(1, 1, 1, "", 1, ""); var res2 = new Good(2, "Marine Diesel Oil", "MDO", 2, 1); //res2.GoodUnit = new GoodUnit(1, 2, 1, "", 1, ""); return new List<Good> { res1,res2 }; }
private GoodUnit mapOffhireDataMeasureUnitToOffhireSystemEntityMeasureUnit(Good good, FuelUnitType fuelUnitType) { var unitTypeCode = OffhireAssetsToFuelAssetsMapper.GetFuelMeasureCode(fuelUnitType.ToString()); var goodUnit = good.GoodUnits.Single(gu => gu.Abbreviation == unitTypeCode); return goodUnit; }
//================================================================================ private void validateValues(decimal quantity, decimal feeInVoucherCurrency, decimal feeInMainCurrency, Good good, GoodUnit unit, Tank tank, Offhire offhire, IOffhireDomainService offhireDomainService, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateTank(tank, offhire, tankDomainService); this.validateGood(good, goodDomainService); this.validateGoodInTank(tank, good, offhire); this.validateGoodToBeUniqueInDetails(good, offhire); this.validateQuantity(quantity); this.validateFeeInMainCurrency(feeInMainCurrency); this.validateUnit(unit, goodUnitDomainService); this.validateGoodUnitInCompany(offhire.Introducer, good, unit); this.validateFeeInVoucherCurrency(feeInVoucherCurrency, offhire, good, offhireDomainService, currencyDomainService); }
//================================================================================ private void validateGoodToBeUniqueInDetails(Good good, Offhire offhire) { if (offhire.OffhireDetails.Count(od => (od.Id != this.Id || (od.Id == NOT_REGISTERED_ID && this.Id == NOT_REGISTERED_ID)) && od.Good.Id == good.Id) != 0) throw new BusinessRuleException("", string.Format("The Good '{0}' has other records in Offhire Details.", good.Name)); }
//================================================================================ private void validateValues(double rob, double price, Currency currency, Good good, GoodUnit unit, Tank tank, Scrap scrap, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateTank(tank, scrap, tankDomainService); this.validateGood(good, goodDomainService); this.validateGoodInTank(tank, good, scrap); this.validateGoodToBeUniqueInDetails(good, scrap); this.validateROB(rob); this.validatePrice(price); this.validateCurrency(currency, currencyDomainService); this.validateUnit(unit, goodUnitDomainService); this.validateGoodUnitInCompany(scrap.VesselInCompany.Company, good, unit); }
//================================================================================ public ScrapDetail UpdateDetail(long scrapDetailId, double rob, double price, Currency currency, Good good, GoodUnit unit, Tank tank, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { var scrapDetailToUpdate = this.findDetail(scrapDetailId); scrapDetailToUpdate.Update(rob, price, currency, good, unit, tank, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); return scrapDetailToUpdate; }
//================================================================================ public PricingValue GetPricingValue(Company introducer, VesselInCompany vesselInCompany, DateTime startDate, Good good) { var partyType = this.GetCharteringPartyType(vesselInCompany); PricingValue result = null; switch (GetPricingType(introducer, vesselInCompany, startDate)) { case OffHirePricingType.CharterPartyBase: var charterPartyBasePricingValues = this.getCharterPartyBasedPricingValues(introducer, vesselInCompany, partyType, startDate); if (charterPartyBasePricingValues != null && charterPartyBasePricingValues.Count != 0) { //The offhire pricing in Charty Party is not mandatory. result = charterPartyBasePricingValues.SingleOrDefault(pv => pv.Good.Id == good.Id); } break; case OffHirePricingType.IssueBase: switch (partyType) { case CharteringPartyType.ShipOwner: var charterInOffhire = this.GetRelevantCharterInOffhire(introducer, vesselInCompany, startDate); if (charterInOffhire == null) throw new ObjectNotFound("RelevantCharterInOffhire"); var relevantCharterInOffhireDetail = charterInOffhire.OffhireDetails.FirstOrDefault(od => od.Good.Id == good.Id); if (relevantCharterInOffhireDetail == null) throw new ObjectNotFound("RelevantCharterInOffhireDetail"); result = new PricingValue() { Currency = relevantCharterInOffhireDetail.Offhire.VoucherCurrency, Fee = relevantCharterInOffhireDetail.FeeInVoucherCurrency, Good = good }; break; case CharteringPartyType.Charterer: var voyage = voyageDomainService.GetVoyage(introducer, startDate); var issueBasePricingValues = this.GetIssueBasedPricingValues(voyage); if (issueBasePricingValues == null || issueBasePricingValues.Count == 0) throw new ObjectNotFound("IssueBased Pricing for Vessel not found."); var issueBasePricingValue = issueBasePricingValues.SingleOrDefault(pv => pv.Good.Id == good.Id); if (issueBasePricingValue == null) throw new ObjectNotFound("IssueBased Pricing for Good " + good.Name + " not found."); result = issueBasePricingValue; break; default: throw new InvalidArgument("PartyType"); } break; default: throw new InvalidArgument("PricingReferenceType"); } if (result != null && result.Fee.HasValue && result.Currency == null) throw new InvalidArgument("Pricing Value has Fee but no currency."); return result; }
public GoodDto MapToModel(Good entity) { throw new NotImplementedException(); }
//================================================================================ internal void Update(double rob, double price, Currency currency, Good good, GoodUnit unit, Tank tank, ITankDomainService tankDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService) { this.validateValues(rob, price, currency, good, unit, tank, this.Scrap, tankDomainService, currencyDomainService, goodDomainService, goodUnitDomainService); this.ROB = rob; this.Price = price; this.Currency = currency; this.Unit = unit; if (!this.isScrapSubmitRejected.IsSatisfiedBy(this.Scrap)) { this.Good = good; this.Tank = tank; } }
//================================================================================ private void validateFeeInVoucherCurrency(decimal feeInVoucherCurrency, Offhire offhire, Good good, IOffhireDomainService offhireDomainService, ICurrencyDomainService currencyDomainService) { if (feeInVoucherCurrency < 0) throw new BusinessRuleException("", string.Format("Fee In Voucher Currency is negative for '{0}'.", good.Name)); var pricingValue = offhireDomainService.GetPricingValue(offhire.Introducer, offhire.VesselInCompany, offhire.StartDateTime, good); switch (offhire.PricingReference.Type) { case OffHirePricingType.CharterPartyBase: if (pricingValue != null && pricingValue.Fee.HasValue && pricingValue.Currency != null) { var charterPartyConvertedOffhireFee = currencyDomainService.ConvertPrice(pricingValue.Fee.Value, pricingValue.Currency.Id, offhire.VoucherCurrencyId, offhire.VoucherDate); if (feeInVoucherCurrency != charterPartyConvertedOffhireFee) throw new BusinessRuleException("", string.Format("The Offhire Fee for Good '{0}' is invlaid.", good.Name)); } break; case OffHirePricingType.IssueBase: if (pricingValue == null || !pricingValue.Fee.HasValue || pricingValue.Currency == null) throw new BusinessRuleException("", string.Format("IssueBased Pricing for Good '{0}' not found.", good.Name)); var issueBaseConvertedOffhireFee = currencyDomainService.ConvertPrice(pricingValue.Fee.Value, pricingValue.Currency.Id, offhire.VoucherCurrencyId, offhire.VoucherDate); if (feeInVoucherCurrency != issueBaseConvertedOffhireFee) throw new BusinessRuleException("", string.Format("The Offhire Fee for Good '{0}' is invlaid.", good.Name)); break; default: throw new InvalidArgument("PricingReferenceType"); } }