public async Task OnGet() { GoogleCredential googleCred = await _auth.GetCredentialAsync(); var google = new GoogleWrapper(googleCred); DriveFiles = await google.GetDriveFiles(); Calendars = await google.GetCalendars(); }
public async Task <ActionResult> CreateFree(Models.Request.RequestVMFree requestVM) { if (ModelState.IsValid) { try { TravelerProfile tp = await ProfileManager.LoadUserAndTravelerProfile(User); tp = await ProfilesController.LoadProfile(tp.ID); Models.Request.Request rq = new Models.Request.Request(tp.ID, requestVM); //AccommodationModel is generated here rq.Accommodation = new Models.Accommodation.Accommodation(0, requestVM.BedRooms); if (!rq.Accommodation.Verified) { throw new Exception("Accommodation abstraction failed"); } // get locationIDs List <Models.Accommodation.Likibu.Destination> dest = await Likibu.LikibuAccess.DestinationRequest(requestVM.Location, tp.Attributes.Language, 1.ToString()); //Models.Accommodation.Likibu.DestinationDetail destDetail = await Likibu.LikibuAccess.DestinationDetailRequest();// Todo add LatLng rq.Accommodation.AccomProfile = new Models.Accommodation.AccommodationProfile(dest.FirstOrDefault(), requestVM.BedRooms, requestVM.Link); if (!requestVM.Lat.HasValue || !requestVM.Lng.HasValue) { float[] lnglat = new float[2]; lnglat = GoogleWrapper.LongLat2DoubleAr(await GoogleWrapper.GetGeolocation(requestVM.Location)); rq.Accommodation.AccomProfile.Lng = lnglat[0]; rq.Accommodation.AccomProfile.Lat = lnglat[1]; } else { rq.Accommodation.AccomProfile.Lng = requestVM.Lng.Value; rq.Accommodation.AccomProfile.Lat = requestVM.Lat.Value; } using (var db = new ApplicationDbContext()) { db.Requests.Add(rq); await db.SaveChangesAsync(); } NotificationManager.AddNotification(NotificationType.Success, "Your request has been saved!"); return(RedirectToAction("Index", "Home")); } catch (Exception e) { NotificationManager.AddException(e); NotificationManager.AddNotification(NotificationType.Error, "Oops, something went wrong!"); } } return(View(requestVM)); }
static async Task Main(string[] args) { Console.WriteLine("This is DEMO application"); string clientSecretFileName = Environment.GetEnvironmentVariable("CLIENT_SECRET_FILENAME_PATH"); string demoStorageFileName = Environment.GetEnvironmentVariable("DEMOSTORAGE_FILENAME"); if (String.IsNullOrEmpty(clientSecretFileName)) { throw new ApplicationException("missing client secret filename"); } if (String.IsNullOrEmpty(demoStorageFileName)) { throw new ApplicationException("missing demostorage filename"); } if (!File.Exists(clientSecretFileName)) { throw new ApplicationException("Cannot find client_secret json file"); } byte[] clientSecret = File.ReadAllBytes(clientSecretFileName); var storage = new DemoStorage(demoStorageFileName); while (true) { string[] googleIDs = storage.GetGoogleIDs(); foreach (var googleID in googleIDs) { Console.WriteLine($"\n---> Processing user {googleID}"); string refreshToken = storage.GetRefreshToken(googleID); Console.WriteLine($"refresh_token: {refreshToken.Substring(0, 50)}..."); var google = new GoogleWrapper(refreshToken, clientSecret); (await google.GetDriveFiles()).Take(5).ToList().ForEach(x => Console.WriteLine($"File: {x.Name}")); (await google.GetCalendars()).Take(5).ToList().ForEach(x => Console.WriteLine($"Calendar: {x.Id}")); } Console.WriteLine("\n\nPress a key to continue"); Console.ReadKey(true); //Thread.Sleep(10 * 1000); } }