private IEnumerable<EmailMessage> GetEmailMessages(
			long templateId,
			IEnumerable<RecipientData> recipients,
			EventDataForEntity data,
			IReadOnlyDictionary<string, FileHolder[]> files,
			long? userId,
			EventType type)
		{
			var application = _applications.Get(data.EntityId);

			foreach(var recipient in recipients)
			{
				var localization = _templates.GetLocalization(templateId, recipient.Culture);

				if(localization == null)
				{
					continue;
				}

				var filesToSend = GetFiles(type, recipient, files);

				yield return GetEmailMessage(
					recipient.Email,
					recipient.Culture,
					localization,
					application,
					data.Data,
					type,
					filesToSend,
					userId);
			}
		}
		public RecipientData[] GetRecipients(EventType type, EventDataForEntity data)
		{
			var roles = _recipients.GetRecipientRoles(type);

			return roles.Length == 0
				? null
				: GetRecipients(roles, data).ToArray();
		}
		public RecipientData[] GetRecipients(EventType type, EventDataForEntity data)
		{
			var application = _applications.Get(data.EntityId);

			var roles = _recipients.GetRecipientRoles(type);

			return roles.Length == 0
				? null
				: GetRecipients(application, roles).ToArray();
		}
Exemple #4
0
		public IReadOnlyDictionary<string, FileHolder[]> GetFiles(
			EventType type, EventDataForEntity eventData, string[] languages)
		{
			switch(type)
			{
				case EventType.SetDateOfCargoReceipt:
				case EventType.SetTransitReference:
				case EventType.ApplicationCreated:
				case EventType.SetSender:
				case EventType.SetForwarder:
				case EventType.SetCarrier:
				case EventType.SetAwb:
				case EventType.ClientAdded:
				case EventType.AwbCreated:
					return null;

				case EventType.ApplicationSetState:
					return OnApplicationSetState(eventData, languages);

				case EventType.Calculate:
				case EventType.CalculationCanceled:
					return OnCalculation(eventData, languages);

				case EventType.BalanceDecreased:
				case EventType.BalanceIncreased:
					return OnBalance(eventData, languages);

				case EventType.CPFileUploaded:
				case EventType.InvoiceFileUploaded:
				case EventType.PackingFileUploaded:
				case EventType.SwiftFileUploaded:
				case EventType.DeliveryBillFileUploaded:
				case EventType.Torg12FileUploaded:
				case EventType.T1FileUploaded:
				case EventType.Ex1FileUploaded:
				case EventType.GTDFileUploaded:
				case EventType.GTDAdditionalFileUploaded:
				case EventType.AwbPackingFileUploaded:
				case EventType.AwbInvoiceFileUploaded:
				case EventType.AWBFileUploaded:
				case EventType.DrawFileUploaded:
				case EventType.OtherAwbFileUploaded:
				case EventType.OtherApplFileUploaded:
					return OnFileUploaded(eventData, languages);

				case EventType.SetBroker:
					return OnSetBroker(eventData, languages);

				default:
					throw new ArgumentOutOfRangeException("type");
			}
		}
		public IDictionary<string, string> Get(string language, EventDataForEntity eventData)
		{
			var client = _clients.Get(eventData.EntityId);

			var password = _serializer.Deserialize<string>(eventData.Data);

			return new Dictionary<string, string>
			{
				{ "ClientNic", client.Nic },
				{ "LegalEntity", client.LegalEntity },
				{ "Password", password },
				{ "Login", client.Login },
				{ "SenderName", GetSenderName(client) }
			};
		}
		public IDictionary<string, string> Get(string language, EventDataForEntity eventData)
		{
			var client = _clients.Get(eventData.EntityId);
			var paymentEvent = _serializer.Deserialize<PaymentEventData>(eventData.Data);
			var culture = CultureInfo.GetCultureInfo(language);
			var balance = _balance.GetBalance(client.ClientId);

			return new Dictionary<string, string>
			{
				{ "ClientBalance", balance.ToString("N2") },
				{ "Money", paymentEvent.Money.ToString("N2") },
				{ "Comment", paymentEvent.Comment },
				{ "ClientNic", client.Nic },
				{ "LegalEntity", client.LegalEntity },
				{ "Timestamp", LocalizationHelper.GetDate(paymentEvent.Timestamp, culture) },
				{ "SenderName", GetSenderName(client) }
			};
		}
		private IEnumerable<EmailMessage> GetEmailMessages(
			long templateId,
			IEnumerable<RecipientData> recipients,
			EventDataForEntity data,
			IReadOnlyDictionary<string, FileHolder[]> files,
			long? userId,
			IEnumerable<string> languages)
		{
			var localizations = GetLocalizationData(data, languages, templateId);

			var emailMessages = recipients.Select(
				x => GetEmailMessage(
					userId,
					x.Email,
					localizations[x.Culture],
					files != null ? files[x.Culture] : null));

			return emailMessages;
		}
		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) }
			};
		}
		private IEnumerable<RecipientData> GetRecipients(IEnumerable<RoleType> roles, EventDataForEntity data)
		{
			foreach(var role in roles)
			{
				switch(role)
				{
					case RoleType.Admin:
						{
							var recipients = _admins.GetAll()
								.Select(user => new RecipientData(user.Email, user.Language, RoleType.Admin));
							foreach(var recipient in recipients)
							{
								yield return recipient;
							}
						}
						break;

					case RoleType.Manager:
						{
							var recipients = _managers.GetAll()
								.Select(user => new RecipientData(user.Email, user.Language, RoleType.Manager));
							foreach(var recipient in recipients)
							{
								yield return recipient;
							}
						}
						break;

					case RoleType.Broker:
						var brokerId = _awbs.Get(data.EntityId).Single().BrokerId;
						if(brokerId.HasValue)
						{
							var broker = _brokers.Get(brokerId.Value);

							yield return new RecipientData(broker.Email, broker.Language, role);
						}

						break;

					case RoleType.Sender:
						foreach(var email in _awbs.GetSenderEmails(data.EntityId))
						{
							yield return new RecipientData(email.Email, email.Language, RoleType.Client);
						}

						break;

					case RoleType.Client:
						foreach(var emailData in _awbs.GetClientEmails(data.EntityId))
						{
							foreach(var email in EmailsHelper.SplitAndTrimEmails(emailData.Email))
							{
								yield return new RecipientData(email, emailData.Language, RoleType.Client);
							}
						}

						break;

					case RoleType.Forwarder:
						foreach(var email in _awbs.GetForwarderEmails(data.EntityId))
						{
							yield return new RecipientData(email.Email, email.Language, RoleType.Client);
						}

						break;

					case RoleType.Carrier:
						foreach(var email in _awbs.GetCarrierEmails(data.EntityId))
						{
							yield return new RecipientData(email.Email, email.Language, RoleType.Client);
						}

						break;

					default:
						throw new InvalidOperationException("Unknown role " + role);
				}
			}
		}
Exemple #10
0
		private IReadOnlyDictionary<string, FileHolder[]> OnSetBroker(EventDataForEntity eventData, string[] languages)
		{
			var queue = new Queue<FileHolder>();
			var packing = _awbFiles.GetPackingFile(eventData.EntityId);
			if(packing != null)
			{
				queue.Enqueue(packing);
			}

			var awbFile = _awbFiles.GetAWBFile(eventData.EntityId);
			if(awbFile != null)
			{
				queue.Enqueue(awbFile);
			}

			var files = queue.ToArray();

			return languages.ToDictionary(x => x, x => files);
		}
Exemple #11
0
		private IReadOnlyDictionary<string, FileHolder[]> OnFileUploaded(EventDataForEntity eventData, string[] languages)
		{
			var file = _serializer.Deserialize<FileHolder>(eventData.Data);

			return languages.ToDictionary(x => x, x => new[] { file });
		}
Exemple #12
0
		private IReadOnlyDictionary<string, FileHolder[]> OnCalculation(EventDataForEntity eventData, string[] languages)
		{
			var applicationId = eventData.EntityId;
			var application = _applications.Get(applicationId);
			var excels = _excel.GetExcels(application.ClientId, languages);

			return languages.ToDictionary(x => x, x => new[] { excels[x] });
		}
Exemple #13
0
		private IReadOnlyDictionary<string, FileHolder[]> OnBalance(EventDataForEntity eventData, string[] languages)
		{
			var clientId = eventData.EntityId;
			var excels = _excel.GetExcels(clientId, languages);

			return languages.ToDictionary(x => x, x => new[] { excels[x] });
		}
Exemple #14
0
		private IReadOnlyDictionary<string, FileHolder[]> OnApplicationSetState(
			EventDataForEntity eventData, string[] languages)
		{
			var applicationId = eventData.EntityId;
			var application = _applications.Get(applicationId);
			if(application == null)
			{
				throw new InvalidOperationException("Can't find application by id " + applicationId);
			}

			var allFiles = GeAllFiles(applicationId, application.AirWaybillId);

			return languages.ToDictionary(x => x, x => allFiles);
		}
		private Dictionary<string, EmailTemplateLocalizationData> GetLocalizationData(
			EventDataForEntity eventData,
			IEnumerable<string> languages,
			long templateId)
		{
			return languages.ToDictionary(
				x => x,
				language =>
				{
					var template = _templates.GetLocalization(templateId, language);

					var localizedData = _localizedHelper.Get(language, eventData);

					return new EmailTemplateLocalizationData
					{
						IsBodyHtml = template.IsBodyHtml,
						Subject = _textBuilder.GetText(template.Subject, language, localizedData),
						Body = _textBuilder.GetText(template.Body, language, localizedData)
					};
				});
		}