Esempio n. 1
0
        //public async Task<User> CreateUserByMochaUserIdAsync(Guid mochaUserId)
        //{
        //    var mochaUser = await GetMochaUserAsync(mochaUserId);
        //    var user = new User()
        //    {
        //        UserName = mochaUser.UserName,
        //        Email = mochaUser.Email,
        //        MochaUserId = mochaUser.Id,
        //        DisplayName = mochaUser.DisplayName,
        //    };
        //    _refsContext.Users.Add(user);
        //    await _refsContext.SaveChangesAsync();

        //    return user;
        //}

        public async Task <User> UpdateUserAsync(User user)
        {
            var query      = _refsContext.Users.Where(u => u.Id == user.Id);
            var storedUser = await query.SingleAsync();

            storedUser.Email       = user.Email;
            storedUser.DisplayName = user.DisplayName;
            await _refsContext.SaveChangesAsync();

            return(storedUser);
        }
Esempio n. 2
0
        public async Task <Tag> EnsureTagAsync(string name)
        {
            // todo: special charsを含んでいる場合もはじく
            SystemContract.RequireNotNullOrWhiteSpace(name, "name");

            var query = _refsContext.Tags.Include("Statistics").
                        Where(t => t.Name == name);

            var storedTag = await query.SingleOrDefaultAsync();

            if (storedTag == null)
            {
                var tag = TagFactory.Create(name);
                _refsContext.Tags.Add(tag);
                await _refsContext.SaveChangesAsync();

                storedTag = tag;
            }

            return(storedTag);
        }
Esempio n. 3
0
        public async Task AddFavoriteRefListAsync(long ownerId, long refListId)
        {
            var exists = await ExistsFavoriteRefListAsync(ownerId, refListId);

            SystemContract.Require(
                !exists,
                "登録済みのお気に入りリスト, ownerId: {0}, refListId: {1}", ownerId.ToString(), refListId.ToString()
                );

            /// update statistics data
            {
                var statisticsQuery         = _refsContext.RefListStatistics.Where(s => s.RefListId == refListId);
                var storedRefListStatistics = await statisticsQuery.SingleAsync();

                var favCountQuery = _refsContext.Favorites.AsNoTracking();
                var favCount      = await favCountQuery.CountAsync(s => s.RefListId == refListId);

                storedRefListStatistics.FavoriteCount = favCount + 1;
            }

            var fav = FavoriteFactory.CreateForRefList(ownerId, refListId);

            _refsContext.Favorites.Add(fav);

            await _refsContext.SaveChangesAsync();
        }
Esempio n. 4
0
 public async Task CreateAsync(IdentityUser user)
 {
     _refsContext.Users.Add(user.User);
     await _refsContext.SaveChangesAsync();
 }
Esempio n. 5
0
        /// <summary>
        /// refListを作成します。
        /// </summary>
        public async Task <RefList> CreateRefListAsync(long userId, CreateRefListRequest request)
        {
            /// DisplayOrderの設定
            if (request.Refs != null)
            {
                var i = 0;
                foreach (var r in request.Refs)
                {
                    r.DisplayOrder = i;
                    ++i;
                }
            }

            var user = await _userHandler.GetUserAsync(userId);

            _refsContext.Users.Attach(user);

            var linkCount = request.Refs == null ? 0 : request.Refs.Count(r => r.Kind == RefKind.Link);
            var refList   = new RefList()
            {
                Author           = user,
                Title            = request.Title,
                Comment          = request.Comment,
                PublishingStatus = request.PublishingStatus,
                PublishedDate    = request.PublishingStatus == PublishingStatusKind.Draft ? (DateTime?)null : DateTime.Now,
                Refs             = request.Refs,
                Statistics       = new RefListStatistics()
                {
                    LinkCount = linkCount,
                },
            };

            _refsContext.RefLists.Add(refList);
            await _refsContext.SaveChangesAsync();

            await SetTagUsesAsync(refList, request.TagUses, false);

            refList.Refs = refList.Refs.OrderBy(r => r.DisplayOrder).ToArray();
            return(refList);
        }