public void Execute(IJobExecutionContext context)
        {
            try
            {
                var allCarList = _vehicleInfoService.GetAll();
                foreach (var item in allCarList)
                {
                    DateTime insectionTime = _vehicleInfoService.GetNextInspectionTime(item.VehicleTypeId, item.Plate, item.LastInspectionTime.HasValue ? 2 : 1, item.PurchaseDate);

                    int day = DateTime.Now.Subtract(insectionTime).Days;
                    if (day >= 0 && day <= 7)
                    {
                        _messageService.Add(new NotificationMessage
                        {
                            Body          = string.Format("您的下一次车检时间为{0},请按时车检!", insectionTime.ToString("yyyy-MM-dd")),
                            CheckTime     = insectionTime,
                            IsSending     = false,
                            Subject       = "车检提醒",
                            VehicleInfoId = item.OwnerId,
                            Email         = item.Owner.Email,
                            Status        = RecordStatus.Acvitiy
                        });
                    }
                }

                var list = _messageService.LoadAllNoSeding();

                ICollection <EmailMessage> mails = new List <EmailMessage>();
                foreach (var item in list)
                {
                    mails.Add(new EmailMessage
                    {
                        MessageBody = item.Body,
                        ToUser      = item.Email
                    });
                }
                SendEmail(mails);
            }
            catch (Exception ex)
            {
                Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex));
            }
        }
        public bool AddNotificationMessage(GenericNotificationViewModel model)
        {
            foreach (var item in model.IndividualRecipients)
            {
                var  senderDetails         = _userService.GetUserByUserGuid(model.CurrentUserGuid);
                var  link                  = model.RedirectUrl;
                Guid notificationBatchGuid = AddNotificationBatch(model);

                if (notificationBatchGuid != Guid.Empty)
                {
                    // Notification Templates
                    var notificationTemplate = _notificationTemplatesService.GetNotificationTemplateByKey(model.NotificationTemplateKey);
                    model.NotificationTemplatesDetail.ReceiverDisplayName = item.DisplayName;
                    model.NotificationTemplatesDetail.SubmittedByName     = senderDetails.DisplayName;
                    model.NotificationTemplatesDetail.RedirectUrlPath     = model.RedirectUrl;

                    var message = GetContentForNotify(notificationTemplate.Message, model.NotificationTemplatesDetail);
                    var subject = GetContentForNotify(notificationTemplate.Subject, model.NotificationTemplatesDetail);

                    var notificationMessage = new NotificationMessage
                    {
                        NotificationBatchGuid = notificationBatchGuid,
                        UserGuid          = item.UserGuid,
                        Subject           = subject,
                        Message           = message,
                        AdditionalMessage = "",
                        Status            = false,
                        UserResponse      = false,
                        NextAction        = model.CurrentDate,
                        CreatedOn         = model.CurrentDate,
                        CreatedBy         = model.CurrentUserGuid,
                    };
                    if (model.SendEmail)
                    {
                        _emailSender.SendEmailAsync(item.WorkEmail, item.DisplayName, subject, message);
                    }
                    return(_notificationMessageService.Add(notificationMessage));
                }
            }
            return(false);
        }