Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Removing any mail lists which are not confirmed and over 28 days old");

            var monthsOld = DateTime.Now.AddDays(-28);

            var dc = new Stage_Plan.Dal.StageplanEntities();

            foreach (var mail in dc.MailingLists)
            {
                if (mail.IsConfirmed)
                {
                    continue;
                }

                if (mail.DateOptInRequest < monthsOld)
                {
                    dc.MailingLists.Remove(mail);
                }
            }

            try
            {
                dc.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed...");
                Console.WriteLine(e.Message);
                throw;
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Deleting old stage plans from stage-plan.com");
            var dc = new Stage_Plan.Dal.StageplanEntities();

            Console.WriteLine("Deprecate older than 28 days");

            var dateNow         = DateTime.Now.AddDays(-28);
            var allEntriesCount = dc.Stageplans.Count();
            var oldEntires      = (from s in dc.Stageplans
                                   where dateNow > s.CreationDate
                                   where s.IsDeprecated == false
                                   select s
                                   ).ToList();

            foreach (var item in oldEntires)
            {
                item.IsDeprecated = true;
                try
                {
                    dc.SaveChanges();
                }
                catch (Exception ex)
                {
                    var error = ex.ToString();
                    throw;
                }
            }


            Console.WriteLine("Deleting older than 3 months (84 days)");
            dateNow = DateTime.Now.AddDays(-84);

            oldEntires = (from s in dc.Stageplans
                          where dateNow > s.CreationDate
                          select s
                          ).ToList();

            foreach (var item in oldEntires)
            {
                dc.StageplanInstruments.RemoveRange(item.StageplanInstruments);
                dc.Stageplans.Remove(item);
                try
                {
                    dc.SaveChanges();
                }
                catch (Exception ex)
                {
                    var error = ex.ToString();
                    throw;
                }
            }
            Console.WriteLine(allEntriesCount - dc.Stageplans.Count() + " were deleted.");
            Console.WriteLine("Press a key to close");
            Console.ReadKey();
        }