public async Task CreateAsync(UserAccount user, string description, UserActionType actionType, string data)
        {
            var now = DateTime.UtcNow;
            var nextActionNumber = 1;

            await foreach (var currentAction in _context.UserActions.Where(a => a.UserAccount == user && a.DeletedDateTime == null && a.IsCurrent).OrderBy(a => a.ActionNumber).AsAsyncEnumerable())
            {
                currentAction.IsCurrent          = false;
                currentAction.LastUpdateDateTime = now;
                nextActionNumber = currentAction.ActionNumber + 1;
            }

            await foreach (var redoAction in _context.UserActions.Where(a => a.UserAccount == user && a.DeletedDateTime == null && a.ActionNumber >= nextActionNumber).AsAsyncEnumerable())
            {
                redoAction.DeletedDateTime    = now;
                redoAction.LastUpdateDateTime = now;
            }

            await _context.UserActions.AddAsync(new UserAction
            {
                UserAccount     = user,
                Description     = description,
                ActionType      = actionType,
                UserActionData  = data,
                IsCurrent       = true,
                ActionNumber    = nextActionNumber,
                CreatedDateTime = now
            });

            await _context.SaveChangesAsync();
        }
        public async Task AddItemAsync(UserAccount user, UserList list, string description, string notes, DateTime?dueDate, ItemRepeat?repeat, IUserActionsService userActions)
        {
            var maxSortOrder = await GetMaxSortOrderAsync(user, list?.UserListId);

            var newUserItem = new UserItem
            {
                UserAccount = user,
                UserList    = list,
                Description = description,
                Notes       = notes,
                NextDueDate = dueDate,
                Repeat      = repeat,
                SortOrder   = maxSortOrder + 1
            };

            _context.UserItems.Add(newUserItem);
            await _context.SaveChangesAsync();

            var savedItemSortOrders = new List <(int, int, int)>();

            if (list?.ItemSortOrder != null)
            {
                await UpdateOrderAsync(user, list, list.ItemSortOrder, savedItemSortOrders);
            }

            await userActions.AddAsync(user, new AddItemAction(newUserItem, savedItemSortOrders));
        }
예제 #3
0
        public Task CreateNewUserAsync(ClaimsPrincipal user)
        {
            var authenticationUri = GetIdentifierFromPrincipal(user);
            var newUser           = new UserAccount {
                AuthenticationUri = authenticationUri
            };

            _context.UserAccounts.Add(newUser);
            return(_context.SaveChangesAsync());
        }
예제 #4
0
        public async Task Create(ApiClient apiClient, UserAccount userAccount, string refreshToken)
        {
            await _context.UserAccountApiAccesses.AddAsync(new UserAccountApiAccess
            {
                ApiClient    = apiClient,
                UserAccount  = userAccount,
                RefreshToken = refreshToken
            });

            await _context.SaveChangesAsync();
        }
        public async Task AddListAsync(UserAccount user, string name)
        {
            var maxSortOrder = await GetMaxSortOrderAsync(user);

            _context.UserLists.Add(new UserList
            {
                UserAccount = user,
                Name        = name,
                SortOrder   = maxSortOrder + 1
            });
            await _context.SaveChangesAsync();
        }
예제 #6
0
        public async Task CreateAsync(UserAccountApiAccess userAccountApiAccess, string tokenData, DateTime expires)
        {
            await DeleteExpiredTokensAsync();

            await _context.UserAccountTokens.AddAsync(new UserAccountToken
            {
                UserAccountApiAccess = userAccountApiAccess,
                ExpiryDateTime       = expires,
                TokenData            = tokenData
            });

            await _context.SaveChangesAsync();
        }
        public Task CreateAsync(UserAccount user, string uniqueFeedIdentifier, UserFeedType type, UserFeedItemDisplay display)
        {
            _logger.LogInformation($"Creating new feed for user {user.UserAccountId}: {uniqueFeedIdentifier}; {type}; {display}");

            _context.UserFeeds.Add(new UserFeed
            {
                UserAccount        = user,
                UserFeedIdentifier = uniqueFeedIdentifier,
                FeedType           = type,
                ItemDisplay        = display
            });
            return(_context.SaveChangesAsync());
        }
예제 #8
0
        public async Task CreateAsync(string displayName, string redirectUri, string appKey, string appSecretHash, string appSecretSalt,
                                      UserAccount createdBy)
        {
            await _context.ApiClients.AddAsync(new ApiClient
            {
                DisplayName   = displayName,
                RedirectUri   = redirectUri,
                AppKey        = appKey,
                AppSecretHash = appSecretHash,
                AppSecretSalt = appSecretSalt,
                CreatedBy     = createdBy
            });

            await _context.SaveChangesAsync();
        }