public async Task CreateFavoriteLinkForUserAsync(ILink link, IGeneralUser user)
        {
            // Validate Link
            Link toBeCreatedFavoriteLink = _dbContext.Links.SingleOrDefault(l =>
                                                                            l.Id == link.Id &&
                                                                            l.IsDeleted == false
                                                                            ) ?? throw new ArgumentException($"Link ID: {link.Id} could not be found.");
            GeneralUser generalUser = _dbContext.GeneralUsers.SingleOrDefault(g => g.Id == user.Id) ?? throw new ArgumentException($"GeneralUser ID: {user.Id} could not be found.");

            if (toBeCreatedFavoriteLink.GeneralUserId == generalUser.Id)
            {
                throw new ArgumentException("Link belong to the logged in user.");
            }
            if (CheckExistingFavoriteLinkAysnc(toBeCreatedFavoriteLink.Id, generalUser.Id) != default)
            {
                throw new ArgumentException($"Favorite link already exists.");
            }

            // Save to db
            FavoriteLink newFavoriteLink = new FavoriteLink
            {
                Link        = toBeCreatedFavoriteLink,
                GeneralUser = generalUser
            };

            generalUser.FavoriteLinks.Add(newFavoriteLink);

            await _dbContext.SaveChangesAsync();
        }
 protected void rptLinks_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Header)
     {
         Literal ltTitle = e.Item.FindControl("ltTitle") as Literal;
         if (ltTitle != null)
         {
             ltTitle.Text = Title;
         }
     }
     else if (e.Item.ItemType == ListItemType.AlternatingItem ||
              e.Item.ItemType == ListItemType.Item)
     {
         FavoriteLink lm = e.Item.DataItem as FavoriteLink;
         if (lm != null)
         {
             Literal lt1 = e.Item.FindControl("lt1") as Literal;
             if (lt1 != null)
             {
                 lt1.Text = lm.Rating.ToString();
             }
             HyperLink hl1 = e.Item.FindControl("hl1") as HyperLink;
             if (hl1 != null)
             {
                 hl1.Text        = lm.Title;
                 hl1.NavigateUrl = lm.Url;
             }
         }
     }
 }
Пример #3
0
        public static void Init()
        {
            EFCFContentRepository repository = new EFCFContentRepository();
            // カテゴリーの作成
            Category category1 = CreateCategory("Desktop", "デスクトップアプリ全般");

            repository.AddCategory(category1);

            Category category2 = CreateCategory("Web", "Web アプリケーション情報全般");

            repository.AddCategory(category2);

            Category category3 = CreateCategory("Universal App", "ユニバーサルアプリケーション");

            repository.AddCategory(category3);

            Category category4 = CreateCategory("Windows", "Windows 全般情報");

            repository.AddCategory(category4);

            repository.SaveChanges();

            // コメントデータの作成
            Article article11 = CreateArticle(category1.CategoryID, "TSQL Server 2012]インデックス再構築タスクで、オンラインインデックス再構築できるのにオフラインインデックス再構築のT-SQLが使用される", "Link-Title1", "ボディーテスト1dddddddddddddddddddddddddddddddddddddddddddddddddSQL Server 2012]インデックス再構築タスクで、オンラインインデックス再構築できるのにオフラインインデックス再構築のT-SQLが使<h1>hello world</h1>用される");
            Article article12 = CreateArticle(category1.CategoryID, "Title2", "Link-Title2", "ボディーテスト2");
            Article article13 = CreateArticle(category1.CategoryID, "Title3", "Link-Title3", "ボディーテスト3");

            repository.AddArticle(article11);
            repository.AddArticle(article12);
            repository.AddArticle(article13);

            var articles = Enumerable.Range(0, 20).Select(x => CreateArticle(category1.CategoryID, "PageTitle" + x.ToString(), "PageTitle-" + x.ToString(), "PageBody" + x.ToString())).ToList();

            articles.ForEach(x => repository.AddArticle(x));
            repository.SaveChanges();

            Comment comment1 = CreateComment();
            Comment comment2 = CreateComment();

            comment1.ArticleID = article11.ArticleID;
            comment2.ArticleID = article11.ArticleID;

            repository.AddComment(comment1);
            repository.AddComment(comment2);

            // お気に入りデータの作成
            FavoriteLink link1 = CreateFavoriteLink("http://www.google.co.jp", "Google");
            FavoriteLink link2 = CreateFavoriteLink("http://www.bing.com", "Bing");
            FavoriteLink link3 = CreateFavoriteLink("http://www.yahoo.co.jp", "ヤフー");

            repository.AddFavoriteLink(link1);
            repository.AddFavoriteLink(link2);
            repository.AddFavoriteLink(link3);

            repository.SaveChanges();
        }
        private FavoriteLink CheckExistingFavoriteLinkAysnc(int linkId, int generalUserId)
        {
            FavoriteLink existingFavoriteLink = _dbContext.FavoriteLinks
                                                .Where(gl =>
                                                       gl.LinkId == linkId && gl.GeneralUserId == generalUserId
                                                       )
                                                .FirstOrDefault();

            return(existingFavoriteLink);
        }
Пример #5
0
        public bool CreateFavoriteLink(EditFavoriteLinkViewModel model, IIdentity identity)
        {
            FavoriteLink link = new FavoriteLink();

            link.InjectFrom(model);
            link.AddedBy     = identity.Name;
            link.UpdatedBy   = identity.Name;
            link.AddedDate   = DateTime.Now;
            link.UpdatedDate = DateTime.Now;

            _repository.AddFavoriteLink(link);
            return(_repository.SaveChanges() == 1);
        }
Пример #6
0
        public static FavoriteLink CreateFavoriteLink(string url, string text)
        {
            FavoriteLink link = new FavoriteLink
            {
                Url         = url,
                Text        = text,
                AddedBy     = "admin",
                UpdatedBy   = "admin",
                AddedDate   = DateTime.Now,
                UpdatedDate = DateTime.Now
            };

            return(link);
        }
        public async Task DeleteFavoriteLinkForUserByIdAsync(int linkId, IGeneralUser generalUser)
        {
            FavoriteLink favoriteLink = _dbContext.FavoriteLinks
                                        .SingleOrDefault(l =>
                                                         l.GeneralUserId == generalUser.Id &&
                                                         l.LinkId == linkId
                                                         );

            if (favoriteLink == default)
            {
                throw new ArgumentException($"Favorite Link ID: {linkId} could not be found.");
            }

            _dbContext.FavoriteLinks.Remove(favoriteLink);
            await _dbContext.SaveChangesAsync();
        }
Пример #8
0
        public void Test350_LoadTest()
        {
            if (!_enableLoadTesting)
            {
                return;
            }
            String titleFormat = "Link {0}";
            String urlFormat   = "http://testurl/{0}.html";

            TimeKeeper timeKeeper = new TimeKeeper();
            int        maxLinks   = 1000;
            double     totalReflectionCastingTime = 0;
            double     totalDirectCastingTime     = 0;

            Console.WriteLine(String.Format("Starting test with {0} links", maxLinks));

            for (int i = 1; i <= maxLinks; i++)
            {
                string title = String.Format(titleFormat, i);
                string url   = String.Format(urlFormat, i);
                domain.SaveFavoriteLink(_profileId1, title, url, true, 3, "A link", "loadtest", -1);
            }

            DataSet ds = domain.GetFavoriteLinksByProfileID(_profileId1);

            FavoriteLink.SelectedCastingMode = CastingMode.ReflectionCasting;
            timeKeeper.Start();
            FavoriteLinkCollection collection1 = new FavoriteLinkCollection();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                FavoriteLink link = domain.Convert(row);
                collection1.Add(link);
            }
            timeKeeper.Stop();
            totalReflectionCastingTime += timeKeeper.Duration;
            timeKeeper.Reset();

            FavoriteLink.SelectedCastingMode = CastingMode.DirectCasting;
            timeKeeper.Start();
            FavoriteLinkCollection collection2 = new FavoriteLinkCollection();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                FavoriteLink link = domain.Convert(row);
                collection2.Add(link);
            }
            timeKeeper.Stop();
            totalDirectCastingTime += timeKeeper.Duration;
            timeKeeper.Reset();

            Console.WriteLine(String.Format("Max Links: {0}", maxLinks));
            double avgReflectionTime = totalReflectionCastingTime / maxLinks * 1000;
            double avgDirectTime     = totalDirectCastingTime / maxLinks * 1000;

            Console.WriteLine(String.Format("Avg Reflection Casting Time: {0} ms", avgReflectionTime));
            Console.WriteLine(String.Format("Avg Direct Casting Time: {0} ms", avgDirectTime));

            domain.PurgeProfile(_profileId1);
            _profileId1 = domain.GetFavoriteLinkProfileID(_userId1);
        }