예제 #1
0
        public void SaveAssignedUsers(int ownerId, int[] userIds)
        {
            int favorateId = _uow.TraderFavRepo.FindByOwner(ownerId);

            if (favorateId > 0)
            {
                _uow.FavorateListRepo.DeleteFavorateTraders(favorateId);
            }
            else if (favorateId == 0)
            {
                TraderFavorites tf = new TraderFavorites {
                    FavOwnerId = ownerId
                };
                _uow.TraderFavRepo.Add(tf);
                _uow.SaveChanges();
                favorateId = tf.Id;
            }

            if (userIds != null)
            {
                foreach (var usr in userIds)
                {
                    _uow.FavorateListRepo.Add(new FavoriteList {
                        TraderFavoriteId = favorateId, SuperTraderId = usr
                    });
                }
            }
            else
            {
                _uow.TraderFavRepo.Remove(favorateId);
            }
            _uow.SaveChanges();
        }
예제 #2
0
        public void CanGetAssignedUnassignedSTradersBigTraderEnter()
        {
            DeleteData();

            TraderFavorites traderFav1 = AddTraderFavorite(1);
            TraderFavorites traderFav2 = AddTraderFavorite(2);

            _uow.TraderFavRepo.Add(traderFav1);
            _uow.TraderFavRepo.Add(traderFav2);
            _uow.SaveChanges();
            FavoriteList f1 = AddFavoriteList(traderFav1.Id, 2);
            FavoriteList f2 = AddFavoriteList(traderFav1.Id, 3);

            _uow.FavorateListRepo.Add(f1);
            _uow.FavorateListRepo.Add(f2);

            FavoriteList f3 = AddFavoriteList(traderFav2.Id, 3);

            _uow.FavorateListRepo.Add(f3);


            _uow.SaveChanges();
            UnitOfWork uow = new UnitOfWork(new GoldStreamerContext());

            List <Trader> t = uow.FavorateListRepo.GetAssignedUnAssignedUsers(1);

            Assert.AreEqual(1, t[0].FavoriteList.Count);
            Assert.AreEqual(1, t[1].FavoriteList.Count);
        }
예제 #3
0
        public void CanDeleteSomeFavorateTraders()
        {
            DeleteData();

            TraderFavorites traderFav1 = AddTraderFavorite(1);
            TraderFavorites traderFav2 = AddTraderFavorite(2);

            _uow.TraderFavRepo.Add(traderFav1);
            _uow.TraderFavRepo.Add(traderFav2);
            _uow.SaveChanges();
            FavoriteList f1 = AddFavoriteList(traderFav1.Id, 2);
            FavoriteList f2 = AddFavoriteList(traderFav1.Id, 3);

            _uow.FavorateListRepo.Add(f1);
            _uow.FavorateListRepo.Add(f2);

            FavoriteList f3 = AddFavoriteList(traderFav2.Id, 3);

            _uow.FavorateListRepo.Add(f3);
            _uow.SaveChanges();

            _uow.FavorateListRepo.DeleteFavorateTraders(traderFav1.Id);
            _uow.SaveChanges();
            Assert.AreEqual(1, _uow.FavorateListRepo.GetAll().Count);
        }
예제 #4
0
        public void CanGetFavorateIdByOwnerId()
        {
            DeleteData();
            TraderFavorites traderFav1 = AddTraderFavorite(1);

            _uow.TraderFavRepo.Add(traderFav1);
            _uow.SaveChanges();

            Assert.AreEqual(traderFav1.Id, _uow.TraderFavRepo.FindByOwner(1));
        }
예제 #5
0
        public void CanCheckTraderHasFavoriteList()
        {
            DeleteData();
            TraderFavorites traderFav1 = AddTraderFavorite(1);

            _uow.SaveChanges();

            bool res = _uow.TraderFavRepo.HasFavorite(1);

            Assert.AreEqual(false, res);
        }
예제 #6
0
        public void CanGetAssignedSuperTraders()
        {
            DeleteData();
            TraderFavorites traderFav1 = AddTraderFavorite(1);

            _uow.TraderFavRepo.Add(traderFav1);

            FavoriteList f1 = AddFavoriteList(traderFav1.Id, 2);
            FavoriteList f2 = AddFavoriteList(traderFav1.Id, 3);

            _uow.FavorateListRepo.Add(f1);
            _uow.FavorateListRepo.Add(f2);
            _uow.SaveChanges();

            List <Trader> t = _uow.FavorateListRepo.GetAssignedTraders(1);

            Assert.AreEqual(2, t.Count);
        }
예제 #7
0
        public IEnumerable <Prices> GetAllPrices(int traderId, bool fromFavScreen = false)
        {
            List <Trader> traderList;

            if (fromFavScreen == false)
            {
                traderList = _context.Set <Trader>().Where(x => x.TypeFlag == 1 && x.IsActive).OrderBy(x => x.SortOrder).ToList();
            }
            else
            {
                TraderFavorites traderFav = _context.Set <TraderFavorites>().FirstOrDefault(tf => tf.FavOwnerId == traderId);
                traderList = (_context.Traders.Join(_context.FavorateList, trd => trd.ID, fav => fav.SuperTraderId,
                                                    (trd, fav) => new { trd, fav })
                              .Where(@t => @t.fav.TraderFavoriteId == traderFav.Id && @t.trd.IsActive)
                              .Select(@t => @t.trd)).ToList();
            }

            return(GetTraderAllPrice(traderId, traderList));
        }
예제 #8
0
        public void CanDeleteAllFavorateTraders()
        {
            DeleteData();

            TraderFavorites traderFav1 = AddTraderFavorite(1);

            _uow.TraderFavRepo.Add(traderFav1);
            _uow.SaveChanges();

            FavoriteList f1 = AddFavoriteList(traderFav1.Id, 2);
            FavoriteList f2 = AddFavoriteList(traderFav1.Id, 3);

            _uow.FavorateListRepo.Add(f1);
            _uow.FavorateListRepo.Add(f2);
            _uow.SaveChanges();

            favLstSrvc.SaveAssignedUsers(1, null);

            Assert.AreEqual(0, _uow.FavorateListRepo.GetAll().Count);
            Assert.AreEqual(0, _uow.TraderFavRepo.GetAll().Count);
        }