コード例 #1
0
        public ActionResult Edit(TopicDto model)
        {
            var subscribers = this.GetValidSubscribers();

            if (subscribers == null || !subscribers.Any())
            {
                return(Json(false, "Modify the topic failure. there are not any subscriber."));
            }

            model.Subscribers = (from subscriber in subscribers
                                 select new SubscriberDto
            {
                Email = subscriber
            }).ToList();

            model.UpdatedBy = this.LoginUser.Identity.Name;
            this.EncodeInput(model);

            try
            {
                using (var service = ServiceLocator.Instance.Resolve <ITopicService>())
                {
                    service.ModifyTopic(model);
                }
            }
            catch (Exception)
            {
                return(Json(false, "Modify the topic failure."));
            }

            return(Json(true));
        }
コード例 #2
0
            public void ConvertsToBoardCorrectly()
            {
                string    prompt          = "prompt";
                string    correctResponse = "correctResponse";
                AnswerDto answerDto       = new AnswerDto()
                {
                    Prompt          = prompt,
                    CorrectResponse = correctResponse
                };
                List <AnswerDto> answerDtos = new List <AnswerDto>()
                {
                    answerDto
                };
                string   topicName = "topicName";
                TopicDto topicDto  = new TopicDto()
                {
                    Answers = answerDtos,
                    Name    = topicName
                };
                List <TopicDto> topicDtos = new List <TopicDto>()
                {
                    topicDto
                };
                string   boardName = "boardName";
                BoardDto boardDto  = new BoardDto
                {
                    Name   = boardName,
                    Topics = topicDtos
                };

                var board = boardDto.ToBoard();

                Assert.True(board.Name == boardName, "Board.Name was not copied correctly.");
                Assert.True(board.Topics.Count() == topicDtos.Count(), "Board.Topics was not copied correctly");
            }
コード例 #3
0
        public async Task UpdateTopicAsync(TopicDto topicDto)
        {
            var topicEntity = TopicMapper.Map(topicDto);

            _unitOfWork.TopicRepository.Update(topicEntity);
            await _unitOfWork.CommitAsync();
        }
コード例 #4
0
        public async Task <(string Message, bool?IsSuccess)> DeleteTopic(int topicId, OperationLogDto logDto)
        {
            try
            {
                var conn  = _context.GetDbConnection();
                var posts = (await conn.QueryAsync <PhpbbPosts>("SELECT * FROM phpbb_posts WHERE topic_id = @topicId", new { topicId })).AsList();
                if (!posts.Any())
                {
                    return(string.Format(LanguageProvider.Moderator[GetLanguage(), "TOPIC_DOESNT_EXIST_FORMAT"], topicId), false);
                }

                var topic = await conn.QueryFirstOrDefaultAsync <PhpbbTopics>("SELECT * FROM phpbb_topics WHERE topic_id = @topicId", new { topicId });

                if (topic != null)
                {
                    var dto = new TopicDto
                    {
                        ForumId               = topic.ForumId,
                        TopicId               = topic.TopicId,
                        TopicTitle            = topic.TopicTitle,
                        TopicStatus           = topic.TopicStatus,
                        TopicType             = topic.TopicType,
                        TopicLastPosterColour = topic.TopicLastPosterColour,
                        TopicLastPosterId     = topic.TopicLastPosterId,
                        TopicLastPosterName   = topic.TopicLastPosterName,
                        TopicLastPostId       = topic.TopicLastPostId,
                        TopicLastPostTime     = topic.TopicLastPostTime,
                        Poll = await _postService.GetPoll(topic)
                    };
                    await conn.ExecuteAsync(
                        "INSERT INTO phpbb_recycle_bin(type, id, content, delete_time, delete_user) VALUES (@type, @id, @content, @now, @userId)",
                        new
                    {
                        type    = RecycleBinItemType.Topic,
                        id      = topic.TopicId,
                        content = await Utils.CompressObject(dto),
                        now     = DateTime.UtcNow.ToUnixTimestamp(),
                        logDto.UserId
                    }
                        );

                    await conn.ExecuteAsync(
                        "DELETE FROM phpbb_topics WHERE topic_id = @topicId; " +
                        "DELETE FROM phpbb_poll_options WHERE topic_id = @topicId",
                        new { topicId }
                        );
                }

                await DeletePostsCore(posts, logDto, false);

                await _operationLogService.LogModeratorTopicAction(ModeratorTopicActions.DeleteTopic, logDto.UserId, topicId);

                return(LanguageProvider.Moderator[GetLanguage(), "TOPIC_DELETED_SUCCESSFULLY"], true);
            }
            catch (Exception ex)
            {
                var id = Utils.HandleError(ex);
                return(string.Format(LanguageProvider.Errors[GetLanguage(), "AN_ERROR_OCCURRED_TRY_AGAIN_ID_FORMAT"], id), false);
            }
        }
コード例 #5
0
        public async Task <ApiRequestResult> AddAsync(TopicDto dto)
        {
            var command = dto.EntityMap <TopicDto, Topic>();
            await _topicRepository.AddAsync(command);

            return(ApiRequestResult.Success("添加成功"));
        }
コード例 #6
0
            public void ConvertsToTopicProperly()
            {
                string    prompt          = "prompt";
                string    correctResponse = "correctResponse";
                AnswerDto answerDto       = new AnswerDto()
                {
                    Prompt          = prompt,
                    CorrectResponse = correctResponse
                };
                List <AnswerDto> answerDtos = new List <AnswerDto>()
                {
                    answerDto
                };
                string   topicName = "topicName";
                TopicDto topicDto  = new TopicDto()
                {
                    Answers = answerDtos,
                    Name    = topicName
                };

                var topic = topicDto.ToTopic();

                Assert.True(topic.Answers.Count() == answerDtos.Count(), "Topic.Answers were not copied correctly.");
                Assert.True(topic.Name == topicName, "Topic.Name was not copied correctly.");
            }
コード例 #7
0
ファイル: TopicRepository.cs プロジェクト: DilyOkoye/Scapel
        protected virtual async Task Create(TopicDto input)
        {
            Topic topicDto = MappingProfile.MappingConfigurationSetups().Map <Topic>(input);

            _context.Topic.Add(topicDto);
            await _context.SaveChangesAsync();
        }
コード例 #8
0
ファイル: TopicService.cs プロジェクト: radtek/ReportMS
        public void ModifyTopic(TopicDto topicDto, bool includeSubscriber = true)
        {
            var topic = this._topicRepository.GetByKey(topicDto.ID);

            if (topic == null)
            {
                return;
            }

            topic.Update(topicDto.TopicName, topicDto.Description, topicDto.Subject, topicDto.Body, topicDto.UpdatedBy);

            if (includeSubscriber)
            {
                this._topicRepository.RemoveSubscribers(topic.Subscribers);

                var subscribers = topicDto.Subscribers;
                if (subscribers != null)
                {
                    var taskSubcribers = (from subscriber in subscribers
                                          select new Subscriber(topic.ID, subscriber.Email));
                    topic.AddSubscribers(taskSubcribers.ToArray());
                }
            }

            this._topicRepository.Update(topic);
        }
コード例 #9
0
        public async Task <TopicDto> GetByIdAsync(string userId, int topicId)
        {
            using (IDbConnection connection = _connectionProvider.GetConnection())
            {
                TopicDto topic = await connection.QueryFirstOrDefaultAsync <TopicDto>(GET_TOPICS, new { topicId });

                NotFoundException.ThrowIfNull(topic, nameof(topic));

                IEnumerable <EventDto> events = await connection.QueryAsync <EventDto>(GET_EVENTS_FOR_TOPIC, new { topicId });

                IEnumerable <QuestionDto> questions = await connection.QueryAsync <QuestionDto>(GET_QUESTIONS_FOR_TOPIC, new { topicId });

                IEnumerable <AnswerDto> answers = await connection.QueryAsync <AnswerDto>(GET_ANSWERS_FOR_TOPIC, new { topicId });

                IEnumerable <AttemptDto> attempts = await connection.QueryAsync <AttemptDto>(GET_ATTEMPTS_FOR_USER, new { userId, topicId });

                ILookup <int, AnswerDto> answerLokup = answers.ToLookup(x => x.QuestionId);

                foreach (QuestionDto question in questions)
                {
                    question.Answers = answerLokup[question.Id];
                }

                topic.Events    = events;
                topic.Questions = questions;
                topic.Attempts  = attempts;

                return(topic);
            }
        }
コード例 #10
0
        public async Task <TopicDto> GetTopic(Guid topicId, int page, int pageSize)
        {
            var topic =
                await
                Topics.Include(t => t.Author)
                .Include(t => t.Author.Identity)
                .Include(t => t.Posts.Select(p => p.Author.Identity))
                .Get(topicId);

            var topicAuthor = Mapper.Map <UserProfile, AuthorModel>(topic.Author);

            topicAuthor.Avatar = FileManager.GetAvatar(topic.Author.Email);

            var dto = new TopicDto
            {
                Id    = topic.Id,
                Title = topic.Title,
                Posts = topic.Posts.Skip((page - 1) * pageSize).Take(pageSize).Select(post => new PostDto
                {
                    Id     = post.Id,
                    Author = new AuthorModel(post.Author.Email,
                                             post.Author.Identity.Role,
                                             FileManager.GetAvatar(post.Author.Email),
                                             string.Concat(post.Author.Surname, " ", post.Author.Name, " ", post.Author.Patronymic)),
                    Content       = post.Content,
                    CreationDate  = post.CreationDate,
                    AttachedFiles = FileManager.GetPostFiles(post.Id)
                }),
                Author = topicAuthor
            };

            return(dto);
        }
コード例 #11
0
 public bool Add(TopicDto topicDto)
 {
     try
     {
         var result = _topicRepository.GetByName(topicDto.TopicName);
         if (result == null)
         {
             Topic topic = new Topic()
             {
                 TopicName   = topicDto.TopicName,
                 TopicDetail = topicDto.TopicDetail
             };
             _topicRepository.Add(topic);
             _topicRepository.SaveChange();
         }
         else
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
コード例 #12
0
        //[ProducesResponseType(typeof(TopicDto), StatusCodes.Status200OK)]
        public IActionResult AddTopic(TopicDto topicDto)
        {
            try
            {
                var topicDtos = _topicService.Add(topicDto);
                if (topicDtos)
                {
                    SuccessModel.SuccessCode    = "200";
                    SuccessModel.SuccessMessage = "Success";
                    return(Ok(SuccessModel));
                }
                else
                {
                    ErrorModel.ErrorCode    = "400";
                    ErrorModel.ErrorMessage = "Add Fail";
                    return(BadRequest(ErrorModel));
                }
            }
            catch (Exception ex)
            {
                ErrorModel.ErrorMessage = ex.Message;
                ErrorModel.ErrorCode    = "500";

                return(StatusCode(500, ErrorModel));
            }
        }
コード例 #13
0
        public void Execute(TopicDto request)
        {
            var topic = Context.Topics.Find(request.Id);

            if (topic == null)
            {
                throw new EntityNotFoundException();
            }

            if (topic.Subject != request.Subject)
            {
                throw new EntityAlreadyExistsException();
            }

            var user     = Context.Users.Find(topic.UserId);
            var category = Context.Categories.Find(topic.CategoryId);

            topic.ModifiedAt = DateTime.Now;
            topic.Subject    = request.Subject;
            topic.Content    = request.Content;
            topic.CategoryId = category.Id;
            topic.UserId     = user.Id;

            Context.SaveChanges();
        }
コード例 #14
0
        public async Task <IActionResult> SaveTopic(TopicDto topicDto)
        {
            if (User.FindFirst(ClaimTypes.Role).Value != "1")
            {
                return(Unauthorized());
            }

            try
            {
                var topic  = _mapper.Map <Topic>(topicDto);
                var number = await _repo.SaveTopic(topic);

                if (number != 0)
                {
                    return(StatusCode(200));
                }
            }
            catch (System.Exception ex)
            {
                Extensions.ReportError(ex);
            }


            return(StatusCode(400));
        }
コード例 #15
0
        public async Task <object> SubmitTopic([Service] Context context, [GraphQLNonNullType] Guid authorId, [GraphQLNonNullType] SubmitTopic topic)
        {
            TopicDto topicDto = topic.ToTopicDto();

            return(await context.AddTopicAsync(authorId, topicDto).ContinueWith(task => task.MapAsync(topicId =>
                                                                                                      context.GetTopicAsync(authorId, topicId)), TaskContinuationOptions.OnlyOnRanToCompletion)
                   .Unwrap().ContinueWith(t => t.Result.Flatten().Unwrap()));
        }
コード例 #16
0
        public void Execute(TopicDto request)
        {
            _validator.ValidateAndThrow(request);
            var topic = _context.Topics.Find(request.Id);

            topic.Name = request.Name;
            _context.SaveChanges();
        }
コード例 #17
0
        public async Task <Result <SuccessModel, ErrorModel> > AddTopic(TopicDto topicDto)
        {
            Uri url = new Uri(BaseUriUser, $"/Topic/AddTopic");

            Result <SuccessModel, ErrorModel> result = await PostMethodAsync <SuccessModel, ErrorModel>(url, topicDto);

            return(result);
        }
コード例 #18
0
        public async Task <ApiRequestResult> UpdateAsync(TopicDto dto)
        {
            var entity = await _topicRepository.GetAsync(dto.Id.Value);

            var newEntity = dto.EntityMap(entity);
            await _topicRepository.UpdateAsync(newEntity);

            return(ApiRequestResult.Success("修改成功"));
        }
コード例 #19
0
        public void SetUp()
        {
            _topicService    = new Mock <ICrudInterface <TopicDto> >();
            _topicController = new TopicController(_topicService.Object);

            _topic = new TopicDto {
                Id = "topic1", Name = "Unit Tests", MaxAttemptCount = 3, QuestionsPerAttempt = 5, TimeToPass = 5, TopicNumber = 5, SubjectId = "subject1"
            };
        }
コード例 #20
0
        public static TopicDto ToDto(this Topic topic)
        {
            TopicDto topicDto = new TopicDto()
            {
                Answers = topic.Answers.Select(x => x.ToDto()),
                Name    = topic.Name
            };

            return(topicDto);
        }
コード例 #21
0
ファイル: TopicRepository.cs プロジェクト: DilyOkoye/Scapel
        protected virtual async Task Update(TopicDto input)
        {
            var users = await _context.Topic.Where(x => x.Id == input.Id).FirstOrDefaultAsync();

            if (users != null)
            {
                Topic topicDto = MappingProfile.MappingConfigurationSetups().Map <Topic>(input);
                _context.Topic.Update(topicDto);
                await _context.SaveChangesAsync();
            }
        }
コード例 #22
0
ファイル: TopicRepository.cs プロジェクト: DilyOkoye/Scapel
 public async Task CreateOrEditTopic(TopicDto input)
 {
     if (input.Id == null || input.Id == 0)
     {
         await Create(input);
     }
     else
     {
         await Update(input);
     }
 }
コード例 #23
0
        private void RetrieveData()
        {
            using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey))
            {
                TopicFacade facade = new TopicFacade(uow);
                CurrentInstance = facade.RetrieveOrNewTopic(InstanceId, new TopicConverter());

                PostFacade postFacade = new PostFacade(uow);
                CurrentInstance.Posts = postFacade.RetrievePostsByTopic(InstanceId, new PostConverter());
            }
        }
コード例 #24
0
        private void CalibrateTopics(TopicDto topic)
        {
            var tasks = topic.TopicTasks.Where(this.CalibrateCore);

            if (!tasks.Any())
            {
                return;
            }

            this._filterTopics.Add(topic, tasks);
        }
コード例 #25
0
ファイル: TopicService.cs プロジェクト: klymenko-ruslan/forum
 public bool PostTopic(TopicDto topicDto)
 {
     using (var context = new ChatContext())
     {
         TopicModel topicModel = new TopicModel();
         topicModel.name   = topicDto.name;
         topicModel.author = context.UserModel.First(user => user.id == topicDto.authorid);
         context.TopicModel.Add(topicModel);
         context.SaveChanges();
         return(true);
     }
 }
コード例 #26
0
ファイル: TopicService.cs プロジェクト: Skape18/Forum
        public async Task RemoveAsync(TopicDto topicDto)
        {
            if (topicDto == null)
            {
                throw new ArgumentNullException("topicDto", "Argument is null");
            }

            var topic = Mapper.Map <TopicDto, Topic>(topicDto);

            UnitOfWork.Topics.Remove(topic);
            await UnitOfWork.SaveChangesAsync();
        }
コード例 #27
0
        public void Execute(TopicDto request)
        {
            _validator.ValidateAndThrow(request);

            var topic = new Topic
            {
                Name = request.Name
            };

            _context.Topics.Add(topic);
            _context.SaveChanges();
        }
コード例 #28
0
        public IActionResult Topic(int topicId)
        {
            var user  = service.GetUserById(User.Identity.GetUserId());
            var posts = service.ReadAllPostsInTopic(topicId);
            var topic = service.GetTopicById(topicId); //TODO use Include
            var model = new TopicDto {
                Posts = posts, Topic = topic, User = user
            };

            service.NewTopicView(topicId);

            return(View(model));
        }
コード例 #29
0
        public async Task <Either <Error, Guid> > AddTopicAsync(Guid authorId, TopicDto topic)
        {
            Either <Error, AuthorDto> author = await GetAuthorAsync(authorId);

            return((await author.MapAsync(async a =>
            {
                Guid topicId = Guid.NewGuid();
                topic.Id = topicId;
                a.Topics.Add(topic);
                Either <Error, AuthorDto> updated = await UpdateAuthorAsync(a);
                return updated.Map(p => topicId);
            })).Flatten());
        }
コード例 #30
0
 private void RetrieveData()
 {
     using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey))
     {
         TopicFacade facade   = new TopicFacade(uow);
         TopicDto    instance = facade.RetrieveOrNewTopic(InstanceId, new TopicConverter());
         if (instance.IsNew)
         {
             instance.IssuedById = CurrentUserContext.User.UserId;
         }
         CurrentInstance = instance;
     }
 }