Esempio n. 1
0
        /// <summary>
        /// refListIdのRefListにrefeを追加します。
        /// bookmarkletから呼ばれ、呼出し後はリダイレクトされるのでRowVersionのことは考えなくてよい。
        /// </summary>
        public async Task AddRefWithoutRowVersionAsync(long refListId, Ref refe)
        {
            var query =
                from l in _refsContext.RefLists.Include("Refs")
                where l.Id == refListId
                select l;

            var storedRefList = await query.SingleAsync();

            BusinessContract.ValidateWritePermission(storedRefList.AuthorId);

            refe.DisplayOrder = storedRefList.Refs.Count;
            refe.RefListId    = 0;
            refe.RefList      = null;
            storedRefList.Refs.Add(refe);

            /// update statistics
            if (refe.Kind == RefKind.Link)
            {
                var statisticsQuery  = _refsContext.RefListStatistics.Where(s => s.RefListId == refListId);
                var storedStatistics = await statisticsQuery.SingleAsync();

                storedStatistics.LinkCount = storedRefList.Refs.Count(r => r.Kind == RefKind.Link);
            }

            _refsContext.MarkAsModified(storedRefList);
            await _refsContext.SaveChangesAsync();

            SendRefListUpdated(refListId);
        }
Esempio n. 2
0
        public async Task <TagUse> RenameTagUseAsync(RenameTagUseRequest request)
        {
            SystemContract.RequireNotNullOrWhiteSpace(request.NewName, "request.NewName");
            SystemContract.RequireNotNullOrWhiteSpace(request.OldName, "request.OldName");

            /// NewNameの使用確認
            var newNameTagUseQuery = _refsContext.TagUses.Include("Owner").AsNoTracking().
                                     Where(u => u.OwnerId == request.OwnerId && u.Name == request.NewName);
            /// collationをcase insensitiveにしているので大文字小文字が異なるTagUseも取得される
            var newNameTagUses = await newNameTagUseQuery.ToArrayAsync();

            var isNewNameTagUseExists = newNameTagUses.Any(u => u.Name == request.NewName);

            BusinessContract.Require(!isNewNameTagUseExists, Errors.TagUseNameAlreadyExists, request.NewName);

            var oldNameTagUseQuery = _refsContext.TagUses.Include("Owner").
                                     Where(t => t.OwnerId == request.OwnerId && t.Name == request.OldName);
            /// collationをcase insensitiveにしているので大文字小文字が異なるTagUseも取得される
            var storedTagUses = await oldNameTagUseQuery.ToArrayAsync();

            var storedTagUse = storedTagUses.Single(u => u.Name == request.OldName);

            BusinessContract.ValidateWritePermission(request.OwnerId);
            BusinessContract.ValidateRowVersion(request.TagUseIdentity.RowVersion, storedTagUse.RowVersion);

            var tag = await EnsureTagAsync(request.NewName);

            storedTagUse.TagId = tag.Id;
            storedTagUse.Name  = request.NewName;

            _refsContext.MarkAsModified(storedTagUse);
            await _refsContext.SaveChangesAsync();

            return(storedTagUse);
        }