Exemplo n.º 1
0
        public ScheduledEmail CreatScheduledEmail(string fromAddress, string fromName, string toAddress, string ccAddress, string bccAddress, string subject, string content, bool isHtml, ScheduledEmailType type, long personId)
        {
            var person         = _personRepository.Get(personId);
            var scheduledEmail = new ScheduledEmail()
            {
                SchFromAddress     = fromAddress,
                SchFromName        = fromName,
                SchToEmailAddress  = toAddress,
                SchCcEmailAddress  = ccAddress,
                SchBccEmailAddress = bccAddress,
                SchSubject         = subject,
                SchContent         = content,
                SchFailureCount    = 0,
                SchReady           = true,
                SchEmailed         = false,
                SchSendAt          = DateTime.Now,
                SchType            = type,
                SchIsHtml          = isHtml,
                Person             = person,
                CreateDate         = DateTime.Now,
                ModifiedDate       = DateTime.Now
            };

            using (var transaction = _scheduledEmailRepository.Session.BeginTransaction())
            {
                _scheduledEmailRepository.SaveOrUpdate(scheduledEmail);
                transaction.Commit();
            }

            return(scheduledEmail);
        }
        //[ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            ScheduledEmail scheduledEmail = db.ScheduledEmails.Find(id);

            db.ScheduledEmails.Remove(scheduledEmail);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        /// <summary>
        ///     Schedules the email.
        /// </summary>
        /// <param name="recipient">The recipient.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="body">The body.</param>
        /// <returns>
        ///     A scheduled email.
        /// </returns>
        public IScheduledEmail ScheduleEmail(string recipient, string subject, string body)
        {
            var scheduledEmail = new ScheduledEmail {
                RecipientAddress = recipient, ScheduledDateTime = DateTime.UtcNow, Subject = subject, Body = body
            };

            _databaseContext.ScheduledEmails.Insert(scheduledEmail);
            return(scheduledEmail);
        }
 //[ValidateAntiForgeryToken]
 public ActionResult Edit([Bind(Include = "Id,CompanyId,Subject,Email,Body,Status,CreatedAt,UpdatedAt")] ScheduledEmail scheduledEmail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(scheduledEmail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", scheduledEmail.CompanyId);
     return(View(scheduledEmail));
 }
Exemplo n.º 5
0
        public void Process(ScheduledEmail scheduledEmail)
        {
            var emailMessage = new EmailMessage
            {
                From       = new MailAddress(scheduledEmail.SchFromAddress, string.IsNullOrEmpty(scheduledEmail.SchFromName) ? "NIHApp Admin" : scheduledEmail.SchFromName),
                Subject    = scheduledEmail.SchSubject,
                Body       = scheduledEmail.SchContent,
                IsBodyHtml = scheduledEmail.SchIsHtml
            };

            foreach (var toEmail in scheduledEmail.ToEmailAddressList.Where(toEmail => !string.IsNullOrWhiteSpace(toEmail)))
            {
                emailMessage.To.Add(new MailAddress(toEmail));
            }

            foreach (var ccEmail in scheduledEmail.CcEmailAddressList.Where(ccEmail => !string.IsNullOrWhiteSpace(ccEmail)))
            {
                emailMessage.CC.Add(new MailAddress(ccEmail));
            }

            foreach (var bccEmail in scheduledEmail.BccEmailAddressList.Where(bccEmail => !string.IsNullOrWhiteSpace(bccEmail)))
            {
                emailMessage.Bcc.Add(new MailAddress(bccEmail));
            }

            try
            {
                var emailSendResponse = _emailNotificationService.Send(emailMessage);
                if (emailSendResponse.IsSuccess)
                {
                    scheduledEmail.SchEmailed = true;
                }
                else
                {
                    throw emailSendResponse.LastException;
                }
            }
            catch (Exception emailException)
            {
                scheduledEmail.SchFailureCount++;
                scheduledEmail.SchLastFailureReason = emailException.Message;
                if (scheduledEmail.SchFailureCount > MaxFailureCount)
                {
                    scheduledEmail.SchReady = false;
                }
                scheduledEmail.SchEmailed = false;
            }

            using (var transaction = _scheduledEmailRepository.Session.BeginTransaction())
            {
                _scheduledEmailRepository.SaveOrUpdate(scheduledEmail);
                transaction.Commit();
            }
        }
Exemplo n.º 6
0
        public void Create(Auction model)
        {
            this._repository.Add(model);
            Save();

            AuctionIndexService.AddToIndex(model);

            int    eligiblePeriodInMinutes = 0;
            string tmp = $"{XCarsConfiguration.XMinutesAuctionFinishEmailEligiblePeriod}";

            int.TryParse(tmp, out eligiblePeriodInMinutes);

            ScheduledEmail email = new ScheduledEmail()
            {
                DateScheduled = DateTime.Now,
                DateDue       = model.Deadline,
                //StatusID = 1,
                To           = model.Auto.User.Email,
                Subject      = "Subject1",
                Body         = "Text1",
                ObjectTypeID = 2,
                ObjectID     = model.ID
            };

            email.DateEligible = email.DateDue.AddMinutes(eligiblePeriodInMinutes);
            ScheduledEmailService.Create(email);

            int minutes = 0;

            tmp = $"{XCarsConfiguration.XMinutesRemaingToAuctionDeadline}";
            int.TryParse(tmp, out minutes);

            eligiblePeriodInMinutes = 0;
            tmp = $"{XCarsConfiguration.XMinutesRemainingAuctionFinishEmailEligiblePeriod}";
            int.TryParse(tmp, out eligiblePeriodInMinutes);

            ScheduledEmail email2 = new ScheduledEmail()
            {
                DateScheduled = DateTime.Now,
                DateDue       = model.Deadline.AddMinutes(-1 * minutes),
                //StatusID = 1,
                To           = model.Auto.User.Email,
                Subject      = "Subject1",
                Body         = "Text1",
                ObjectTypeID = 3,
                ObjectID     = model.ID
            };

            email2.DateEligible = email2.DateDue.AddMinutes(eligiblePeriodInMinutes);
            ScheduledEmailService.Create(email2);
        }
        // GET: ScheduledEmails/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ScheduledEmail scheduledEmail = db.ScheduledEmails.Find(id);

            if (scheduledEmail == null)
            {
                return(HttpNotFound());
            }
            return(View(scheduledEmail));
        }
Exemplo n.º 8
0
        public void Add(int companyId, string subject, string body, string emailAddress)
        {
            ScheduledEmail email = new ScheduledEmail
            {
                CompanyId = companyId,
                Subject   = subject,
                Body      = body,
                Email     = emailAddress,
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now
            };

            _db.ScheduledEmails.Add(email);
            _db.SaveChanges();
        }
        // GET: ScheduledEmails/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ScheduledEmail scheduledEmail = db.ScheduledEmails.Find(id);

            if (scheduledEmail == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", scheduledEmail.CompanyId);
            return(View(scheduledEmail));
        }
Exemplo n.º 10
0
        public void TestScheduledEmail()
        {
            // arrange
            var email = new ScheduledEmail {
                RecipientAddress = "*****@*****.**", Body = "body", ScheduledDateTime = Truncate(DateTime.UtcNow), FailureReason = "failure", Subject = "subject"
            };

            // act
            var result = RunTest(email, _databaseContext.ScheduledEmails, x => ((ScheduledEmail)x).Id);

            // assert
            result.Body.ShouldBe(email.Body);
            result.RecipientAddress.ShouldBe(email.RecipientAddress);
            result.ScheduledDateTime.ShouldBe(email.ScheduledDateTime);
            result.Subject.ShouldBe(email.Subject);
            result.FailureReason.ShouldBe(email.FailureReason);
        }