Пример #1
0
        public void Delete(int id)
        {
            using (var context = new DbGoogleContext())
            {
                var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(

                    new ClientSecrets
                {
                    ClientId     = "491606904456-nr7nscjo3l75na40kq939t35fd55i9o7.apps.googleusercontent.com",
                    ClientSecret = "xhc5pCiEoW54ch7aF_J8Ah69",
                },
                    new[] { CalendarService.Scope.Calendar },
                    "user",

                    CancellationToken.None).Result;
                try
                {
                    var service = new CalendarService(new BaseClientService.Initializer
                    {
                        HttpClientInitializer = credential,
                        ApplicationName       = "Calendar API Realtor",
                    });

                    CalendarListResource.ListRequest cal = service.CalendarList.List();
                    cal.MaxResults = 100;

                    var calresult = cal.Execute().Items;



                    foreach (CalendarListEntry entry in calresult)
                    {
                        EventsResource.ListRequest request = service.Events.List(entry.Id);
                        request.TimeMin      = Convert.ToDateTime("03/01/2019");
                        request.ShowDeleted  = false;
                        request.SingleEvents = true;
                        request.MaxResults   = 200;
                        request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;
                        Events eventss = request.Execute();
                    }
                    var    eid        = new DbGoogleContext().Content.Where(d => d.Id == id).FirstOrDefault().EventId;
                    String calendarId = "*****@*****.**";
                    String eventId    = eid;
                    var    delCal     = service.Events.Delete(calendarId, eventId);
                    delCal.SendNotifications = true;
                    delCal.Execute();

                    var removes = context.Content.Where(s => s.Id == id).FirstOrDefault();
                    context.Content.Remove(removes);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Пример #2
0
        public bool Post([FromBody] Content val)
        {
            bool state = false;

            using (var context = new DbGoogleContext())
            {
                var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new ClientSecrets
                {
                    ClientId     = "491606904456-nr7nscjo3l75na40kq939t35fd55i9o7.apps.googleusercontent.com",
                    ClientSecret = "xhc5pCiEoW54ch7aF_J8Ah69",
                },
                    new[] { CalendarService.Scope.Calendar },
                    "user",
                    CancellationToken.None).Result;

                try
                {
                    var service = new CalendarService(new BaseClientService.Initializer
                    {
                        HttpClientInitializer = credential,
                        ApplicationName       = "Calendar API Realtor",
                    });

                    CalendarListResource.ListRequest cal = service.CalendarList.List();
                    cal.MaxResults = 100;
                    var calresult = cal.Execute().Items;



                    foreach (CalendarListEntry entry in calresult)
                    {
                        EventsResource.ListRequest request = service.Events.List(entry.Id);
                        request.TimeMin      = Convert.ToDateTime("03/01/2015");
                        request.ShowDeleted  = false;
                        request.SingleEvents = true;
                        request.MaxResults   = 200;
                        request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;


                        Events events = request.Execute();
                    }



                    DateTime sDate = val.Start;

                    DateTime eDate = val.End;



                    var myEvent = new Event
                    {
                        Id          = val.EventId,
                        Summary     = val.Title,
                        Description = val.Description,
                        Location    = "Thailand",

                        Start = new EventDateTime()
                        {
                            DateTime = sDate,
                            TimeZone = "Asia/Colombo",
                        },
                        End = new EventDateTime()
                        {
                            DateTime = eDate,
                            TimeZone = "Asia/Colombo",
                        },
                        Attendees = new EventAttendee[] {
                            new EventAttendee()
                            {
                                Email = "*****@*****.**"
                            },
                            new EventAttendee()
                            {
                                Email = "*****@*****.**"
                            },
                        },
                        Reminders = new Event.RemindersData()
                        {
                            UseDefault = false,
                            Overrides  = new EventReminder[]
                            {
                                new EventReminder()
                                {
                                    Method = "email", Minutes = 24 * 60
                                },
                                new EventReminder()
                                {
                                    Method = "popup", Minutes = 10
                                },
                            }
                        }
                    };
                    String calendarId = "*****@*****.**";
                    EventsResource.InsertRequest singleEvent = service.Events.Insert(myEvent, calendarId);
                    singleEvent.SendNotifications = true;
                    singleEvent.Execute();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                context.Content.Add(val);
                context.SaveChanges();
                state = true;
            }

            return(state);
        }