public void AddEventToAlgolia(long eventId)
        {
            var eventDetailModel = _eventRepository.GetPlaceForAlgolia(eventId).FirstOrDefault();

            var algoliaExportModel = _algoliaExportRepositoryRepository.GetByObjectId(eventId.ToString());

            bool isInsert = ShouldInsert(algoliaExportModel, eventDetailModel);

            if (algoliaExportModel == null || isInsert)
            {
                AlgoliaPlacesExportModel placeData = new AlgoliaPlacesExportModel();
                placeData.ObjectID      = eventDetailModel.Id.ToString();
                placeData.Name          = eventDetailModel.Name;
                placeData.Description   = eventDetailModel.EventDescription;
                placeData.State         = eventDetailModel.StateName;
                placeData.Country       = eventDetailModel.CountryName;
                placeData.City          = eventDetailModel.CityName;
                placeData.Category      = eventDetailModel.ParentCategory;
                placeData.SubCategory   = eventDetailModel.Category;
                placeData.Url           = eventDetailModel.Url;
                placeData.PlaceImageUrl = "https://static5.feelaplace.com/images/places/tiles/" + eventDetailModel.AltId.ToString().ToUpper() + "-ht-c1.jpg";
                placeData.CityId        = eventDetailModel.CityId;
                placeData.CountryId     = eventDetailModel.CountryId;
                placeData.StateId       = eventDetailModel.StateId;

                _algoliaClientProvider.SavePlaceObject(placeData);

                if (algoliaExportModel == null)
                {
                    InsertObjects(eventDetailModel);
                }
                else
                {
                    UpdateAlgoliaExports(eventDetailModel, algoliaExportModel);
                }
            }
        }
        protected override async Task <ICommandResult> Handle(AlgoliaPlaceSyncCommand command)
        {
            AlgoliaPlaceSyncCommandResult result = new AlgoliaPlaceSyncCommandResult();

            try
            {
                List <AlgoliaPlacesExportModel> places = new List <AlgoliaPlacesExportModel>();
                foreach (var currentPlace in command.AllPlaces)
                {
                    try
                    {
                        bool isUpdate             = false;
                        var  currentAlgoliaObject = _algoliaExportRepositoryRepository.GetByObjectId(currentPlace.Id.ToString());
                        if (currentAlgoliaObject == null)
                        {
                            isUpdate = true;
                            await InsertObjects(currentPlace);
                        }
                        else
                        {
                            isUpdate = CheckForUpdate(currentAlgoliaObject, currentPlace);
                            if (isUpdate)
                            {
                                await UpdateAlgoliaExports(currentPlace, currentAlgoliaObject);
                            }
                            currentAlgoliaObject.IsIndexed = true;
                            currentAlgoliaObject.IsEnabled = true;
                            _algoliaExportRepositoryRepository.Save(currentAlgoliaObject);
                        }
                        if (isUpdate)
                        {
                            AlgoliaPlacesExportModel placeData = new AlgoliaPlacesExportModel();
                            placeData.ObjectID      = currentPlace.Id.ToString();
                            placeData.Name          = currentPlace.Name;
                            placeData.Description   = currentPlace.EventDescription;
                            placeData.State         = currentPlace.StateName;
                            placeData.Country       = currentPlace.CountryName;
                            placeData.City          = currentPlace.CityName;
                            placeData.Category      = currentPlace.ParentCategory;
                            placeData.SubCategory   = currentPlace.Category;
                            placeData.Url           = currentPlace.Url;
                            placeData.PlaceImageUrl = "https://static1.feelaplace.com/images/places/tiles/" + currentPlace.AltId.ToString().ToUpper() + "-ht-c1.jpg";
                            placeData.CityId        = currentPlace.CityId;
                            placeData.CountryId     = currentPlace.CountryId;
                            placeData.StateId       = currentPlace.StateId;
                            places.Add(placeData);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Log(LogCategory.Error, new Exception("Failed to Save Objects to Algolia index", e));
                        continue;
                    }
                }
                if (places.Count > 0)
                {
                    _algoliaClientProvider.SavePlaceObjects(places);
                    result.IsSuccess = true;
                }
                return(result);
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                _logger.Log(LogCategory.Error, new Exception("Failed to Save Objects to Algolia index", e));
                return(result);
            }
        }
Exemple #3
0
 public void SavePlaceObject(AlgoliaPlacesExportModel places)
 {
     _index = _client.InitIndex((_settings.GetConfigSetting <string>(SettingKeys.Integration.Algolia.Index)));
     _index.SaveObject(places);
 }