Example #1
0
        /// <summary>
        /// 添加/删除收藏
        /// </summary>
        /// <param name="fr"></param>
        /// <returns></returns>
        public async Task <Good> Updatefavorite(FavoriteRequest fr)
        {
            try
            {
                //获取商品
                var Go = await _indexStore.GetAsync(a => a.Where(b => b.GoodId == fr.GoodId));

                //获取该商品的用户收藏
                var fa = await _indexStore.GetFavoriteAsync(a => a.Where(b => b.GoodId == fr.GoodId && b.UserId == fr.UserId));

                if (fa == null)
                {
                    await _indexStore.Favoriteadd(new Favorite
                    {
                        GoodId = fr.GoodId,
                        UserId = fr.UserId
                    });

                    //增加收藏数量
                    Go.Facount += 1;
                    return(await _indexStore.UpdateGood(Go));
                }
                await _indexStore.Favoritedelete(fa);

                //减少收藏数量
                Go.Facount -= 1;
                return(await _indexStore.UpdateGood(Go));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #2
0
        public IActionResult Create([FromBody] FavoriteRequest model)
        {
            var clientId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var map      = _mapper.Map <Favorite>(model);

            map.ClientId = long.Parse(clientId);
            var m = _favoriteService.Create(map);

            return(CreatedAtAction(nameof(Get), new DataResponse <Favorite>(m)));
        }
Example #3
0
        public async Task <int> DeleteFavorite(FavoriteRequest request)
        {
            var temp = await FavoriteAccessor.Find(request.favorite_id);

            if (temp != null)
            {
                var num = FavoriteAccessor.Delete(request.favorite_id);
                return(num.Result);
            }
            return(0);
        }
Example #4
0
        public void PostFavoriteVideo([FromBody] FavoriteRequest request)
        {
            User user = _context.Users.FirstOrDefault(u => u.Id == request.user.Id);

            Favorite favorite = new Favorite();

            favorite.video = request.video;

            if (user.Favorites == null)
            {
                user.Favorites = new List <Favorite>();
            }
            user.Favorites.Add(favorite);
            _context.SaveChanges();
        }
Example #5
0
        public void FavoriteAndRetweetImmediate()
        {
            if (IsDirectMessage)
            {
                // disable on direct messages
                return;
            }
            if (!this.AssertQuickActionEnabled())
            {
                return;
            }
            var accounts = this.GetImmediateAccounts()
                           .ToObservable()
                           .Publish();

            if (!this.IsFavorited)
            {
                var freq = new FavoriteRequest(this.Status, true);
                accounts.Do(a => Task.Run(() => this.Model.AddFavoritedUser(a.Id)))
                .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
                .SelectMany(a => RequestQueue.Enqueue(a, freq)
                            .Catch((Exception ex) =>
                {
                    Task.Run(() => this.Model.RemoveFavoritedUser(a.Id));
                    return(Observable.Empty <TwitterStatus>());
                }))
                .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
                .Subscribe();
            }
            if (!this.IsRetweeted)
            {
                var rreq = new RetweetRequest(this.Status, true);
                accounts.Do(a => Task.Run(() => this.Model.AddRetweetedUser(a.Id)))
                .Do(_ => this.RaisePropertyChanged(() => this.IsRetweeted))
                .SelectMany(a => RequestQueue.Enqueue(a, rreq)
                            .Catch((Exception ex) =>
                {
                    Task.Run(() => this.Model.RemoveRetweetedUser(a.Id));
                    return(Observable.Empty <TwitterStatus>());
                }))
                .Do(_ => this.RaisePropertyChanged(() => this.IsRetweeted))
                .Subscribe();
            }
            accounts.Connect();
        }
Example #6
0
        public async Task <int> CreateFavorite([FromBody] FavoriteRequest request)
        {
            //判断request里是否满足前置条件
            if (!ModelState.IsValid)
            {
                return(-5);
            }
            //取得存在cookie的当前账户id
            var user_id = Int32.Parse(User.Identity.Name);
            //生成favorite实例
            var favorite = _mapper.Map <FavoriteEntity>(request);

            favorite.user_id = user_id;
            //新建favorite
            var num = await FavoriteAccessor.Create(favorite);

            return(num);
        }
Example #7
0
        public void Favorite(IEnumerable <TwitterAccount> infos, bool add)
        {
            if (IsDirectMessage)
            {
                // disable on direct messages
                return;
            }
            Action <TwitterAccount> expected;
            Action <TwitterAccount> onFail;

            if (add)
            {
                expected = a => Task.Run(() => this.Model.AddFavoritedUser(a.Id));
                onFail   = a => Task.Run(() => this.Model.RemoveFavoritedUser(a.Id));
            }
            else
            {
                expected = a => Task.Run(() => this.Model.RemoveFavoritedUser(a.Id));
                onFail   = a => Task.Run(() => this.Model.AddFavoritedUser(a.Id));
            }

            var freq = new FavoriteRequest(this.Status, add);

            infos.ToObservable()
            .Do(expected)
            .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
            .SelectMany(a => RequestQueue.Enqueue(a, freq)
                        .Catch((Exception ex) =>
            {
                onFail(a);
                var desc = add
                                                      ? "お気に入り登録に失敗"
                                                      : "お気に入り登録解除に失敗";
                BackstageModel.RegisterEvent(new OperationFailedEvent(
                                                 desc + "(" + a.UnreliableScreenName + " -> " +
                                                 this.Status.User.ScreenName + ")", ex));
                return(Observable.Empty <TwitterStatus>());
            }))
            .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
            .Subscribe();
        }
Example #8
0
        public async Task <IActionResult> Userfavorite(FavoriteRequest fr)
        {
            string userName = HttpContext.Session.GetString("UserName");
            int?   userId   = HttpContext.Session.GetInt32("UserId");

            log.InfoFormat(userName + " || Get into 编辑收藏");
            try
            {
                fr.UserId = userId;
                var good = await _userManager.Updatefavorite(fr);

                log.InfoFormat("编辑收藏成功" + (good != null ? Helper.JsonHelper.ToJson(good) : ""));
                ViewData["UserName"] = userName;
                return(View("../Index/Goodlistbranchdetails", good));
            }
            catch (Exception e)
            {
                log.Error("编辑收藏失败,错误提示: " + Helper.JsonHelper.ToJson(e));
                return(View("Error", e));
            }
        }
Example #9
0
        public async Task <ActionResult <int> > UpdateFavorite([FromBody] FavoriteRequest request)
        {
            //判断request里是否满足前置条件
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            //取得存在cookie的当前账户id
            var user_id = Int32.Parse(User.Identity.Name);
            //生成favorite实例
            var temp_favorite = _mapper.Map <FavoriteEntity>(request);

            //查找是否存在favorite
            var temp = await FavoriteAccessor.Find(request.favorite_id);

            if (temp != null)
            {
                var num = FavoriteAccessor.Change(temp);
                temp.user_id       = user_id;
                temp.favorite_name = request.favorite_name;
                return(Ok(_mapper.Map <FavoriteResponse>(temp)));
            }
            return(Ok(-1));
        }
Example #10
0
 public void FavoriteAndRetweetImmediate()
 {
     if (!this.AssertQuickActionEnabled()) return;
     var accounts = this.GetImmediateAccounts()
         .ToObservable()
         .Publish();
     if (!this.IsFavorited)
     {
         var freq = new FavoriteRequest(this.Status, true);
         accounts.Do(a => Task.Run(() => this.Model.AddFavoritedUser(a.Id)))
                 .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
                 .SelectMany(a => RequestQueue.Enqueue(a, freq)
                                      .Catch((Exception ex) =>
                                      {
                                          Task.Run(() => this.Model.RemoveFavoritedUser(a.Id));
                                          return Observable.Empty<TwitterStatus>();
                                      }))
                 .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
                 .Subscribe();
     }
     if (!this.IsRetweeted)
     {
         var rreq = new RetweetRequest(this.Status, true);
         accounts.Do(a => Task.Run(() => this.Model.AddRetweetedUser(a.Id)))
                   .Do(_ => this.RaisePropertyChanged(() => this.IsRetweeted))
                   .SelectMany(a => RequestQueue.Enqueue(a, rreq)
                                        .Catch((Exception ex) =>
                                        {
                                            Task.Run(() => this.Model.RemoveRetweetedUser(a.Id));
                                            return Observable.Empty<TwitterStatus>();
                                        }))
                   .Do(_ => this.RaisePropertyChanged(() => this.IsRetweeted))
                   .Subscribe();
     }
     accounts.Connect();
 }
Example #11
0
        public void Favorite(IEnumerable<TwitterAccount> infos, bool add)
        {
            Action<TwitterAccount> expected;
            Action<TwitterAccount> onFail;
            if (add)
            {
                expected = a => Task.Run(() => this.Model.AddFavoritedUser(a.Id));
                onFail = a => Task.Run(() => this.Model.RemoveFavoritedUser(a.Id));
            }
            else
            {
                expected = a => Task.Run(() => this.Model.RemoveFavoritedUser(a.Id));
                onFail = a => Task.Run(() => this.Model.AddFavoritedUser(a.Id));
            }

            var freq = new FavoriteRequest(this.Status, add);
            infos.ToObservable()
                 .Do(expected)
                 .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
                 .SelectMany(a => RequestQueue.Enqueue(a, freq)
                                              .Catch((Exception ex) =>
                                              {
                                                  onFail(a);
                                                  BackstageModel.RegisterEvent(
                                                      new OperationFailedEvent((add ? "" : "un") + "favorite failed: " +
                                                                               a.UnreliableScreenName + " -> " +
                                                                               this.Status.User.ScreenName + " :" +
                                                                               ex.Message));
                                                  return Observable.Empty<TwitterStatus>();
                                              }))
                 .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
                 .Subscribe();
        }
Example #12
0
        public void Favorite(IEnumerable<TwitterAccount> infos, bool add)
        {
            if (IsDirectMessage)
            {
                // disable on direct messages
                return;
            }
            Action<TwitterAccount> expected;
            Action<TwitterAccount> onFail;
            if (add)
            {
                expected = a => Task.Run(() => this.Model.AddFavoritedUser(a.Id));
                onFail = a => Task.Run(() => this.Model.RemoveFavoritedUser(a.Id));
            }
            else
            {
                expected = a => Task.Run(() => this.Model.RemoveFavoritedUser(a.Id));
                onFail = a => Task.Run(() => this.Model.AddFavoritedUser(a.Id));
            }

            var freq = new FavoriteRequest(this.Status, add);
            infos.ToObservable()
                 .Do(expected)
                 .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
                 .SelectMany(a => RequestQueue.Enqueue(a, freq)
                                              .Catch((Exception ex) =>
                                              {
                                                  onFail(a);
                                                  var desc = add
                                                      ? "お気に入り登録に失敗"
                                                      : "お気に入り登録解除に失敗";
                                                  BackstageModel.RegisterEvent(new OperationFailedEvent(
                                                      desc + "(" + a.UnreliableScreenName + " -> " +
                                                      this.Status.User.ScreenName + ")", ex));
                                                  return Observable.Empty<TwitterStatus>();
                                              }))
                 .Do(_ => this.RaisePropertyChanged(() => this.IsFavorited))
                 .Subscribe();
        }
Example #13
0
        public void Favorite(IEnumerable<TwitterAccount> infos, bool add)
        {
            if (IsDirectMessage)
            {
                // disable on direct messages
                return;
            }
            Task.Run(() =>
            {
                Action<TwitterAccount> expected;
                Action<TwitterAccount> onFail;
                if (add)
                {
                    expected = a => Model.AddFavoritedUser(a.GetPseudoUser());
                    onFail = a => Model.RemoveFavoritedUser(a.Id);
                }
                else
                {
                    expected = a => Model.RemoveFavoritedUser(a.Id);
                    onFail = a => Model.AddFavoritedUser(a.GetPseudoUser());
                }

                var request = new FavoriteRequest(Status, add);

                // define working task
                Func<TwitterAccount, Task> workTask = account => Task.Run(async () =>
                {
                    expected(account);
                    try
                    {
                        await RequestQueue.EnqueueAsync(account, request).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        onFail(account);
                        var desc = add
                            ? MainAreaTimelineResources.MsgFavoriteFailed
                            : MainAreaTimelineResources.MsgUnfavoriteFailed;
                        BackstageModel.RegisterEvent(new OperationFailedEvent(
                            desc + "(" + account.UnreliableScreenName + " -> " +
                            Status.User.ScreenName + ")", ex));
                    }
                });

                // dispatch actions
                Task.WaitAll(infos.Select(workTask).ToArray());

                // notify changed
                RaisePropertyChanged(() => IsFavorited);
            });
        }