public async Task Save(CreatePersonRequest request, CancellationToken cancellationToken)
        {
            if (_context.Entry(request).State == EntityState.Detached)
            {
                _context.CreatePersonRequests.Add(request);
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
Beispiel #2
0
        public async Task <ActionResult> Remove(
            CancellationToken cancellationToken,
            [FromRoute] Guid newsPostId)
        {
            var newsPost = await _newsRepository.Get(newsPostId, cancellationToken);

            if (newsPost == null)
            {
                return(NotFound($"News post not found: {newsPostId}"));
            }

            var house = await _houseRepository.GetByAddress(User.GetAddress(), cancellationToken);

            if (house == null)
            {
                return(Unauthorized());
            }
            if (newsPost.House != house)
            {
                return(Unauthorized());
            }

            _context.News.Remove(newsPost);

            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public async Task Save(House house, CancellationToken cancellationToken)
        {
            if (_context.Entry(house).State == EntityState.Detached)
            {
                _context.Houses.Add(house);
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
        public async Task Save(Meeting meeting, CancellationToken cancellationToken)
        {
            if (_context.Entry(meeting).State == EntityState.Detached)
            {
                _context.Meetings.Add(meeting);
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
Beispiel #5
0
        public async Task Save(Person person, CancellationToken cancellationToken)
        {
            if (_context.Entry(person).State == EntityState.Detached)
            {
                _context.People.Add(person);
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
Beispiel #6
0
        public async Task Save(NewsPost newsPost, CancellationToken cancellationToken)
        {
            if (_context.Entry(newsPost).State == EntityState.Detached)
            {
                _context.News.Add(newsPost);
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
Beispiel #7
0
        private async Task UnVote(Guid personId, Guid votingId)
        {
            var vote = await _context.Votes
                       .Include(o => o.Person)
                       .Include(o => o.Variant)
                       .Where(o => o.Person.Id == personId && o.Variant.Voting.Id == votingId).SingleOrDefaultAsync();

            if (vote == null)
            {
                throw new InvalidOperationException($"Person vote not found");
            }

            _context.Votes.Remove(vote);

            await _context.SaveChangesAsync();
        }