Esempio n. 1
0
        protected override long ExecuteWorkImplementation()
        {
            var now      = DateTime.UtcNow;
            var user     = m_favoritesRepository.Load <User>(m_userId);
            var bookPage = m_resourceRepository.GetLatestResourceVersion <PageResource>(m_data.PageId);

            if (bookPage == null)
            {
                throw new MainServiceException(MainServiceErrorCode.PageNotFound,
                                               $"Page with ID {m_data.PageId} not found",
                                               HttpStatusCode.NotFound,
                                               new object[] { m_data.PageId });
            }

            var label = GetFavoriteLabelAndCheckAuthorization(m_data.FavoriteLabelId, user.Id);

            label.LastUseTime = now;

            var favoriteItem = new FavoritePage
            {
                ResourcePage  = bookPage.Resource,
                Title         = m_data.Title,
                FavoriteLabel = label,
                CreateTime    = now,
            };

            var resultId = (long)m_favoritesRepository.Create(favoriteItem);

            return(resultId);
        }
Esempio n. 2
0
        protected override long ExecuteWorkImplementation()
        {
            var now  = DateTime.UtcNow;
            var user = m_favoritesRepository.Load <User>(m_userId);

            var bookTypeEnum  = m_mapper.Map <BookTypeEnum>(m_data.BookType);
            var queryTypeEnum = m_mapper.Map <QueryTypeEnum>(m_data.QueryType);

            var bookTypeEntity = m_catalogValueRepository.GetBookType(bookTypeEnum);
            var label          = GetFavoriteLabelAndCheckAuthorization(m_data.FavoriteLabelId, user.Id);

            label.LastUseTime = now;

            var favoriteItem = new FavoriteQuery
            {
                BookType      = bookTypeEntity,
                Query         = m_data.Query,
                QueryType     = queryTypeEnum,
                CreateTime    = now,
                FavoriteLabel = label,
                Title         = m_data.Title,
            };

            var resultId = (long)m_favoritesRepository.Create(favoriteItem);

            return(resultId);
        }
        public void FavoritesRepoCheck()
        {
            CleanUpDatabase();
            _db = CreateDBInstance();
            _db.Init();

            var record = new FavoritesStreamReference()
            {
                TableName = "folder_refs",
                id        = new Identifier(1)
            };

            var repo      = FavoritesRepository.Create(_db);
            var recordKey = repo.CreateKey();

            recordKey["id"]        = record.id;
            recordKey["TableName"] = record.TableName;

            var found = repo.FindByKey(recordKey);

            Assert.IsTrue(found.Equals(default(FavoritesStreamReference)));

            repo.Write(record);
            found = repo.FindByKey(recordKey);
            Assert.IsTrue(found.Equals(record));

            repo.Remove(recordKey);
            found = repo.FindByKey(recordKey);
            Assert.IsTrue(found.Equals(default(FavoritesStreamReference)));

            CleanUpDatabase();
        }
Esempio n. 4
0
        public long CreateFavoriteLabel(string name, string color, bool isDefault)
        {
            var now           = DateTime.UtcNow;
            var user          = TryGetUser();
            var favoriteLabel = new FavoriteLabel
            {
                Name        = name,
                Color       = color,
                IsDefault   = isDefault,
                LastUseTime = now,
                User        = m_favoritesRepository.Load <User>(user.Id)
            };

            var id = m_favoritesRepository.Create(favoriteLabel);

            return((long)id);
        }
Esempio n. 5
0
        protected override long ExecuteWorkImplementation()
        {
            var now      = DateTime.UtcNow;
            var headword = m_favoritesRepository.Load <Resource>(m_data.HeadwordId);
            var label    = m_favoritesRepository.GetDefaultFavoriteLabel(m_userId);

            label.LastUseTime = now;

            var favoriteItem = new FavoriteHeadword
            {
                CreateTime              = now,
                FavoriteLabel           = label,
                Title                   = m_data.Title,
                DefaultHeadwordResource = headword,
                Query                   = m_data.Title,
            };

            var resultId = (long)m_favoritesRepository.Create(favoriteItem);

            return(resultId);
        }
        protected override long ExecuteWorkImplementation()
        {
            var now     = DateTime.UtcNow;
            var user    = m_favoritesRepository.Load <User>(m_userId);
            var project = m_favoritesRepository.Load <Project>(m_data.ProjectId);

            var label = GetFavoriteLabelAndCheckAuthorization(m_data.FavoriteLabelId, user.Id);

            label.LastUseTime = now;

            var favoriteItem = new FavoriteProject
            {
                Project       = project,
                CreateTime    = now,
                FavoriteLabel = label,
                Title         = m_data.Title
            };

            var resultId = (long)m_favoritesRepository.Create(favoriteItem);

            return(resultId);
        }