Ejemplo n.º 1
0
        public Example()
        {
            // repo that should have our CRUD operations for schedules
            // (currently only implements Create and Read)
            Repository repo = new FakeRepository();

            // create our new schedule that will be persisted
            var schedule = new DbSchedule()
            {
                Id       = 1,
                Schedule = new WeeklySchedule()
                {
                    Frequency = 2,
                    Monday    = true,
                    Friday    = true
                }
            };

            // create the schedule in our repository
            repo.Create(schedule);

            // now read it back out
            schedule = repo.Read(1);

            // test the occurrences; it should produce ~2 occurrences
            var now = DateTime.Now;
            var end = now.AddMonths(2);

            foreach (var d in schedule.Schedule.GetOccurrences(now, now.AddMonths(1)).TakeWhile <DateTime>(dt => dt <= end))
            {
                Console.WriteLine(d);
            }
        }
Ejemplo n.º 2
0
        public Example()
        {
            // repo that should have our CRUD operations for schedules
            // (currently only implements Create and Read)
            Repository repo = new FakeRepository();

            // create our new schedule that will be persisted
            var schedule = new DbSchedule()
            {
                Id = 1,
                Schedule = new WeeklySchedule()
                {
                    Frequency = 2,
                    Monday = true,
                    Friday = true
                }
            };

            // create the schedule in our repository
            repo.Create(schedule);

            // now read it back out
            schedule = repo.Read(1);

            // test the occurrences; it should produce ~2 occurrences
            var now = DateTime.Now;
            var end = now.AddMonths(2);
            foreach (var d in schedule.Schedule.GetOccurrences(now, now.AddMonths(1)).TakeWhile<DateTime>(dt => dt <= end))
                Console.WriteLine(d);
        }
Ejemplo n.º 3
0
        public virtual void Create(DbSchedule schedule)
        {
            using (var conn = new SqlConnection("connection string"))
            {
                using (var cmd = conn.CreateCommand())
                {
                    // assume triggers update date created and modified
                    cmd.CommandText = @"INSERT INTO [Schedules] (Id, Frequency) VALUES (@Id, @Frequency)";
                    cmd.Parameters.AddWithValue("Id", schedule.Id);
                    cmd.Parameters.AddWithValue("Frequency", schedule.Schedule.Frequency);
                    cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("Id", schedule.Id);

                    // now commit the correct ID into the correct table
                    if (schedule.Schedule is DailySchedule)
                    {
                        cmd.CommandText = "INSERT INTO [ScheduleDay] (Id) VALUES (@Id)";
                    }
                    else if (schedule.Schedule is WeeklySchedule)
                    {
                        var week = (WeeklySchedule)schedule.Schedule;
                        cmd.CommandText = "INSERT INTO [ScheduleWeek] (Id, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) VALUES (@Id, @Monday, @Tuesday, @Wednesday, @Thursday, @Friday, @Saturday, @Sunday)";
                        cmd.Parameters.AddWithValue("@Monday", week.Monday);
                        cmd.Parameters.AddWithValue("@Tuesday", week.Tuesday);
                        cmd.Parameters.AddWithValue("@Wednesday", week.Wednesday);
                        cmd.Parameters.AddWithValue("@Thursday", week.Thursday);
                        cmd.Parameters.AddWithValue("@Friday", week.Friday);
                        cmd.Parameters.AddWithValue("@Saturday", week.Saturday);
                        cmd.Parameters.AddWithValue("@Sunday", week.Sunday);
                    }
                    else if (schedule.Schedule is MonthlyDaySchedule)
                    {
                        cmd.CommandText = "INSERT INTO [ScheduleMonthByDay] (Id) VALUES (@Id)";
                    }
                    else if (schedule.Schedule is MonthlySchedule)
                    {
                        cmd.CommandText = "INSERT INTO [ScheduleMonth] (Id) VALUES (@Id)";
                    }
                    else if (schedule.Schedule is YearlySchedule)
                    {
                        cmd.CommandText = "INSERT INTO [ScheduleYear] (Id) VALUES (@Id)";
                    }

                    cmd.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 4
0
        public virtual void Create(DbSchedule schedule)
        {
            using (var conn = new SqlConnection("connection string"))
            {
                using (var cmd = conn.CreateCommand())
                {
                    // assume triggers update date created and modified
                    cmd.CommandText = @"INSERT INTO [Schedules] (Id, Frequency) VALUES (@Id, @Frequency)";
                    cmd.Parameters.AddWithValue("Id", schedule.Id);
                    cmd.Parameters.AddWithValue("Frequency", schedule.Schedule.Frequency);
                    cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("Id", schedule.Id);

                    // now commit the correct ID into the correct table
                    if (schedule.Schedule is DailySchedule)
                        cmd.CommandText = "INSERT INTO [ScheduleDay] (Id) VALUES (@Id)";
                    else if (schedule.Schedule is WeeklySchedule)
                    {
                        var week = (WeeklySchedule)schedule.Schedule;
                        cmd.CommandText = "INSERT INTO [ScheduleWeek] (Id, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) VALUES (@Id, @Monday, @Tuesday, @Wednesday, @Thursday, @Friday, @Saturday, @Sunday)";
                        cmd.Parameters.AddWithValue("@Monday", week.Monday);
                        cmd.Parameters.AddWithValue("@Tuesday", week.Tuesday);
                        cmd.Parameters.AddWithValue("@Wednesday", week.Wednesday);
                        cmd.Parameters.AddWithValue("@Thursday", week.Thursday);
                        cmd.Parameters.AddWithValue("@Friday", week.Friday);
                        cmd.Parameters.AddWithValue("@Saturday", week.Saturday);
                        cmd.Parameters.AddWithValue("@Sunday", week.Sunday);
                    }
                    else if (schedule.Schedule is MonthlyDaySchedule)
                        cmd.CommandText = "INSERT INTO [ScheduleMonthByDay] (Id) VALUES (@Id)";
                    else if (schedule.Schedule is MonthlySchedule)
                        cmd.CommandText = "INSERT INTO [ScheduleMonth] (Id) VALUES (@Id)";
                    else if (schedule.Schedule is YearlySchedule)
                        cmd.CommandText = "INSERT INTO [ScheduleYear] (Id) VALUES (@Id)";

                    cmd.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 5
0
 public override void Create(DbSchedule schedule)
 {
     Console.WriteLine("Repository.Create({0})", schedule.Id);
     _schedule = schedule;
 }
Ejemplo n.º 6
0
 public override void Create(DbSchedule schedule)
 {
     Console.WriteLine("Repository.Create({0})", schedule.Id);
     _schedule = schedule;
 }