예제 #1
0
        public StoreExtensions.AsyncActionCreator <ApplicationState> GetPlaceById(int id, long version)
        {
            return(async(dispatch, getState) =>
            {
                dispatch(new GetPlaceByIdStartAction(id));

                try
                {
                    Place place;
                    var isPlaceInLocalDatabase = PlaceRepository.ExistPlace(id);
                    //TODO: Refactor!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    if (isPlaceInLocalDatabase)
                    {
                        place = PlaceRepository.GetPlace(id);
                        if (version > place.Version)
                        {
                            place = await PlaceService.GetByIdAsync(id);

                            PlaceRepository.InsertPlace(place);
                        }
                    }
                    else
                    {
                        place = await PlaceService.GetByIdAsync(id);

                        PlaceRepository.InsertPlace(place);
                    }

                    dispatch(new GetPlaceByIdCompleteAction(place));
                }
                catch (Exception ex)
                {
                    //TODO: Log...
                    dispatch(new GetPlaceByIdCompleteAction(ex));
                }
            });
        }