private async void AddFavorite_Tapped()
        {
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            var email = (string)localSettings.Values["Email"];

            FavoriteService service = new FavoriteService();

            if (email != personCliked.Email) {
                try {
                    bool isCreated = await service.AddFavoriteAsync(email, personCliked.Email);

                    if (isCreated) {
                        _navigationService.NavigateTo("FavoriteDetails", personCliked);
                    } else {
                        //show error link already exist
                        ShowToast("favorite_link_exists");
                    }

                } catch (NoNetworkException e) {
                    ShowToast(e.ToString());
                }

            }
            else
            {
                //try to add himself in favorite
                ShowToast("add_himself_favorite");
            }
Пример #2
0
        public async void FavoriteControllerUpdateTest()
        {
            DbContextOptions <LTBDBContext> options =
                new DbContextOptionsBuilder <LTBDBContext>()
                .UseInMemoryDatabase("FavoritesUpdate")
                .Options;

            using (LTBDBContext context = new LTBDBContext(options))
            {
                FavoriteService TestService = new FavoriteService(context);
                Favorite        favorites   = new Favorite();
                favorites.UserID = 1;
                favorites.PetID  = 2;
                favorites.Notes  = "Did this test pass?";
                await TestService.CreateFavorite(favorites);

                favorites.Notes = "Let's change the test";

                await TestService.UpdateFavorite(favorites);

                var TestFavorite = await TestService.GetFavorite(favorites.UserID, favorites.PetID);

                Assert.Equal("Let's change the test", TestFavorite.Notes);
            }
        }
 public FavoriteController(ProductService productService, FavoriteService favoriteService, CurrentUser currentUser, IMapper mapper)
 {
     _mapper          = mapper;
     _currentUser     = currentUser;
     _productService  = productService;
     _favoriteService = favoriteService;
 }
Пример #4
0
        private async void Delete_Favorite_Tapped(object sender, TappedRoutedEventArgs e)
        {
            //MessageDialog ms = new MessageDialog("ee");
            //await   ms.ShowAsync();
            Item          product = ProductList.SelectedItem as Item;
            ContentDialog ms      = new ContentDialog()
            {
                Title             = "Thông Báo",
                Content           = "Bạn có muốn xóa sản phẩm khỏi danh sách",
                PrimaryButtonText = "OK",
                CloseButtonText   = "Close"
            };
            ContentDialogResult result = await ms.ShowAsync();


            if (result == ContentDialogResult.Primary)
            {
                FavoriteService.deleteProduct(product.id);
                GetFavourite();
            }
            else
            {
                ContentDialog mc = new ContentDialog()
                {
                    Title = "Thông Báo : DELETE FAILED",
                };
            }
        }
Пример #5
0
        public async Task FavoriteBookShouldReturnCorrectData()
        {
            this.InitializeMapper();
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Favorite>(dbContext);
            var service    = new FavoriteService(repository);
            var userId     = "UserId";
            await service.AddToFavoriteAsync(userId, 1);

            await service.AddToFavoriteAsync(userId, 2);

            await service.AddToFavoriteAsync("UserIdDiffrent", 1);

            var actualResult   = service.FavoriteBook <FavoriteModel>(userId).ToList();
            var expectedResult = repository.All()
                                 .Where(x => x.UserId == userId)
                                 .ToList();

            for (int i = 0; i < actualResult.Count; i++)
            {
                Assert.Equal(expectedResult[i].UserId, actualResult[i].UserId);
            }
        }
Пример #6
0
        private FavoriteService CreateFavoriteService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new FavoriteService(userId);

            return(service);
        }
        public void Setup()
        {
            dbProvider = new TestDbConnectionProvider("pwetDb");

            _favoriteSvc = new FavoriteService(dbProvider);
            _viewModel   = new CoffeeViewModel(_favoriteSvc, null);
        }
Пример #8
0
        public ValueTask <List <long> > Search(long userId)
        {
            using var context = Context;
            var favoriteService = new FavoriteService(context);

            return(favoriteService.QueryEntityIdsByUserId(userId));
        }
Пример #9
0
        public ActionResult TopicDetail(string spaceKey, string tagName)
        {
            Tag tag = tagService.Get(tagName);

            if (tag == null)
            {
                return(HttpNotFound());
            }

            GroupEntity group = groupService.Get(spaceKey);

            if (group == null)
            {
                return(HttpNotFound());
            }

            FavoriteService FavoriteService = new FavoriteService(TenantTypeIds.Instance().Tag());

            pageResourceManager.InsertTitlePart(group.GroupName);
            pageResourceManager.InsertTitlePart(tag.TagName);
            if (!string.IsNullOrEmpty(tag.Description))
            {
                pageResourceManager.SetMetaOfDescription(HtmlUtility.StripHtml(tag.Description, false, false));
            }

            return(View(tag));
        }
Пример #10
0
 public UserController(PersonService personService, ActivityService activityService, PostService postService, FavoriteService favoriteService)
 {
     this.personService   = personService;
     this.activityService = activityService;
     this.postService     = postService;
     this.favoriteService = favoriteService;
 }
Пример #11
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Initializing services
            _favoriteService = new FavoriteService();

            // Load the Main.axml into this Activity
            SetContentView(Resource.Layout.Main);

            // Store the ListView inside a class attribute for reuse
            _jokesListView = this.FindViewById <ListView>(Resource.Id.jokesListView);
            // Subscribe to the Item Click event to handle adding a joke to favorites
            _jokesListView.ItemClick += JokeItemClicked;

            // Get the refresh button to subscribe to the click event and refresh the jokes
            var refreshButton = this.FindViewById <Button>(Resource.Id.refreshButton);

            refreshButton.Click += Refresh;
            refreshButton.Text   = "Loaded";

            // Get the favorites button to subscribe to the click event and go to the favorites activity
            var favoritesButton = this.FindViewById <Button>(Resource.Id.favoritesButton);

            favoritesButton.Click += FavoritesButton_Click;
        }
Пример #12
0
        /// <summary>
        /// 话题详情页
        /// </summary>
        /// <returns></returns>
        public ActionResult Topic(string topic)
        {
            topic = WebUtility.UrlDecode(topic);

            Tag tag = tagService.Get(topic);

            if (tag == null)
            {
                return(HttpNotFound());
            }

            if (UserContext.CurrentUser != null)
            {
                FavoriteService FavoriteService = new FavoriteService(TenantTypeIds.Instance().Tag());
                ViewData["isFavorited"] = FavoriteService.IsFavorited(tag.TagId, UserContext.CurrentUser.UserId);
            }
            pageResourceManager.InsertTitlePart(tag.TagName);
            if (!string.IsNullOrEmpty(tag.Description))
            {
                pageResourceManager.SetMetaOfDescription(HtmlUtility.StripHtml(tag.Description, true, false));
            }
            //话题下有没有微博
            string tagName = tag.TagName;

            return(View(tag));
        }
        public ActionResult _FollowTopics(string spaceKey, int?topNumber)
        {
            FavoriteService   favoriteService = new FavoriteService(TenantTypeIds.Instance().Tag());
            long              userId          = UserIdToUserNameDictionary.GetUserId(spaceKey);
            IEnumerable <Tag> tags            = new TagService(TenantTypeIds.Instance().Microblog()).GetTags(favoriteService.GetTopObjectIds(userId, topNumber ?? 15));

            return(View(tags));
        }
Пример #14
0
        private async void LoadFavorites()
        {
            var             localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            var             email         = (string)localSettings.Values["Email"];
            FavoriteService service       = new FavoriteService();

            PeopleList = await service.getFavoritesAsync(email);
        }
Пример #15
0
        // GET: Favorite
        public ActionResult Index()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new FavoriteService(userId);
            var model   = service.GetFavorites();

            return(View(model));
        }
Пример #16
0
        private async Task ExecuteFavoriteCommandAsync(SessionCellViewViewModel session)
        {
            var toggled = await FavoriteService.ToggleFavorite(session.SelectedSession);

            if (toggled && Settings.FavoritesOnly)
            {
                SortSessions();
            }
        }
Пример #17
0
 public ArticleContentViewComponent(PersonService personService, TagService tagService, TopicService topicService, PostService postService, ZanService zanService, FavoriteService favoriteService)
 {
     this.personService   = personService ?? throw new ArgumentNullException(nameof(personService));
     this.tagService      = tagService ?? throw new ArgumentNullException(nameof(tagService));
     this.topicService    = topicService ?? throw new ArgumentNullException(nameof(topicService));
     this.postService     = postService ?? throw new ArgumentNullException(nameof(postService));
     this.zanService      = zanService ?? throw new ArgumentNullException(nameof(zanService));
     this.favoriteService = favoriteService ?? throw new ArgumentNullException(nameof(favoriteService));
 }
Пример #18
0
        private async Task ExecuteFavoriteCommandAsync(WorkshopCellViewViewModel workshop)
        {
            var toggled = await FavoriteService.ToggleFavorite(workshop.SelectedWorkshop);

            if (toggled && Settings.FavoritesOnly)
            {
                SortWorkshops();
            }
        }
Пример #19
0
        public void LvListFavoritesDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            IUnityContainer container = (IUnityContainer)HttpContext.Current.Application["unityContainer"];

            IFavoriteService favoriteService = new FavoriteService();

            favoriteService = (IFavoriteService)container.BuildUp(favoriteService.GetType(), favoriteService);

            e.ObjectInstance = favoriteService;
        }
Пример #20
0
        public void GetAll_IsOfTypeProductList()
        {
            var productRepositoryMock = new Mock <IProductRepository>();

            productRepositoryMock.Setup(repository => repository.GetProducts("DummyId")).Returns(new List <Product>());

            var sut = new FavoriteService(productRepositoryMock.Object);

            sut.GetAll("DummyId").Should().BeOfType(typeof(List <Product>));
        }
Пример #21
0
        public void GetAll_CallsGetProducts()
        {
            var productRepositoryMock = new Mock <IProductRepository>();

            productRepositoryMock.Setup(repository => repository.GetProducts("DummyId")).Returns(new List <Product>());

            var sut = new FavoriteService(productRepositoryMock.Object);

            sut.GetAll("DummyId");

            productRepositoryMock.Verify(repository => repository.GetProducts("DummyId"));
        }
Пример #22
0
        public void Return_FavoriteService_Instance_WhenParametersSetCorrectly()
        {
            // Arrange
            var favoriteRepoMock = new Mock <IEfRepository <Favorite> >();
            var uowMock          = new Mock <ISaveContext>();

            // Act
            var favoriteService = new FavoriteService(favoriteRepoMock.Object, uowMock.Object);

            // Assert
            Assert.IsNotNull(favoriteService);
        }
Пример #23
0
 private void DeleteFavorite_Click(object sender, RoutedEventArgs e)
 {
     //TODO: notify observable collection change
     if (selectedBookList == null)
     {
         return;
     }
     foreach (var book in selectedBookList)
     {
         FavoriteService.RemoveBook(book);
     }
     Refresh();
 }
        private async void LoadFavorites()
        {
            var             localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            var             email         = (string)localSettings.Values["Email"];
            FavoriteService service       = new FavoriteService();

            try {
                FavoritesList = await service.getFavoritesAsync(email);
            }catch (NoNetworkException e)
            {
                ShowToast(e.ToString());
            }
        }
Пример #25
0
        public void ToggleIcon(Joke joke)
        {
            if (joke == null)
            {
                return;
            }

            joke = FavoriteService.ToggleFavorite(joke);

            var jokeIndex = _Jokes.FindIndex(j => j.ID == joke.ID);

            Jokes[jokeIndex] = joke;
        }
Пример #26
0
        public void ToggleFavorite()
        {
            if (IsFavorite)
            {
                FavoriteService.RemoveBook(this);
            }
            else
            {
                FavoriteService.AddBook(this);
            }

            NotifyPropertyChanged("IsFavorite");
        }
Пример #27
0
        public void IsExistShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository   = new EfDeletableEntityRepository <Favorite>(dbContext);
            var service      = new FavoriteService(repository);
            var favoriteBook = repository.All().FirstOrDefault();

            var actualResult = service.IsExist("UserId", 1);

            Assert.True(actualResult == false);
        }
Пример #28
0
        public async Task AddShouldReturnCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repository   = new EfDeletableEntityRepository <Favorite>(dbContext);
            var service      = new FavoriteService(repository);
            var favoriteBook = repository.All().FirstOrDefault();

            await service.AddToFavoriteAsync("UserId", 1);

            Assert.Equal(1, repository.All().Count());
        }
Пример #29
0
        public ActionResult Create(FavoriteCreate model)
        {
            if (ModelState.IsValid)
            {
                return(View(model));
            }

            var userId   = Guid.Parse(User.Identity.GetUserId());
            var services = new FavoriteService(userId);

            services.CreateFavorite(model);

            return(RedirectToAction("Index"));
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            _favoriteService = new FavoriteService();

            SetContentView(Resource.Layout.Favorites);

            var         jokesList = FindViewById <ListView>(Resource.Id.jokesListView);
            JokeAdapter adapter   = new JokeAdapter(this, _favoriteService.GetAll().ToArray());

            jokesList.Adapter    = adapter;
            jokesList.ItemClick += FavoriteClicked;
        }
Пример #31
0
        public ActionResult _FollowTopics(string spaceKey, int? topNumber)
        {
            FavoriteService favoriteService = new FavoriteService(TenantTypeIds.Instance().Tag());
            long userId = UserIdToUserNameDictionary.GetUserId(spaceKey);
            IEnumerable<Tag> tags = new TagService(TenantTypeIds.Instance().Microblog()).GetTags(favoriteService.GetTopObjectIds(userId, topNumber ?? 15));

            return View(tags);
        }
Пример #32
0
        /// <summary>
        /// 话题详情页
        /// </summary>
        /// <returns></returns>
        public ActionResult Topic(string topic)
        {
            topic = WebUtility.UrlDecode(topic);

            Tag tag = tagService.Get(topic);
            if (tag == null)
            {
                return HttpNotFound();
            }

            if (UserContext.CurrentUser != null)
            {
                FavoriteService FavoriteService = new FavoriteService(TenantTypeIds.Instance().Tag());
                ViewData["isFavorited"] = FavoriteService.IsFavorited(tag.TagId, UserContext.CurrentUser.UserId);
            }
            pageResourceManager.InsertTitlePart(tag.TagName);
            if (!string.IsNullOrEmpty(tag.Description))
            {
                pageResourceManager.SetMetaOfDescription(HtmlUtility.StripHtml(tag.Description, true, false));
            }
            //话题下有没有微博
            string tagName = tag.TagName;
            return View(tag);
        }
        public ActionResult TopicDetail(string spaceKey, string tagName)
        {
            Tag tag = tagService.Get(tagName);
            if (tag == null) return HttpNotFound();

            GroupEntity group = groupService.Get(spaceKey);
            if (group == null) return HttpNotFound();

            FavoriteService FavoriteService = new FavoriteService(TenantTypeIds.Instance().Tag());

            pageResourceManager.InsertTitlePart(group.GroupName);
            pageResourceManager.InsertTitlePart(tag.TagName);
            if (!string.IsNullOrEmpty(tag.Description))
            {
                pageResourceManager.SetMetaOfDescription(HtmlUtility.StripHtml(tag.Description, false, false));
            }

            return View(tag);
        }
Пример #34
0
        public JsonResult _AddFollowedTopic(string spaceKey, long tagId = 0)
        {
            IUser CurrentUser = UserContext.CurrentUser;
            if (CurrentUser == null)
            {
                return Json(new StatusMessageData(StatusMessageType.Error, "请先登录!"), JsonRequestBehavior.AllowGet);
            }

            FavoriteService FavoriteService = new FavoriteService(TenantTypeIds.Instance().Tag());
            if (!FavoriteService.IsFavorited(tagId, CurrentUser.UserId))
            {
                FavoriteService.Favorite(tagId, CurrentUser.UserId);
            }

            return Json(new StatusMessageData(StatusMessageType.Success, "添加关注成功!"), JsonRequestBehavior.AllowGet);
        }