Esempio n. 1
0
        public async Task <ActionResult <QuestionTopic> > PutQuestionTopic(int id, QuestionTopic questionTopic)
        {
            if (!AuthenticateEditor())
            {
                return(Unauthorized("Sorry you don't have the permission to create or edit is resource"));
            }
            if (id != questionTopic.Id)
            {
                return(BadRequest());
            }
            questionTopic.UpdateTime            = DateTime.Now;
            _context.Entry(questionTopic).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuestionTopicExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(questionTopic);
        }
 public IActionResult PostQuestionTopic([FromBody] QuestionTopic topic)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(_topicApplication.CreateEditQuestionTopic(topic)));
 }
        public long DeleteTopic(long ID)
        {
            QuestionTopic topic = _context.QuestionTopics.FirstOrDefault(e => e.ID == ID);

            if (topic == null)
            {
                return(-1);
            }

            _context.QuestionTopics.Remove(topic);
            _context.SaveChanges();
            return(topic.ID);
        }
        public QuestionTopic CreateEditTopic(QuestionTopic topic)
        {
            if (topic.ID > 0)
            {
                _context.Update(topic);
            }
            else
            {
                _context.Add(topic);
            }

            _context.SaveChanges();
            return(topic);
        }
Esempio n. 5
0
        public async Task <ActionResult <QuestionTopic> > PostQuestionTopic(QuestionTopic questionTopic)
        {
            if (!AuthenticateEditor())
            {
                return(Unauthorized("Sorry you don't have the permission to create or edit is resource"));
            }
            if (QuestionTopicExists(questionTopic.Id))
            {
                return(BadRequest());
            }
            questionTopic.UpdateTime = DateTime.Now;
            _context.QuestionTopics.Add(questionTopic);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetQuestionTopic", new { id = questionTopic.Id }, questionTopic));
        }
Esempio n. 6
0
        public IResult QuestionTopicFile(string pathArchiv)
        {
            List <string> stagesArchiv = Directory.GetDirectories
                                             (pathArchiv).ToList();
            Result result = new Result()
            {
                Success = true
            };

            int nomerStage = 0;

            foreach (var stage in configSection.StageItems)
            {
                List <string> substatages = new List <string>();

                if (stagesArchiv.Count >= stage.StageNumber)
                {
                    substatages = Directory.GetDirectories
                                      (stagesArchiv[stage.StageNumber - 1]).ToList();
                }

                int i = 0;
                int nomerSubStsages = 0;

                foreach (var subStage in stage.SubStageItems)
                {
                    List <string> topicThems = new List <string>();

                    if (substatages.Count - 1 >= i)
                    {
                        topicThems = Directory.GetDirectories
                                         (substatages[i]).ToList();
                    }

                    List <IQuestionTopic> listQuestionTopic =
                        new List <IQuestionTopic>();

                    for (int k = 0; k < subStage.TopicsCount; k++)
                    {
                        List <string> questions = new List <string>();

                        if (topicThems.Count - 1 >= k)
                        {
                            questions = Directory.GetDirectories
                                            (topicThems[k]).ToList();
                        }


                        foreach (var s in questions)
                        {
                            List <string> topicQuestion =
                                Directory.GetFiles(s).ToList();
                            IQuestionTopic questionTopic = new QuestionTopic();

                            foreach (var format in topicQuestion)
                            {
                                if (format.Contains(".txt"))
                                {
                                    questionTopic.Text = SaveTextFile(format);
                                }
                                else
                                {
                                    questionTopic.Image = SaveImageFile(format);
                                }
                            }

                            listQuestionTopic.Add(questionTopic);
                        }
                    }
                    GameEntityHolder.Game.ChildItemss[nomerStage].
                    ChildItemss[nomerSubStsages].ChildItemss = listQuestionTopic;

                    i++;
                    nomerSubStsages++;
                }

                nomerStage++;
            }

            return(result);
        }
Esempio n. 7
0
 public QuestionTopic CreateEditQuestionTopic(QuestionTopic topic)
 {
     return(_topicService.CreateEditTopic(topic));
 }