public async Task PerformReporting(OvernightSwapReportType reportType) { var invocationTime = GetInvocationTime(reportType); var from = reportType == OvernightSwapReportType.Daily ? _systemClock.UtcNow.Date.AddDays(-1) : _systemClock.UtcNow.Date.AddMonths(-1); var to = new DateTime(_systemClock.UtcNow.Year, _systemClock.UtcNow.Month, _systemClock.UtcNow.Day, invocationTime.Hours, invocationTime.Minutes, invocationTime.Seconds); var reportPeriodIndex = reportType == OvernightSwapReportType.Daily ? from.DayOfWeek.ToString() : from.Month.ToString("MMMM"); await _log.WriteInfoAsync(nameof(TradingReportService), nameof(PerformReporting), $"Report invoked for {reportPeriodIndex}, period from {from:s} to {to:s}"); var(clientIds, accounts, closedTrades, openPositions, pendingPositions, accountTransactions) = await GetDataForNotifications(reportType, to, from); //prepare notification models var notifications = clientIds.Select(x => PrepareNotification(reportType, from, to, x, closedTrades, openPositions, pendingPositions, accounts, accountTransactions)).ToList(); //retrieve emails var emails = (await _clientAccountClient.GetClientsByIdsAsync(clientIds)) .ToDictionary(x => x.Id, x => x.Email); if (reportType == OvernightSwapReportType.Daily ? _dailyNotificationsSettings.EmailNotificationEnabled : _monthlyNotificationsSettings.EmailNotificationEnabled) { await SendNotifications(reportType, notifications, emails); } else { await _log.WriteInfoAsync(nameof(TradingReportService), nameof(PerformReporting), $"Email notifications are disabled for {reportType.ToString()} reports."); } }
private async Task <List <KycStatusLogRecord> > GetKycStatusLogRecords(DateTime startDate, DateTime endDate) { ReportFilter f = new ReportFilter(); f.DatePeriod = new DatePeriod(); f.DatePeriod.StartDate = startDate; f.DatePeriod.EndDate = endDate; IEnumerable <IKycStatuschangeItem> items = await _kycStatusService.GetRecordsForPeriodAsync(f); if (items == null || items.Count() == 0) { return(new List <KycStatusLogRecord>()); } IEnumerable <Partner> partners = await _partnersService.GetPartnersAsync(); Dictionary <string, string> partnersDict = new Dictionary <string, string>(); foreach (Partner p in partners) { partnersDict[p.PublicId] = p.Name; } Dictionary <string, ClientAccountInformationModel> clients = null; clients = (await _clientAccountService.GetClientsByIdsAsync(items.Select(_ => _.ClientId).Distinct().ToArray())).ToDictionary(_ => _.Id, _ => _); var auditLogEntities = items.Select(item => { var status = (KycStatus)item.CurrentStatus; var previousStatus = (KycStatus)item.PreviousStatus; string kycOfficer; if (item != null && item.Changer != null && item.Changer.StartsWith(_boChanger)) { kycOfficer = item.Changer.Substring(_boChanger.Length); } else { return(null); } var partnerName = _lykkeWalletPartnerName; ClientAccountInformationModel client; if (clients.TryGetValue(item.ClientId, out client)) { if (!String.IsNullOrWhiteSpace(client.PartnerId)) { if (partnersDict.TryGetValue(client.PartnerId, out string name)) { partnerName = name; } else { partnerName = null; _log.WriteWarningAsync("GetKycStatusLogRecords", new { startDate, endDate }.ToJson(), $"Cannot find Partner with ID = {client.PartnerId}"); } } } return(new KycStatusLogRecord(item.ClientId, status, previousStatus, item.CreatedTime, kycOfficer, partnerName)); }).Where(item => item != null).ToList(); return(auditLogEntities); }