예제 #1
0
 internal override IObservable <object> BuildObservable(Params param) => Observable.Create <object>(async o =>
 {
     try
     {
         var favorites   = await FavoritesRepository.GetAllAsync();
         var existedItem = favorites.Where(x => x.EntityId == param.Id).FirstOrDefault();
         if (param.IsFavorite)
         {
             if (existedItem == null)
             {
                 await FavoritesRepository.AddAsync(new FavoriteItem()
                 {
                     EntityId = param.Id,
                     Tag      = null
                 });
             }
         }
         else
         {
             if (existedItem != null)
             {
                 await FavoritesRepository.DeleteByIdAsync(existedItem.Id);
             }
         }
         o.OnNext(null);
     }
     catch (Exception e)
     {
         Log.Error(GetType().Name, e.Message);
         o.OnError(e);
     }
     finally { o.OnCompleted(); }
 });