Ejemplo n.º 1
0
        public async Task ToggleWatchAsync(int postId, UserAndOrganizationDto userAndOrg, bool shouldWatch)
        {
            await _postDeleteLock.WaitAsync();

            try
            {
                var entity = await _postWatchers.FindAsync(postId, userAndOrg.UserId);

                if (shouldWatch && entity == null)
                {
                    entity = new PostWatcher
                    {
                        PostId = postId,
                        UserId = userAndOrg.UserId
                    };
                    _postWatchers.Add(entity);
                }

                if (!shouldWatch && entity != null)
                {
                    _postWatchers.Remove(entity);
                }

                await _uow.SaveChangesAsync();
            }
            finally
            {
                _postDeleteLock.Release();
            }
        }
Ejemplo n.º 2
0
        public void ToggleWatch(int postId, UserAndOrganizationDTO userAndOrg, bool shouldWatch)
        {
            var entity = _postWatchers.Find(postId, userAndOrg.UserId);

            if (shouldWatch && entity == null)
            {
                entity = new PostWatcher
                {
                    PostId = postId,
                    UserId = userAndOrg.UserId
                };
                _postWatchers.Add(entity);
            }

            if (!shouldWatch && entity != null)
            {
                _postWatchers.Remove(entity);
            }

            _uow.SaveChanges();
        }