Beispiel #1
0
        public void Generate(GratsDBContext db)
        {
            var contacts = (from categoryContact in db.CategoryContacts
                            where categoryContact.CategoryID == ID &&
                            categoryContact.Contact.Birthday != null
                            select categoryContact.Contact).ToList();

            var now = DateTime.Now;

            foreach (var contact in contacts)
            {
                var birthday     = contact.Birthday.Value;
                var dispatchDate = new DateTime(
                    birthday.Year, birthday.Month, birthday.Day,
                    Time.Hours, Time.Minutes, Time.Seconds);
                dispatchDate = dispatchDate.AddYears(now.Year - dispatchDate.Year);
                if (dispatchDate < now)
                {
                    dispatchDate = dispatchDate.AddYears(1);
                }

                db.MessageTasks.Add(new MessageTask()
                {
                    CategoryID   = ID,
                    Contact      = contact,
                    DispatchDate = dispatchDate,
                    Status       = MessageTask.TaskStatus.New,
                });
            }

            db.SaveChanges();
        }
Beispiel #2
0
        public void Regenerate(GratsDBContext db)
        {
            var pendingTasks = from task in db.MessageTasks
                               where task.CategoryID == ID &&
                               (task.Status == MessageTask.TaskStatus.New ||
                                task.Status == MessageTask.TaskStatus.Retry)
                               select task;

            db.MessageTasks.RemoveRange(pendingTasks);

            Generate(db);
        }