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)); }
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); }
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); }
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()); }
public Task <Result <Poll> > FindById(IPollRepository pollRepository, int pollId) { return(pollRepository.FindById(pollId)); }