Exemple #1
0
 /// <summary>
 /// Elimina un usuario ligado a un recordatorio
 /// </summary>
 /// <param name="entidad"></param>
 /// <returns></returns>
 public string EliminarUsuarioAdicional(recordatorios_usuarios_adicionales entidad)
 {
     try
     {
         Model context = new Model();
         recordatorios_usuarios_adicionales recordatorio = context.recordatorios_usuarios_adicionales
                                                           .First(i => i.nombre == entidad.nombre && i.id_recordatorio == entidad.id_recordatorio);
         recordatorio.activo = false;
         context.SaveChanges();
         return("");
     }
     catch (DbEntityValidationException ex)
     {
         var errorMessages = ex.EntityValidationErrors
                             .SelectMany(x => x.ValidationErrors)
                             .Select(x => x.ErrorMessage);
         var fullErrorMessage = string.Join("; ", errorMessages);
         return(fullErrorMessage.ToString());
     }
 }
Exemple #2
0
        /// <summary>
        /// Inserta los meetings en una tabla sql
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public void GetAllCalendar(string userId, string password)
        {
            try
            {
                List <datos.Model.recordatorios> list = new List <datos.Model.recordatorios>();
                service              = new ExchangeService(ExchangeVersion.Exchange2010);
                credentials          = new WebCredentials(userId, password);
                service.Credentials  = credentials;
                service.TraceEnabled = true;
                service.TraceFlags   = TraceFlags.All;
                service.Url          = new Uri("https://mail.migesa.com.mx/ews/exchange.asmx");
                service.AutodiscoverUrl(userId, RedirectionUrlValidationCallback);
                DateTime startDate = DateTime.Now.AddMonths(-6);
                DateTime endDate   = DateTime.Now.AddMonths(3);
                // Initialize the calendar folder object with only the folder ID.
                CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());

                // Set the start and end time and number of appointments to retrieve.
                CalendarView cView = new CalendarView(startDate.AddDays(-1), endDate.AddDays(1));

                // Limit the properties returned to the appointment's subject, start time, and end time.
                cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);

                // Retrieve a collection of appointments by using the calendar view.
                FindItemsResults <Microsoft.Exchange.WebServices.Data.Appointment> appointments = calendar.FindAppointments(cView);
                string      username        = (userId.Split('@')[0]);
                PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
                itempropertyset.RequestedBodyType = BodyType.Text;
                RecordatoriosCOM reco = new RecordatoriosCOM();
                int total_actual      = reco.GetRecords(username);
                if (total_actual != appointments.Items.Count)
                {
                }

                foreach (Microsoft.Exchange.WebServices.Data.Appointment a in appointments)
                {
                    a.Load(itempropertyset);
                    DateTime         fecha_inicio  = a.Start;
                    DateTime         fecha_fin     = a.End;
                    string           subject       = a.Subject == null ? "" : a.Subject.ToString();
                    string           organizer     = a.Organizer.Name == null ? "" : a.Organizer.Name.ToString();
                    RecordatoriosCOM recordatorios = new RecordatoriosCOM();
                    string           id            = a.Id.ToString();
                    List <recordatorios_usuarios_adicionales> list_Ad = new List <recordatorios_usuarios_adicionales>();
                    string nbody = a.Body.Text == null ? "" : a.Body.Text.ToString();
                    datos.Model.recordatorios e = new datos.Model.recordatorios();
                    string organizer_address    = a.Organizer.Address == null ? "" : a.Organizer.Address.ToString();
                    string body          = a.Body.Text == null ? "" : a.Body.Text.ToString();
                    string participantes = a.DisplayTo == null ? "" : a.DisplayTo.ToString();
                    string lugar         = a.Location == null ? "" : a.Location.ToString();
                    if (participantes != "")
                    {
                        string[] participantes_array = participantes.Split(';');
                        foreach (string part in participantes_array)
                        {
                            if (part.ToUpper() != organizer.ToUpper())
                            {
                                recordatorios_usuarios_adicionales rec = new recordatorios_usuarios_adicionales
                                {
                                    nombre = part,
                                    activo = true
                                };
                                list_Ad.Add(rec);
                            }
                        }
                    }
                    e.organizer                 = organizer;
                    e.organizer_address         = organizer_address;
                    e.key_appointment_exchanged = id;
                    e.fecha            = fecha_inicio;
                    e.fecha_end        = fecha_fin;
                    e.titulo           = subject;
                    e.usuario          = username;
                    e.descripcion      = body;
                    e.usuario_creacion = username;
                    e.location         = lugar;
                    bool caneled = e.titulo.Contains("Cancelada:") || a.IsCancelled;
                    e.activo = !caneled;
                    if (e.descripcion.Contains("https://connext.webex.com/join/sergio_gaytan"))
                    {
                        e.activo = e.activo;
                    }
                    int id_recordatorio = recordatorios.ExistAppointmentID(username, id, organizer, subject, fecha_inicio, fecha_fin);
                    e.id_recordatorio = id_recordatorio;
                    string vmensaje = id_recordatorio == 0 ?
                                      recordatorios.Agregar(e, list_Ad) :
                                      reco.Editar(e, list_Ad);
                }
            }
            catch (Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException obj)
            {
                exchangeInitialized = false;
            }
            catch (Exception ex)
            {
                exchangeInitialized = false;
            }
        }