Exemplo n.º 1
0
        public void SendMail(AlertResponse response, NotificationTitleType type, decimal percentange = 0)
        {
            Notification n = new Notification();

            n.Id        = ObjectId.GenerateNewId();
            n.Style     = NotificationStyles.INFO.ToString();
            n.AccountId = response.Id;
            n.CreatedAt = DateTime.UtcNow;

            if (type == NotificationTitleType.PRICE_ABOWE || type == NotificationTitleType.PRICE_BELOW)
            {
                n.Message = string.Format("Exchange: {4}{0}Market: {5}{0}{0}Above Price: {1}{0}Saved Price: {2}{0}Below Price: {3}{0}{0}Current Price:{7}{0}{0}Date: {6:dd.MM.yyyy HH:mm} UTC",
                                          Environment.NewLine,
                                          response.Alert.AboveValue,
                                          response.Alert.SavedValue,
                                          response.Alert.BelowValue,
                                          response.Exchange.ExchangeName,
                                          response.Market.Code,
                                          DateTime.UtcNow,
                                          response.Market.Ticker.Last);
            }
            else if (type == NotificationTitleType.PERCENTANGE_ABOWE || type == NotificationTitleType.PERCENTANGE_BELOW)
            {
                n.Message = string.Format("Exchange: {4}{0}Market: {5}{0}Above Percent: % {1:0.00}{0}Saved Price: {2}{0}Below Percent: % {3:0.00}{0}{0}Current Price:{8}{0}Percentange:% {7:0.00}{0}{0}Date: {6:dd.MM.yyyy HH:mm} UTC",
                                          Environment.NewLine,
                                          response.Alert.AboveValue,
                                          response.Alert.SavedValue,
                                          response.Alert.BelowValue,
                                          response.Exchange.ExchangeName,
                                          response.Market.Code,
                                          DateTime.UtcNow,
                                          percentange,
                                          response.Market.Ticker.Last);
            }

            n.Title  = response.Market.Code + " is " + type.ToString();
            n.Type   = NotificationTypes.EMAIL.ToString();
            n.Repeat = 1;

            string displayName;

            if (string.IsNullOrEmpty(response.Name) && string.IsNullOrEmpty(response.Surname))
            {
                displayName = response.Email;
            }
            else
            {
                displayName = string.Format("{0} {1}", response.Name, response.Surname);
            }

            Response mailResponse = MailBL.GetInstance().SendMail(response.Email, n.Title, n.Message, displayName);

            if (mailResponse.IsSuccess)
            {
                n.CompletedAt   = DateTime.UtcNow;
                n.Status        = NotificationStatus.SENT.ToString();
                n.StatusMessage = mailResponse.Message;
            }
            else
            {
                n.Status        = NotificationStatus.HASERROR.ToString();
                n.StatusMessage = mailResponse.Message;
            }



            AccountBL.GetInstance().AddNotification(n);


            Console.WriteLine(n.Title + "---" + DateTime.Now);
        }
Exemplo n.º 2
0
 public Task SendMailAsync(AlertResponse response, NotificationTitleType type, decimal percentange = 0) => Task.Run(() => SendMail(response, type, percentange));