예제 #1
0
파일: Home.aspx.cs 프로젝트: tatwd/bermuda
        /// <summary>
        /// 点击提交话题进行审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SubmitTopic_Click(object sender, EventArgs e)
        {
            try
            {
                Topic topic = GetAddingTopic();

                if (topic != null)
                {
                    Boolean isOk = TopicService.AddTopic(topic);

                    if (isOk)
                    {
                        Response.Redirect(Request.Url.ToString()); // 刷新本页
                    }
                }
                else
                {
                    PromptInfo.Text = "申请创建失败,请按要求填写信息!";
                }
            }
            catch (Exception ex)
            {
                PromptInfo.Text = ex.Message;
            }
        }
        public async System.Threading.Tasks.Task <ActionResult> Create(Topic topic, string message, int forumID)
        {
            StringBuilder sbBody = new StringBuilder();

            sbBody.Append(HttpUtility.HtmlEncode(message));

            message = sbBody.ToString();
            message = message.Replace(Environment.NewLine, "<br />");

            user = fum.GetCurrentForumUser(User.Identity.GetUserId());
            string ip = Request.UserHostAddress;

            this.topic = await ts.AddTopic(topic, forumID, user);

            if (this.topic != null)
            {
                this.post = await ps.AddPost(this.topic.Title, message, ip, this.topic.Id, user);

                if (this.post != null)
                {
                    await fs.UpdateForumCountByForumID(forumID, this.topic.Id, this.post.Id, user, ForumCountUtilities.TOPIC);

                    return(RedirectToAction("ViewForum", "Forum", new { id = forumID }));
                }
            }
            return(RedirectToAction("Create", forumID));
        }
예제 #3
0
        public async Task AddTopic(string roleName, string name, string?emoji)
        {
            var role = Context.Guild.Roles.Where(x => x.Name == roleName).FirstOrDefault(); // Hello? Should be able to get by name.

            if (role == null)
            {
                await ReplyAsync("No such role");

                return;
            }
            // I'm just going to hard cast and it can suck one if it blows up.
            await topics.AddTopic((IGuildChannel)Context.Channel, role, name, emoji);
        }
        private void HandleCreateTopic(TopicDto newTopic)
        {
            var topic = new Topic {
                Title = newTopic.Title, Description = newTopic.Description
            };

            if (TopicService.AddTopic(topic))
            {
                Log.Information($"Topic {topic.Title} created");
                Communication.SendSuccess(_webSocket);
            }
            else
            {
                Communication.SendError(_webSocket, "Wrong username or password");
            }
        }
        public async Task <Topic> Post(Topic topic)
        {
            TopicService topicService = new TopicService(_iconfiguration);

            return(await topicService.AddTopic(topic));
        }
예제 #6
0
        static void Main(string[] args)
        {
            IVocabularyUnitOfWork unitOfWork = new EFVocabularyUnitOfWork(new EnglishTrainer.DAL.EF.VocabularyContext());

            WordRepository  wordRepo        = (WordRepository)unitOfWork.Words;
            TopicRepository topicRepository = (TopicRepository)unitOfWork.Topics;

            /*
             * User user = new User() { NickName = "Test" };
             *
             * Word word1 = new Word() { EnglshTranslation = "Color", UkrainianTranslation = "Колір" };
             * Word word2 = new Word() { EnglshTranslation = "House", UkrainianTranslation = "Будинок" };
             * Word word3 = new Word() { EnglshTranslation = "Door", UkrainianTranslation = "Двері" };
             * Topic topic = new Topic { Name = "Starter2", Words = new List<Word>() { word1, word2, word3}, User = user };
             * word1.Topic = topic;
             * word2.Topic = topic;
             * word3.Topic = topic;
             * wordRepo.Create(word1);
             * wordRepo.Create(word2);
             * wordRepo.Create(word3);
             *
             *
             * topicRepository.Create(topic);
             * unitOfWork.Save();
             */

            foreach (Word word in wordRepo.GetAll())
            {
                Console.WriteLine("{0}, {1}, {2}, {3}", word.Id, word.EnglshTranslation, word.UkrainianTranslation, word.Topic.Id);
            }


            ITopicService topicService = new TopicService(unitOfWork, new Checker());

            foreach (TopicDTO item in topicService.GetTopics())
            {
                Console.WriteLine("{0}, {1}\n", item.Id, item.Name);
            }

            Console.WriteLine("get topic with id 1\n" +
                              "{0}\n", topicService.GetEngQuestoins(1).First().Queston);
            Console.WriteLine("get topic with id 1\n" +
                              "{0}\n", topicService.GetUkrQuestoins(1).First().Queston);

            var res = topicService.Check(new List <AnswerDTO>()
            {
                new AnswerDTO()
                {
                    Id = 1, Answer = "Color", Language = Language.English, TopicId = 1
                },
                new AnswerDTO()
                {
                    Id = 2, Answer = "House", Language = Language.English, TopicId = 1
                },
                new AnswerDTO()
                {
                    Id = 3, Answer = "e", Language = Language.English, TopicId = 1
                },
            });

            foreach (var item in res)
            {
                Console.WriteLine("{0} {1}", item.IsCorrect, item.Answer);
            }

            List <WordDTO> wordsToInsert = new List <WordDTO>()
            {
                new WordDTO("Book", "Книга"),
                new WordDTO("Thread", "Нитка"),
                new WordDTO("Computer", "Комп'ютер"),
                new WordDTO("Paper", "Папір")
            };

            topicService.AddTopic(wordsToInsert, "starter3", 1);
        }