public async Task <PLDeskDm> GetDailyPLTradeAsync(string deskId, DateTime businessDate)
        {
            try
            {
                var dailyPLInfos = await _profitLossRepository.GetDailyPLTradeAsync(deskId, businessDate);

                if (dailyPLInfos == null)
                {
                    return(dailyPLInfos);
                }
                foreach (var tradeDm in dailyPLInfos.DailyPLTrades)
                {
                    dailyPLInfos.TotalCleanPL += tradeDm.CleanPL;
                }
                return(dailyPLInfos);
            }
            catch (CustomDataException ex)
            {
                throw ex;
            }
            catch (InvalidOperationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public async Task <EmailResponseDm> SendEmail(string deskId, DateTime businessDate)
        {
            bool   isUpdated = false;
            string toEmail   = Configuration["toMail"];

            try
            {
                var plDetail = await _profitLossRepository.GetDailyPLTradeAsync(deskId, businessDate);

                var body = string.Format(Constants.EmailTemplate, plDetail.TotalPL, plDetail.DealerEstimate,
                                         plDetail.Variance, plDetail.ExplainedVariance, plDetail.UnExplainedVariance, plDetail.PLCommentary,
                                         plDetail.VarianceComentary);
                var         fromMail = Configuration["fromMail"];
                var         fromName = Configuration["fromName"];
                var         mailPwd  = Configuration["fromPwd"];
                MailMessage mail     = new MailMessage()
                {
                    From = new MailAddress(fromMail, fromName)
                };
                mail.To.Add(new MailAddress(toEmail));
                //mail.CC.Add(new MailAddress(_emailSettings.CcEmail));

                mail.Subject    = $"[{plDetail.BusinessDate.ToString("dd-MMM-yyyy")}]: P&L Report - {plDetail.Desk}";
                mail.Body       = body;
                mail.IsBodyHtml = true;
                mail.Priority   = MailPriority.High;

                //using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
                using (SmtpClient smtp = new SmtpClient(Configuration["mailClient"], Convert.ToInt32(Configuration["mailPort"])))
                {
                    smtp.Credentials = new NetworkCredential(fromMail, mailPwd);
                    smtp.EnableSsl   = true;
                    await smtp.SendMailAsync(mail);
                }

                isUpdated = await _profitLossRepository.UpdateFOEmail(deskId, businessDate);

                var emailresp = new EmailResponseDm
                {
                    Message   = "Email Sent Successfully!",
                    To        = toEmail,
                    IsSuccess = true
                };

                return(emailresp);
            }
            catch (Exception ex)
            {
                //do something here
                var emailresp = new EmailResponseDm
                {
                    Message   = "Email Failure!",
                    To        = toEmail,
                    IsSuccess = false
                };
                return(emailresp);
            }
        }
        public async Task <string> DownloadCsv(string deskId, DateTime date)
        {
            var plDetails = await _profitLossRepository.GetDailyPLTradeAsync(deskId, date);

            var deskData = _mapper.Map <PLDataExportDm>(plDetails);

            //var deskHR = CSVUtil<PLDataExportDm>.ConvertHeaderRow(deskData);
            var tradeHR = CSVUtil <DailyPLTradeDm> .ConvertHeaderRow(plDetails.DailyPLTrades[0]);

            //var finalHR = deskHR + "," + tradeHR + Environment.NewLine;
            //var dailyDeskCsv = CSVUtil<PLDataExportDm>.ConvertObjectToCSV(new List<PLDataExportDm> { deskData });
            var transactCsv = CSVUtil <DailyPLTradeDm> .ConvertObjectToCSV(plDetails.DailyPLTrades);

            //var finalDataCsv = finalHR + Environment.NewLine + dailyDeskCsv + "," + transactCsv;
            var finalDataCsv = tradeHR + Environment.NewLine + transactCsv;

            return(finalDataCsv);
        }