Exemplo n.º 1
0
        public ActionResult Contact()
        {
            List <Schedule> schedules = new List <Schedule>();

            ViewBag.Message = "Your contact page.";


            EveryXMonthsSchedule monthly = new EveryXMonthsSchedule
            {
                Name            = "Prueba",
                MonthsBetween   = 2, //Cada dos meses
                TimeOfDay       = new TimeSpan(19, 30, 0),
                DayOfMonth      = 20,
                SchedulingRange = new Period(DateTime.Today, new DateTime(2020, 07, 20)),
            };

            schedules.Add(monthly);

            CalendarGenerator         generator    = new CalendarGenerator();
            Period                    period       = new Period(DateTime.Today, new DateTime(2020, 07, 20));
            IEnumerable <Appointment> appointments = generator.GenerateCalendar(period, schedules);

            return(View());
        }
        private void generateAppoiment(ViewModelActividadCumplimiento model, int idActcumplimiento)
        {
            //// se asigna fecha inicial a la fecha final para tener solo una fecha de ejecucion
            //model.FechaFinal = model.FechaInicial;
            List <Schedule> schedules = new List <Schedule>();

            if (model.Frecuencia_desc == "norepeat")
            {
                SingleSchedule single1 = new SingleSchedule
                {
                    Name      = model.NombreActividad,
                    TimeOfDay = model.hora, //new TimeSpan(19, 30, 0),
                    Date      = model.FechaInicial.Date
                };
                schedules.Add(single1);
            }
            else if (model.Frecuencia_desc == "daily")
            {
                SimpleRepeatingSchedule simple = new SimpleRepeatingSchedule
                {
                    Name            = model.NombreActividad,
                    TimeOfDay       = model.hora,//new TimeSpan(10, 0, 0),
                    SchedulingRange = new Period(model.FechaInicial.Date, model.FechaFinal.Date),
                    //DaysBetween = model.period
                };
                schedules.Add(simple);
            }
            else if (model.Frecuencia_desc == "weekly")
            {
                WeeklySchedule weekly = new WeeklySchedule
                {
                    Name            = model.NombreActividad,
                    TimeOfDay       = model.hora,//TimeSpan(8, 0, 0),
                    SchedulingRange = new Period(model.FechaInicial.Date, model.FechaFinal.Date),
                };

                //Seteamos loas dias de la semana seleccionados.
                int i = 0;
                List <DayOfWeek> dayOfWeeks = new List <DayOfWeek>();
                if (model.weekly_0 != null)
                {
                    dayOfWeeks.Add(DayOfWeek.Monday);
                    i++;
                }

                if (model.weekly_1 != null)
                {
                    dayOfWeeks.Add(DayOfWeek.Tuesday);
                    i++;
                }

                if (model.weekly_2 != null)
                {
                    dayOfWeeks.Add(DayOfWeek.Wednesday);
                    i++;
                }

                if (model.weekly_3 != null)
                {
                    dayOfWeeks.Add(DayOfWeek.Thursday);
                    i++;
                }

                if (model.weekly_4 != null)
                {
                    dayOfWeeks.Add(DayOfWeek.Friday);
                    i++;
                }

                if (model.weekly_5 != null)
                {
                    dayOfWeeks.Add(DayOfWeek.Saturday);
                    i++;
                }

                if (model.weekly_6 != null)
                {
                    dayOfWeeks.Add(DayOfWeek.Sunday);
                    i++;
                }

                weekly.SetDays(dayOfWeeks);

                schedules.Add(weekly);
            }
            else if (model.Frecuencia_desc == "monthly")
            {
                MonthlySchedule monthly = new MonthlySchedule
                {
                    Name            = model.NombreActividad,
                    TimeOfDay       = model.hora,//TimeSpan(8, 0, 0),
                    DayOfMonth      = model.period,
                    SchedulingRange = new Period(model.FechaInicial.Date, model.FechaFinal.Date),
                };
                schedules.Add(monthly);
            }
            else if (model.Frecuencia_desc == "bimestral")
            {
                EveryXMonthsSchedule everyxMonths = new EveryXMonthsSchedule
                {
                    Name            = model.NombreActividad,
                    MonthsBetween   = 2, //Cada dos meses
                    TimeOfDay       = model.hora,
                    DayOfMonth      = model.period,
                    SchedulingRange = new Period(model.FechaInicial.Date, model.FechaFinal.Date),
                };
                schedules.Add(everyxMonths);
            }
            else if (model.Frecuencia_desc == "trimestral")
            {
                EveryXMonthsSchedule everyxMonths = new EveryXMonthsSchedule
                {
                    Name            = model.NombreActividad,
                    MonthsBetween   = 3, //Cada tres meses
                    TimeOfDay       = model.hora,
                    DayOfMonth      = model.period,
                    SchedulingRange = new Period(model.FechaInicial.Date, model.FechaFinal.Date),
                };
                schedules.Add(everyxMonths);
            }
            else if (model.Frecuencia_desc == "semestral")
            {
                EveryXMonthsSchedule everyxMonths = new EveryXMonthsSchedule
                {
                    Name            = model.NombreActividad,
                    MonthsBetween   = 6, //Cada Seis meses
                    TimeOfDay       = model.hora,
                    DayOfMonth      = model.period,
                    SchedulingRange = new Period(model.FechaInicial.Date, model.FechaFinal.Date),
                };
                schedules.Add(everyxMonths);
            }

            CalendarGenerator         generator    = new CalendarGenerator();
            Period                    period       = new Period(model.FechaInicial.Date, model.FechaFinal.Date);
            IEnumerable <Appointment> appointments = generator.GenerateCalendar(period, schedules);

            foreach (var app in appointments)
            {
                db.Tb_ProgamacionTareas.Add(
                    new ProgamacionTareas
                {
                    ActiCumplimiento_Id = idActcumplimiento,
                    Descripcion         = app.Name,
                    //FechaHora = new DateTime(model.FechaInicial.Year, model.FechaInicial.Month, model.FechaInicial.Day, model.hora.Hours, model.hora.Minutes, model.hora.Seconds),
                    FechaHora  = app.Time,
                    Estado     = true,
                    Finalizada = false,
                }
                    );
            }
            db.SaveChanges();
        }