public ListCollection <AirWaybillListItem> List(int take, int skip, long?brokerId, long?senderUserId, string language) { var data = _awbs.GetRange(take, skip, brokerId, senderUserId); var ids = data.Select(x => x.Id).ToArray(); var aggregates = _awbs.GetAggregate(ids).ToDictionary(x => x.AirWaybillId, x => x); var states = _states.Get(language); var currentCulture = CultureProvider.GetCultureInfo(); var awbFiles = GetFileInfo(ids, AwbFileType.AWB); var packingFiles = GetFileInfo(ids, AwbFileType.Packing); var drawFiles = GetFileInfo(ids, AwbFileType.Draw); var gtdFiles = GetFileInfo(ids, AwbFileType.GTD); var gtdAddFiles = GetFileInfo(ids, AwbFileType.GTDAdditional); var invoiceFiles = GetFileInfo(ids, AwbFileType.Invoice); var otherFiles = GetFileInfo(ids, AwbFileType.Other); var items = data.Select(x => new AirWaybillListItem { Id = x.Id, PackingFiles = GetFileInfo(packingFiles, x.Id), InvoiceFiles = GetFileInfo(invoiceFiles, x.Id), State = new ApplicationStateModel { StateName = states[x.StateId].LocalizedName, StateId = x.StateId }, AWBFiles = GetFileInfo(awbFiles, x.Id), OtherFiles = GetFileInfo(otherFiles, x.Id), ArrivalAirport = x.ArrivalAirport, Bill = x.Bill, CreationTimestampLocalString = LocalizationHelper.GetDate(x.CreationTimestamp, currentCulture), DateOfArrivalLocalString = LocalizationHelper.GetDate(x.DateOfArrival, currentCulture), DateOfDepartureLocalString = LocalizationHelper.GetDate(x.DateOfDeparture, currentCulture), StateChangeTimestampLocalString = LocalizationHelper.GetDate(x.StateChangeTimestamp, currentCulture), DepartureAirport = x.DepartureAirport, GTD = x.GTD, GTDAdditionalFiles = GetFileInfo(gtdAddFiles, x.Id), GTDFiles = GetFileInfo(gtdFiles, x.Id), DrawFiles = GetFileInfo(drawFiles, x.Id), TotalCount = aggregates[x.Id].TotalCount, TotalWeight = aggregates[x.Id].TotalWeight, AdditionalCost = x.AdditionalCost, TotalCostOfSenderForWeight = x.TotalCostOfSenderForWeight, BrokerCost = x.BrokerCost, CustomCost = x.CustomCost, FlightCost = x.FlightCost, IsActive = x.IsActive }).ToArray(); var total = _awbs.Count(brokerId, senderUserId); return(new ListCollection <AirWaybillListItem> { Data = items, Total = total }); }
private void OnSetAwb(byte[] bytes, CultureInfo culture, IDictionary <string, string> localizedData) { var awbId = _serializer.Deserialize <long>(bytes); var awb = _awbs.Get(awbId).Single(); var aggregate = _awbs.GetAggregate(new[] { awb.Id }).Single(); Add(localizedData, "DepartureAirport", awb.DepartureAirport); Add(localizedData, "DateOfDeparture", LocalizationHelper.GetDate(awb.DateOfDeparture, culture)); Add(localizedData, "ArrivalAirport", awb.ArrivalAirport); Add(localizedData, "DateOfArrival", LocalizationHelper.GetDate(awb.DateOfArrival, culture)); Add(localizedData, "TotalWeight", aggregate.TotalWeight.ToString("N2")); Add(localizedData, "TotalCount", aggregate.TotalCount.ToString("N2")); Add(localizedData, "TotalValue", aggregate.TotalValue.ToString("N2")); Add(localizedData, "TotalVolume", aggregate.TotalVolume.ToString("N2")); }
public ApplicationGroup[] Group(ApplicationListItem[] applications, OrderType[] groups, long?clientId = null, long?senderId = null, long?forwarderId = null, long?carrierId = null) { var awbIds = applications.Select(x => x.AirWaybillId ?? 0).Distinct().ToArray(); _airWaybills = _awbRepository.Get(awbIds).ToDictionary(x => x.Id, x => x); _awbAggregates = _awbRepository.GetAggregate(awbIds, clientId, senderId, forwarderId, carrierId) .ToDictionary(x => x.AirWaybillId, x => x); _countWithouAwb = _awbRepository.GetTotalCountWithouAwb(clientId, senderId, forwarderId, carrierId); _weightWithouAwb = _awbRepository.GetTotalWeightWithouAwb(clientId, senderId, forwarderId, carrierId); _docWeightWithouAwb = _awbRepository.GetTotalDocWeightWithouAwb(clientId, senderId, forwarderId, carrierId); _valueWithouAwb = _awbRepository.GetTotalValueWithouAwb(clientId, senderId, forwarderId, carrierId); _volumeWithouAwb = _awbRepository.GetTotalVolumeWithouAwb(clientId, senderId, forwarderId, carrierId); return(GroupImpl(applications, groups)); }
public void SetAwb(long applicationId, long?awbId) { if (awbId.HasValue) { var aggregate = _awbs.GetAggregate(new[] { awbId.Value }).First(); _editor.SetAirWaybill(applicationId, awbId.Value); _states.SetState(applicationId, aggregate.StateId); _events.Add(applicationId, EventType.SetAwb, EventState.Emailing, awbId.Value); } else { _editor.SetAirWaybill(applicationId, null); _states.SetState(applicationId, _config.CargoInStockStateId); } }
public IDictionary <string, string> Get(string language, EventDataForEntity eventData) { var awb = _awbs.Get(eventData.EntityId).Single(); var aggregate = _awbs.GetAggregate(new[] { awb.Id }).Single(); var culture = CultureInfo.GetCultureInfo(language); return(new Dictionary <string, string> { { "DepartureAirport", awb.DepartureAirport }, { "DateOfDeparture", LocalizationHelper.GetDate(awb.DateOfDeparture, culture) }, { "ArrivalAirport", awb.ArrivalAirport }, { "DateOfArrival", LocalizationHelper.GetDate(awb.DateOfArrival, culture) }, { "TotalWeight", aggregate.TotalWeight.ToString("N2") }, { "TotalCount", aggregate.TotalCount.ToString("N2") }, { "TotalValue", aggregate.TotalValue.ToString("N2") }, { "AirWaybill", awb.Bill }, { "TotalVolume", aggregate.TotalVolume.ToString("N2") }, { "SenderName", GetSenderName(awb) } }); }
public void Test_AwbRepository_GetAggregate() { var data11 = CreateApplicationData(TestConstants.TestClientId1); var data12 = CreateApplicationData(TestConstants.TestClientId1); var data21 = CreateApplicationData(TestConstants.TestClientId1); var data22 = CreateApplicationData(TestConstants.TestClientId1); var awbId1 = _awbs.Add(CreateAirWaybillData(), TestConstants.DefaultStateId, TestConstants.TestAdminUserId); var awbId2 = _awbs.Add(CreateAirWaybillData(), TestConstants.DefaultStateId, TestConstants.TestAdminUserId); var applications = _applicationEditor; var app11 = applications.Add(data11); var app12 = applications.Add(data12); var app21 = applications.Add(data21); var app22 = applications.Add(data22); applications.SetAirWaybill(app11, awbId1); applications.SetAirWaybill(app12, awbId1); applications.SetAirWaybill(app21, awbId2); applications.SetAirWaybill(app22, awbId2); var aggregates = _awbs.GetAggregate(new[] { awbId1, awbId2 }); aggregates.Count().ShouldBeEquivalentTo(2); var aggregate1 = aggregates.First(x => x.AirWaybillId == awbId1); aggregate1.TotalCount.ShouldBeEquivalentTo(data11.Count + data12.Count); aggregate1.TotalWeight.ShouldBeEquivalentTo(data11.Weight + data12.Weight); aggregate1.TotalVolume.ShouldBeEquivalentTo(data11.Volume + data12.Volume); aggregate1.TotalValue.ShouldBeEquivalentTo(data11.Value + data12.Value); var aggregate2 = aggregates.First(x => x.AirWaybillId == awbId2); aggregate2.TotalCount.ShouldBeEquivalentTo(data21.Count + data22.Count); aggregate2.TotalWeight.ShouldBeEquivalentTo(data21.Weight + data22.Weight); aggregate2.TotalVolume.ShouldBeEquivalentTo(data21.Volume + data22.Volume); aggregate2.TotalValue.ShouldBeEquivalentTo(data21.Value + data22.Value); }