Beispiel #1
0
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            ServiceIsRunning = true;

            searchModelForNotifications  = new AdvertisementsSearchModelForNotifications();
            this.sharedPreferencesHelper = new SharedPreferencesHelper(Application.ApplicationContext);
            var bearerToken = (string)this.sharedPreferencesHelper.GetSharedPreference <string>(SharedPreferencesKeys.BEARER_TOKEN);

            this.advertisementItemService = new AdvertisementItemService(bearerToken);
            this.gpsLocationService       = new GpsLocationService(Application.ApplicationContext, null);

            DoWork();

            return(StartCommandResult.Sticky);
        }
        public bool CheckForNewAdvertisementsSinceLastCheck(string userId, AdvertisementsSearchModelForNotifications searchModel, bool currentLocation)
        {
            var coordinatesForSearchModel = coordinatesCalculator.GetCoordinatesForSearchingAdvertisements(searchModel.CoordinatesModels.Latitude, searchModel.CoordinatesModels.Longitude, searchModel.CoordinatesModels.MaxDistance);
            var lastUserCheckModel        = this.lastUsersChecksCacheService.GetLastTimeUserCheck(userId);
            var dateToCompare             = currentLocation ? lastUserCheckModel.LastAroundCurrentLocationCheckDate : lastUserCheckModel.LastAroundHomeLocationCheckDate;
            var advertisementsFromDbQuery = this.advertisementItemDbService.GetAdvertisementsFromDeclaredAreaSinceLastCheck(dateToCompare, userId, coordinatesForSearchModel);

            if (searchModel.CategoriesIds.Count > 0)
            {
                advertisementsFromDbQuery = advertisementsFromDbQuery.Where(a => searchModel.CategoriesIds.Contains(a.CategoryId));
            }
            if (searchModel.Sizes.Count > 0)
            {
                advertisementsFromDbQuery = advertisementsFromDbQuery.Where(a => searchModel.Sizes.Contains(a.Size));
            }
            var advertisements = advertisementsFromDbQuery.Take(1).ToList();

            this.lastUsersChecksCacheService.UpdateLastTimeUserCheckDate(userId, currentLocation);

            return(advertisements.Count > 0);
        }
 private void SetCheckingNewAdvertisementsAction(Context context)
 {
     checkingNewAdvertsAction = async() =>
     {
         try
         {
             searchModelForNotifications   = new AdvertisementsSearchModelForNotifications();
             this.appsettings              = SharedPreferencesHelper.GetAppSettings(this.context);
             this.advertisementItemService = new AdvertisementItemService(bearerToken);
             this.gpsLocationService       = new GpsLocationService(context.ApplicationContext, null);
             var coordinates = await CheckNewAdvertisementsAroundUserCurrentLocation();
             await CheckNewAdvertisementsAroundUserHomeLocation(coordinates);
         }
         catch
         {
         }
         finally
         {
             checkingNewAdvertsFinished = true;
         }
     };
 }
Beispiel #4
0
 public IActionResult CheckForNewAdvertisementsAroundHomeLocationSinceLastCheck([FromBody] AdvertisementsSearchModelForNotifications searchModel)
 {
     try
     {
         var userId = this.identityService.GetUserId(User.Identity);
         var foundedNewAdvertisements = this.advertisementItemService.CheckForNewAdvertisementsSinceLastCheck(userId, searchModel, false);
         return(Json(foundedNewAdvertisements));
     }
     catch (Exception exc)
     {
         Response.StatusCode = (int)HttpStatusCode.InternalServerError;
         logger.LogError("Wystąpił wyjątek w trakcie sprawdzania nowych ogłoszeń: " + exc);
         return(null);
     }
 }
Beispiel #5
0
        public async Task <bool> CheckForNewAdvertisementsAroundHomeLocationSinceLastCheck(AdvertisementsSearchModelForNotifications searchModel)
        {
            var stringContent = new StringContent(JsonConvert.SerializeObject(searchModel), Encoding.UTF8, "application/json");
            HttpResponseMessage response;

            try
            {
                response = await client.PostAsync(WebApiConsts.ADVERTISEMENT_CONTROLLER + "CheckForNewAdvertisementsAroundHomeLocationSinceLastCheck", stringContent);
            }
            catch
            {
                response = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
            }
            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(false);
            }
            var responseContentString = await response.Content.ReadAsStringAsync();

            var areTherNewAdvertisements = JsonConvert.DeserializeObject <bool>(responseContentString);

            return(areTherNewAdvertisements);
        }