示例#1
0
        public async Task <Result> DeleteGuest(IPollRepository pollRepository, int guestId, int pollId)
        {
            Result <Poll> poll = await pollRepository.FindById(pollId);

            if (!poll.IsSuccess)
            {
                return(poll);
            }
            return(poll.Value.RemoveGuest(guestId));
        }
示例#2
0
        public async Task <Result <Poll> > FindByIdForAuthor(IPollRepository pollRepository, int authorId, int pollId)
        {
            Result <Poll> poll = await pollRepository.FindById(pollId);

            if (!poll.IsSuccess)
            {
                return(poll);
            }
            if (poll.Value.AuthorId != authorId)
            {
                return(Result.CreateError <Poll>(Errors.Forbidden, ForbiddenMsg));
            }
            return(poll);
        }
示例#3
0
        public async Task <Result <Poll> > FindByIdForGuest(IPollRepository pollRepository, int pollId, int guestId)
        {
            Result <Poll> poll = await pollRepository.FindById(pollId);

            if (!poll.IsSuccess)
            {
                return(poll);
            }
            if (!poll.Value.Guests.Any(g => g.UserId == guestId))
            {
                return(Result.CreateError <Poll>(Errors.Forbidden, ForbiddenMsg));
            }
            return(poll);
        }
示例#4
0
        public async Task <Result> DeletePoll(IUnitOfWork unitOfWork, IPollRepository pollRepository, int pollId)
        {
            Result <Poll> poll = await pollRepository.FindById(pollId);

            if (!poll.IsSuccess)
            {
                return(poll);
            }

            var removed = poll.Value.Delete();

            pollRepository.Remove(removed);
            await unitOfWork.SaveChanges();

            return(Result.CreateSuccess());
        }
示例#5
0
 public Task <Result <Poll> > FindById(IPollRepository pollRepository, int pollId)
 {
     return(pollRepository.FindById(pollId));
 }