Exemple #1
0
        /// <summary>
        /// Delete message of given id.
        /// </summary>
        /// <param name="id"> Message id. </param>
        /// <returns> Success/failure message. </returns>
        public async Task <DtoResponse> Delete(int id)
        {
            var entity = await _unitOfWork.GroupMessageRepository.FindAsync(g => g.Id == id);

            if (entity == null)
            {
                return(DtoResponse.Failed("Group Message not found - task failed successfully"));
            }

            _unitOfWork.GroupMessageRepository.Delete(entity);
            await _unitOfWork.SaveChangesAsync();

            return(DtoResponse.Success());
        }
        /// <summary>
        /// Delete the poll of given Id.
        /// </summary>
        /// <param name="pollId">Id of a poll to be deleted.</param>
        /// <returns>Success/failure message.</returns>
        public async Task <DtoResponse> Delete(int pollId)
        {
            var entity = await _unitOfWork.PollRepository.FindAsync(p => p.Id == pollId);

            if (entity == null)
            {
                return(DtoResponse.Failed("Poll not found"));
            }

            _unitOfWork.PollRepository.Delete(entity);
            await _unitOfWork.SaveChangesAsync();

            return(DtoResponse.Success());
        }
Exemple #3
0
        /// <summary>
        /// Delete the question of given Id.
        /// </summary>
        /// <param name="pollQuestionId">Id of question to be deleted.</param>
        /// <returns>Success/failure message.</returns>
        public async Task <DtoResponse> Delete(int pollQuestionId)
        {
            var entity =
                await _unitOfWork.PollQuestionRepository.FindAsync(p => p.Id == pollQuestionId);

            if (entity == null)
            {
                return(DtoResponse.Failed("Poll question not found"));
            }

            if (entity.Points != 0)
            {
                var poll = _unitOfWork.PollRepository.Get(entity.PollId);
                poll.Points -= entity.Points;
                _unitOfWork.PollRepository.Update(poll, entity.PollId);
            }

            _unitOfWork.PollQuestionRepository.Delete(entity);
            await _unitOfWork.SaveChangesAsync();

            return(DtoResponse.Success());
        }