Beispiel #1
0
        /// <inheritdoc />
        /// <summary>
        /// Добавить пользователя
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task AddUser(User user)
        {
            var result = await _repository.GetAsync(u => u.Id == user.Id);

            if (result == null)
            {
                await _repository.CreateAsync(user);

                if (user.Friends?.Count > 0)
                {
                    var friends = user.Friends.Select(f => new Friend()
                    {
                        FriendId = f.FriendId, UserId = user.Id
                    }).ToList();
                    await _friendRepository.CreateAllAsync(friends);
                }

                if (user.Tags?.Count > 0)
                {
                    var tags = user.Tags.Select(t => new Tag()
                    {
                        Name = t, UserId = user.Id
                    }).ToList();
                    await _tagRepository.CreateAllAsync(tags);
                }
            }
        }