public QuestionController(QuestionRepository questionRepository, QuestionCategoryRepository qcRepo, AnswerRepository aRepo, FeedbackRepository fRepo, IHostingEnvironment hostingEnvironment) : base(questionRepository)
 {
     _hostingEnvironment   = hostingEnvironment;
     _questionCategoryRepo = qcRepo;
     _answerRepo           = aRepo;
     _feedBackRepo         = fRepo;
 }
예제 #2
0
        /// <summary>
        /// Creates the category.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="parentId">The parent id.</param>
        public void CreateCategory(string name, int?parentId)
        {
            var category = new QuestionCategory()
            {
                Name             = name,
                ParentCategoryId = parentId
            };

            QuestionCategoryRepository.Add(category);
        }
예제 #3
0
        private static void MakeFullCategoryName(QuestionCategory rootCategory, QuestionCategory childCategory)
        {
            var parentCategory = QuestionCategoryRepository.GetById(childCategory.ParentCategoryId.Value);

            rootCategory.Name = parentCategory.Name + "/" + rootCategory.Name;

            if (parentCategory.ParentCategoryId != null)
            {
                MakeFullCategoryName(rootCategory, parentCategory);
            }
        }
예제 #4
0
        void IndexAllQuestions()
        {
            var ctx     = new ApplicationDbContext();
            var repo    = new QuestionRepository(ctx);
            var catRepo = new QuestionCategoryRepository(ctx);
            var all     = repo.FindAllOrDefault(x => x.IsApproved == true).ToList();
            var catDesc = catRepo.GetAll().ToDictionary(x => x.Id, x => x.Name);

            all.ForEach(x => x.CategoryDescription = catDesc.GetValueOrDefault(x.CategoryId, "General"));

            var indexer = new QuestionIndexer();

            indexer.IndexData(all);
        }
예제 #5
0
 public IEnumerable <QuestionCategory> GetQuestionCategories()
 {
     return(QuestionCategoryRepository.GetAll());
 }
예제 #6
0
        public static async Task <(bool, string, Message)> FindServiceByQuestion(Message source, User user,
                                                                                 UsersRepository users, MessageParams messageParams)
        {
            var startTime     = DateTime.Now;
            var question      = source.Body;
            var lastMessageID = users.GetLastMessageID(user.GUID);

            var(success, error, apsolutionsAnswer) = await GetCategorized(user.GUID, user.Fio, user.Position, user.EmploymentDate, question).ConfigureAwait(false);

            if (users.IsOlderThenLast(user.GUID, lastMessageID))
            {
                return(false, null, null);
            }

            var answerHasError = !success || apsolutionsAnswer is null || apsolutionsAnswer.ServiceIDs is null || apsolutionsAnswer.QuestionCategories is null;
            var validServises  = apsolutionsAnswer?.ServiceIDs?
                                 .Where(sa => sa.ServiceID != 0 && ServiceItemRepository.GetServiceItems().Exists(s => s.Id == sa.ServiceID));

            answerHasError = validServises is null || validServises.Count() == 0;

            if (answerHasError)
            {
                users.SetLastMessageID(user.GUID);
                return(true, error, Message.Answer(source, success ? messageParams.NotFound : messageParams.AIError, DateTime.Now.Ticks - startTime.Ticks));
            }

            Message firstAnswer            = null;
            var     userMessagesForService = new Queue <Message>();

            foreach (var apsolutionService in validServises)
            {
                var serviceItem = ServiceItemRepository.GetServiceItems().FirstOrDefault(s => s.Id == apsolutionService.ServiceID);
                var commands    = CommandRepository.GetYesNo(source.ID);
                commands[0].CommandText = serviceItem.GUID.ToString();
                var answer = new Message
                {
                    SourceId    = source.ID ?? 0,
                    UserGuid    = source.UserGuid,
                    Iid         = source.Iid,
                    Date        = source.Date,
                    ServiceGuid = source.ServiceGuid,

                    Body = $"Используем '{serviceItem.Title}'?",

                    GUID     = Guid.NewGuid(),
                    Command  = 0,
                    IsFile   = false,
                    Commands = commands,
                    Style    = 1
                };

                if (firstAnswer is null)
                {
                    firstAnswer      = answer;
                    firstAnswer.Date = firstAnswer.Date.AddTicks(DateTime.Now.Ticks - startTime.Ticks);
                }
                else
                {
                    userMessagesForService.Enqueue(answer);
                }
            }

            users.SetMessages(user.GUID, QueueType.service, userMessagesForService);

            var validCategories = apsolutionsAnswer?.QuestionCategories?
                                  .Where(qc => qc.QuestionCategory != 0 && QuestionCategoryRepository.GetQuestionCategories().Exists(s => s.Id == qc.QuestionCategory));

            var userMessagesForQuestionCategory = new Queue <Message>();

            foreach (var apsolutionsCategory in validCategories)
            {
                var answer = new Message
                {
                    SourceId         = source.ID ?? 0,
                    UserGuid         = source.UserGuid,
                    Iid              = source.Iid,
                    Date             = source.Date,
                    ServiceGuid      = source.ServiceGuid,
                    QuestionCategory = apsolutionsCategory.QuestionCategory,

                    Body = "",
                    GUID = Guid.NewGuid(),
                };

                userMessagesForQuestionCategory.Enqueue(answer);
            }

            users.SetMessages(user.GUID, QueueType.category, userMessagesForQuestionCategory);
            users.SetLastMessageID(user.GUID);

            return(true, null, firstAnswer);
        }